-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add TodoMVC
as example
#103
Open
Saviio
wants to merge
1
commit into
master
Choose a base branch
from
chore/example
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,999
−243
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will there have any problem using
React.memp
withempty props
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this should be ok, just like