Skip to content

Commit fba438e

Browse files
author
Vlad Balin
committed
Merge remote-tracking branch 'refs/remotes/origin/develop'
# Conflicts: # README.md # examples/todomvc/app.js # examples/todomvc/app.js.map # nestedreact.js # nestedreact.js.map # package.json
2 parents bc53afe + ee80c4c commit fba438e

17 files changed

+43155
-126
lines changed

examples/todomvc/js/main.jsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
11
import 'css/app.css'
22
import React from 'nestedreact'
33
import ReactDOM from 'react-dom'
4-
import { ToDo, LocalStorage } from './model.js'
4+
import {ToDo} from './model.js'
55
import TodoList from './todolist.jsx'
66
import Filter from './filter.jsx'
77
import AddTodo from './addtodo.jsx'
88

99
const App = React.createClass( {
10-
Model : LocalStorage,
11-
10+
// Declare component state
1211
state : {
13-
id : 'todo-mvc',
1412
todos : ToDo.Collection,
15-
filterDone : Boolean.value( null )
13+
filterDone : Boolean.value( null ) // null | true | false, initialized with null.
1614
},
1715

1816
componentWillMount(){
19-
this.state.fetch();
20-
window.onunload = () => this.state.save();
17+
const { state } = this,
18+
// load raw JSON from local storage
19+
json = JSON.parse( localStorage.getItem( 'todo-mvc' ) || "{}" );
20+
21+
// initialize state with raw JSON
22+
state.set( json, { parse : true } );
23+
24+
window.onunload = () =>{
25+
// Save state back to the local storage
26+
localStorage.setItem( 'todo-mvc', JSON.stringify( state ) );
27+
}
2128
},
2229

2330
render(){
24-
const { state } = this,
25-
hasTodos = Boolean( state.todos.length );
31+
const { todos, filterDone } = this.state,
32+
hasTodos = Boolean( todos.length );
2633

2734
return (
2835
<div>
2936
<section className="todoapp">
30-
<AddTodo onEnter={ desc => state.todos.add({ desc : desc }) }/>
37+
<AddTodo onEnter={ desc => todos.add({ desc : desc }) }/>
3138

32-
{ hasTodos && <TodoList todos={ state.todos }
33-
filterDone={ state.filterDone }/> }
39+
{ hasTodos && <TodoList todos={ todos }
40+
filterDone={ filterDone }/> }
3441

35-
{ hasTodos && <Filter count={ state.todos.activeCount }
36-
filterLink={ state.getLink( 'filterDone' )}
37-
onClear={ () => state.todos.clearCompleted() }
42+
{ hasTodos && <Filter count={ todos.activeCount }
43+
filterLink={ this.state.getLink( 'filterDone' ) }
44+
onClear={ () => todos.clearCompleted() }
3845
/>}
3946
</section>
4047

examples/todomvc/js/model.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,3 @@ export const ToDo = Model.extend({
3434
}
3535
}
3636
});
37-
38-
export const LocalStorage = Model.extend({
39-
fetch(){
40-
if( this.id ){
41-
const json = localStorage.getItem( this.id );
42-
json && ( this.set( JSON.parse( json ), { parse: true }) );
43-
}
44-
},
45-
46-
save( attrs ){
47-
if( attrs ){
48-
this.set( attrs );
49-
}
50-
51-
if( this.id ){
52-
localStorage.setItem( this.id, JSON.stringify( this ) );
53-
}
54-
}
55-
});

examples/todomvc/js/todolist.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ const TodoList = React.createClass( {
1818

1919
render(){
2020
const { todos, filterDone } = this.props,
21-
filtered = filterDone === null ?
22-
todos.models
21+
filtered = filterDone === null ? todos.models
2322
: todos.filter( todo => todo.done === filterDone ),
2423

2524
editingLink = this.state.getLink( 'editing' );
@@ -62,7 +61,7 @@ const TodoItem = ( { todo, editingLink } ) =>{
6261
<Input className="toggle" type="checkbox"
6362
checkedLink={ todo.getLink( 'done' ) }/>
6463

65-
<label onDoubleClick={ () => editingLink.set( todo ) }>
64+
<label onDoubleClick={ editingLink.action( () => todo ) }>
6665
{ todo.desc }
6766
</label>
6867

@@ -72,7 +71,7 @@ const TodoItem = ( { todo, editingLink } ) =>{
7271
{ editing && <Input className="edit"
7372
valueLink={ todo.getLink( 'desc' ) }
7473
autoFocus={ true }
75-
onBlur={ () => editingLink.set( null ) }
74+
onBlur={ editingLink.action( () => null ) }
7675
onKeyDown={ editingLink.action( clearOnEnter ) }/> }
7776
</li>
7877
);

examples/todomvc/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"classnames": "^2.2.0",
1313
"css-loader": "^0.23.0",
1414
"jquery": "^2.1.4",
15-
"nestedreact": "^0.6.0-rc0",
15+
"nestedreact": "^1.0.0-rc0",
1616
"nestedtypes": "^1.3.2-rc0",
17-
"react": "^0.14.2",
18-
"react-dom": "^0.14.2",
17+
"react": "^15.0.0",
18+
"react-dom": "^15.0.0",
1919
"react-router": "^1.0.0",
2020
"style-loader": "^0.13.0",
2121
"underscore": "^1.8.3",

examples/userslist/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# UsersList Example
2+
3+
Here's the UsersList application example, written originally for NestedLink.
4+
5+
It's changed to use NestedReact. Feel the difference.
6+
7+
NestedLink data binding is so powerful that there are no any difference
8+
in size, so expressiveness is roughly the same.
9+
10+
But. Check out how much less magical NestedReact solution feels - compare the code.
11+
12+
In fact, there's an incredible amount of dirty magic involved,
13+
just to make you feel that there are no any magic at all :).
14+
15+
That's NestedReact. Relax, and write in natural way, no tricks are required.

0 commit comments

Comments
 (0)