Skip to content

Commit

Permalink
chore: add TodoMVC as example
Browse files Browse the repository at this point in the history
  • Loading branch information
Saviio committed Jan 21, 2019
1 parent 2311825 commit 7d959fc
Show file tree
Hide file tree
Showing 24 changed files with 4,999 additions and 243 deletions.
1 change: 0 additions & 1 deletion example/consumer/index.ts

This file was deleted.

12 changes: 12 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo</title>
<link rel="stylesheet" href="todo.css">
</head>
<body>
<div id="app"></div>
<script src="/dist/main.js"></script>
</body>
</html>
52 changes: 27 additions & 25 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
{
"name": "reactivedb-expmple",
"version": "0.7.0",
"description": "Example for ReactiveDB",
"main": "index.ts",
"name": "reactivedb-todo-mvc",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"dev": "cross-env NODE_ENV=development webpack-dev-server --hot --port 9999",
"build": "cross-env NODE_ENV=production webpack"
},
"repository": {
"type": "git",
"url": "git+https://github.com/teambition/ReactiveDB.git"
},
"keywords": [
"ReactiveDB",
"RxJS",
"Lovefield"
],
"author": "[email protected]",
"license": "MIT",
"bugs": {
"url": "https://github.com/teambition/ReactiveDB/issues"
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/react": "^16.7.20",
"@types/react-dom": "^16.0.11",
"cross-env": "^5.2.0",
"ts-loader": "^5.2.2",
"tslint": "^5.11.0",
"tslint-config-standard": "^8.0.1",
"tslint-loader": "^3.5.4",
"typescript": "^3.2.4",
"webpack": "^4.23.1",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.10"
},
"homepage": "https://github.com/teambition/ReactiveDB#readme",
"dependencies": {
"antd": "^2.7.3",
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
"devDependencies": {
"typescript": "^2.2.1"
"@types/classnames": "^2.2.6",
"classnames": "^2.2.6",
"react": "^16.8.0-alpha.0",
"react-dom": "16.8.0-alpha.0",
"reactivedb": "0.12.0-alpha.1-incremental",
"rxjs": "^6.3.3"
}
}
3 changes: 0 additions & 3 deletions example/rdb/Database.ts

This file was deleted.

160 changes: 0 additions & 160 deletions example/rdb/defineSchema.ts

This file was deleted.

1 change: 0 additions & 1 deletion example/rdb/index.ts

This file was deleted.

13 changes: 13 additions & 0 deletions example/src/TodoMVC.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react'

import { TodoList, Filter, Header } from './components'

export const TodoMVC = () => {
return (
<>
<Header />
<TodoList />
<Filter />
</>
)
}
52 changes: 52 additions & 0 deletions example/src/components/filter.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as React from 'react'
import { useContext } from 'react'
import cx from 'classnames'

import { source, TodoContext } from '../controller'
import { useObservable } from '../hooks'

export const Filter = React.memo(() => {
const filter = useObservable(source.filter, 'all')
const context = useContext(TodoContext)

const setAll = () => context.setFilter('all')
const setActive = () => context.setFilter('active')
const setCompleted = () => context.setFilter('completed')

const handlers = [
{
href: '#/',
className: cx({ selected: filter === 'all' }),
onClick: setAll,
children: 'All'
},
{
href: '#/active',
className: cx({ selected: filter === 'active' }),
onClick: setActive,
children: 'Active'
},
{
href: '#/completed',
className: cx({ selected: filter === 'completed' }),
onClick: setCompleted,
children: 'Complete'
}
]

const items = handlers.map((item) => {
return (
<li key={ item.href }>
<a { ...item } />
</li>
)
})

return (
<footer className='footer'>
<ul className="filters">
{ items }
</ul>
</footer>
)
})
35 changes: 35 additions & 0 deletions example/src/components/header.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from 'react'
import { useState, useContext } from 'react'

import { TodoContext } from '../controller'

export const Header = () => {
const [ newItem, setValue ] = useState('')
const context = useContext(TodoContext)

const onInput = (e: React.SyntheticEvent<HTMLInputElement>) => {
const target = e.target as HTMLInputElement
setValue(target.value)
}

const onAdd = (e: React.KeyboardEvent<HTMLInputElement>) => {
const target = e.target as HTMLInputElement
if (e.key === 'Enter') {
context.addItem(target.value)
setValue('')
}
}

return (
<header className='header'>
<h1>todos</h1>
<input
className='new-todo'
value={ newItem }
placeholder='What needs to be done?'
onKeyPress={ onAdd }
onChange={ onInput }
/>
</header>
)
}
4 changes: 4 additions & 0 deletions example/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './filter.component'
export * from './list.component'
export * from './header.component'
export * from './item.component'
Loading

0 comments on commit 7d959fc

Please sign in to comment.