Skip to content

Commit b1d0567

Browse files
committed
change todos structure todo.done
1 parent 6144412 commit b1d0567

File tree

5 files changed

+63
-30
lines changed

5 files changed

+63
-30
lines changed

examples/todomvc/public/todos.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[{
22
"text": "Try React Most",
3-
"completed": false,
3+
"done": true,
44
"id": 0
55
},{
66
"text": "Give it a Star on Github",
7-
"completed": false,
7+
"done": false,
88
"id": 1
99
}]

examples/todomvc/src/components/Footer.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const FILTER_TITLES = {
1111

1212
export const FILTER_FUNC = {
1313
'SHOW_ALL': _=>_,
14-
'SHOW_ACTIVE': todos=>todos.filter(todo=>!todo.completed),
15-
'SHOW_COMPLETED': todos=>todos.filter(todo=>todo.completed),
14+
'SHOW_ACTIVE': todos=>todos.filter(todo=>!todo.done),
15+
'SHOW_COMPLETED': todos=>todos.filter(todo=>todo.done),
1616
}
1717
let Footer = React.createClass({
1818
renderTodoCount() {
@@ -69,7 +69,7 @@ let Footer = React.createClass({
6969

7070
export default connect((intent$)=>{
7171
return {
72-
clear: Intent.Clear,
72+
clear: () => Intent.Clear(),
7373
filterWith: Intent.Filter,
7474
}
7575
})(Footer)

examples/todomvc/src/components/MainSection.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ const MainSection = ({todos,filter}) => {
2626

2727
MainSection.defaultProps = {
2828
todos: [
29-
{id:0, text:'Loading...dadada', completed:false},
29+
{id:0, text:'Loading...dadada', done:false},
3030
],
3131
filter: _=>_
3232
}
3333

3434
export default connect((intent$)=>{
3535
let lensTodos = r.lensProp('todos')
36-
let lensComplete = r.lensProp('completed')
36+
let lensComplete = r.lensProp('done')
3737
let lensTodo = index => r.compose(lensTodos, r.lensIndex(index))
3838
let lensTodoComplete = index => r.compose(lensTodo(index), lensComplete)
3939
let sinks$ = intent$.map(Intent.case({
4040
Edit: (todo,index) => r.set(lensTodo(index), todo),
41-
Clear: () => r.over(lensTodos, r.filter(todo=>todo.completed)),
41+
Clear: () => r.over(lensTodos, r.filter(todo=>!todo.done)),
4242
Delete: id => r.over(lensTodos, r.filter(todo=>todo.id!=id)),
4343
Filter: filter=>state=>({ filter }),
4444
Done: index=>r.over(lensTodoComplete(index), r.not),

examples/todomvc/src/components/TodoItem.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const TodoItemView = ({todo, actions, index}) => {
88
return <div className="view">
99
<input className="toggle"
1010
type="checkbox"
11-
checked={todo.completed}
11+
checked={todo.done}
1212
onChange={()=>actions.done(index)} />
1313
<label onDoubleClick={()=>actions.editing(todo.id)}>
1414
{todo.text}
@@ -29,7 +29,7 @@ const TodoItem = props => {
2929
/>: <TodoItemView index={index} todo={todo} actions={actions}/>
3030

3131
return <li className={classnames({
32-
completed: todo.completed,
32+
completed: todo.done,
3333
editing: editing===todo.id
3434
})}>{element}</li>
3535
}

examples/todomvc/src/components/__tests__/MainSection-spec.jsx

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,69 @@ import React from 'react'
44
import when from 'when'
55
import Intent from '../../todo.action'
66
import MainSection from '../MainSection.jsx'
7-
import Footer from '../Footer.jsx'
7+
import Footer, {FILTER_FUNC} from '../Footer.jsx'
8+
import TodoItem from '../TodoItem.jsx'
89
import Most from '../../../../../lib/react-most'
910
import {do$, historyStreamOf} from '../../../../../lib/test-utils'
1011
import TestUtils from 'react-addons-test-utils'
11-
describe('MainSection', ()=>{
1212

13-
describe('display', ()=> {
14-
it('correct counts on footer', ()=> {
13+
describe('MainSection', ()=>{
14+
const RESPONSE = '[{"text": "Try React Most","done": false,"id": 0},{"text": "Give it a Star on Github","done": false,"id": 1}]'
15+
beforeEach(()=>{
16+
rest.__return(RESPONSE)
17+
})
18+
describe('View', ()=> {
19+
const defaultTodos = [
20+
{id:0, text:'Loading...dadada', done:false},
21+
{id:1, text:'dadada', done:false},
22+
{id:2, text:'yay', done:true},
23+
]
24+
it('should show correct counts on footer', ()=> {
1525
let mainSection = TestUtils.renderIntoDocument(
1626
<Most>
1727
<MainSection
18-
todos={[
19-
{id:0, text:'Loading...dadada', done:false},
20-
{id:1, text:'dadada', done:false},
21-
]}
28+
todos={defaultTodos}
2229
filter={_=>_}
2330
/>
2431
</Most>
2532
)
2633
let footer = TestUtils.findRenderedComponentWithType(mainSection, Footer);
27-
expect(footer.props.completedCount).toBe(0)
34+
expect(footer.props.completedCount).toBe(1)
2835
expect(footer.props.activeCount).toBe(2)
2936
})
37+
38+
it('should show only active todos', ()=> {
39+
let mainSection = TestUtils.renderIntoDocument(
40+
<Most>
41+
<MainSection
42+
todos={defaultTodos}
43+
filter={FILTER_FUNC['SHOW_ACTIVE']}
44+
/>
45+
</Most>
46+
)
47+
let todoItems = TestUtils.scryRenderedComponentsWithType(mainSection, TodoItem);
48+
expect(todoItems.map(item=>item.props.todo.id)).toEqual(
49+
[0,1])
50+
})
51+
52+
it('should show only done todos', ()=> {
53+
let mainSection = TestUtils.renderIntoDocument(
54+
<Most>
55+
<MainSection
56+
todos={defaultTodos}
57+
filter={FILTER_FUNC['SHOW_COMPLETED']}
58+
/>
59+
</Most>
60+
)
61+
let todoItems = TestUtils.scryRenderedComponentsWithType(mainSection, TodoItem);
62+
expect(todoItems.map(item=>item.props.todo.id)).toEqual(
63+
[2])
64+
})
3065
})
3166

32-
describe('behavior', ()=> {
67+
describe('Behavior', ()=> {
3368
let mainSectionWrapper, mainSection, send
34-
let response = '[{"text": "Try React Most","completed": false,"id": 0},{"text": "Give it a Star on Github","completed": false,"id": 1}]'
3569
beforeEach(()=>{
36-
rest.__return(response)
3770
mainSectionWrapper = TestUtils.renderIntoDocument(
3871
<Most>
3972
<MainSection history={true}/>
@@ -48,30 +81,30 @@ describe('MainSection', ()=>{
4881
{id:0, text:'Loading...dadada', done:false},
4982
])
5083
})
51-
it('should get data from rest response to MainSection', ()=>{
52-
return historyStreamOf(mainSection).take$(1).then(state=>expect(state.todos).toEqual(JSON.parse(response)))
84+
it('should get data from rest response to MainSection', ()=>{
85+
return historyStreamOf(mainSection).take$(1).then(state=>expect(state.todos).toEqual(JSON.parse(RESPONSE)))
5386
})
5487
});
5588

56-
describe('edit sink', ()=>{
57-
it('should update todo 0 item text', ()=>{
89+
describe('edit', ()=>{
90+
it('should update todo id 0 item text', ()=>{
5891
do$([
59-
()=>send(Intent.Edit({id:0, text:'hehedayo'})),
92+
()=>send(Intent.Edit({id:0, text:'hehedayo'}, 0)),
6093
])
6194
return historyStreamOf(mainSection).take$(2).then(state=>expect(state.todos[0]).toEqual({"id": 0, "text": "hehedayo"}))
6295
})
6396
});
6497

65-
describe('clear sink', ()=> {
98+
describe('clear', ()=> {
6699
it('should remove all done todos', ()=>{
67100
do$([
68-
()=>send(Intent.Edit({id:0,text:'done',completed:true})),
101+
()=>send(Intent.Edit({id:0,text:'done',done:true}, 0)),
69102
()=>send(Intent.Clear()),
70103
])
71104
return historyStreamOf(mainSection)
72105
.take$(3)
73106
.then(state=>{
74-
expect(state.todos).toEqual([{"completed": false, "id": 1, "text": "Give it a Star on Github"}])
107+
expect(state.todos).toEqual([{"done": false, "id": 1, "text": "Give it a Star on Github"}])
75108
})
76109
})
77110
})

0 commit comments

Comments
 (0)