Skip to content

Commit 7f66db2

Browse files
committed
updating examples
1 parent 67f1316 commit 7f66db2

File tree

7 files changed

+107
-107
lines changed

7 files changed

+107
-107
lines changed

examples/auth-flow/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var App = React.createClass({
3434
<li><Link to="about">About</Link></li>
3535
<li><Link to="dashboard">Dashboard</Link> (authenticated)</li>
3636
</ul>
37-
{this.props.activeRouteHandler()}
37+
<this.props.activeRouteHandler />
3838
</div>
3939
);
4040
}

examples/data-flow/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var App = React.createClass({
4545
{links}
4646
</ul>
4747
<div className="Detail">
48-
{this.props.activeRouteHandler({onRemoveTaco: this.handleRemoveTaco})}
48+
<this.props.activeRouteHandler onRemoveTaco={this.handleRemoveTaco} />
4949
</div>
5050
</div>
5151
);

examples/dynamic-segments/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var App = React.createClass({
1414
<li><Link to="user" params={{userId: "123"}}>Bob</Link></li>
1515
<li><Link to="user" params={{userId: "abc"}}>Sally</Link></li>
1616
</ul>
17-
{this.props.activeRouteHandler()}
17+
<this.props.activeRouteHandler />
1818
</div>
1919
);
2020
}
@@ -29,7 +29,7 @@ var User = React.createClass({
2929
<li><Link to="task" params={{userId: this.props.params.userId, taskId: "foo"}}>foo task</Link></li>
3030
<li><Link to="task" params={{userId: this.props.params.userId, taskId: "bar"}}>bar task</Link></li>
3131
</ul>
32-
{this.props.activeRouteHandler()}
32+
<this.props.activeRouteHandler />
3333
</div>
3434
);
3535
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
var API = 'http://addressbook-api.herokuapp.com/contacts';
2+
var _contacts = {};
3+
var _changeListeners = [];
4+
var _initCalled = false;
5+
6+
var ContactStore = module.exports = {
7+
8+
init: function () {
9+
if (_initCalled)
10+
return;
11+
12+
_initCalled = true;
13+
14+
getJSON(API, function (err, res) {
15+
res.contacts.forEach(function (contact) {
16+
_contacts[contact.id] = contact;
17+
});
18+
19+
ContactStore.notifyChange();
20+
});
21+
},
22+
23+
addContact: function (contact, cb) {
24+
postJSON(API, { contact: contact }, function (res) {
25+
_contacts[res.contact.id] = res.contact;
26+
ContactStore.notifyChange();
27+
if (cb) cb(res.contact);
28+
});
29+
},
30+
31+
removeContact: function (id, cb) {
32+
deleteJSON(API + '/' + id, cb);
33+
delete _contacts[id];
34+
ContactStore.notifyChange();
35+
},
36+
37+
getContacts: function () {
38+
var array = [];
39+
40+
for (var id in _contacts)
41+
array.push(_contacts[id]);
42+
43+
return array;
44+
},
45+
46+
getContact: function (id) {
47+
return _contacts[id];
48+
},
49+
50+
notifyChange: function () {
51+
_changeListeners.forEach(function (listener) {
52+
listener();
53+
});
54+
},
55+
56+
addChangeListener: function (listener) {
57+
_changeListeners.push(listener);
58+
},
59+
60+
removeChangeListener: function (listener) {
61+
_changeListeners = _changeListeners.filter(function (l) {
62+
return listener !== l;
63+
});
64+
}
65+
66+
};
67+
68+
function getJSON(url, cb) {
69+
var req = new XMLHttpRequest();
70+
req.onload = function() {
71+
if (req.status === 404) {
72+
cb(new Error('not found'));
73+
} else {
74+
cb(null, JSON.parse(req.response));
75+
}
76+
};
77+
req.open('GET', url);
78+
req.send();
79+
}
80+
81+
function postJSON(url, obj, cb) {
82+
var req = new XMLHttpRequest();
83+
req.onload = function() {
84+
cb(JSON.parse(req.response));
85+
};
86+
req.open('POST', url);
87+
req.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
88+
req.send(JSON.stringify(obj));
89+
}
90+
91+
function deleteJSON(url, cb) {
92+
var req = new XMLHttpRequest();
93+
req.onload = cb;
94+
req.open('DELETE', url);
95+
req.send();
96+
}
97+
98+

examples/master-detail/app.js

Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -6,73 +6,7 @@ var DefaultRoute = Router.DefaultRoute;
66
var Routes = Router.Routes;
77
var Link = Router.Link;
88
var NotFoundRoute = Router.NotFoundRoute;
9-
10-
var api = 'http://addressbook-api.herokuapp.com/contacts';
11-
var _contacts = {};
12-
var _changeListeners = [];
13-
var _initCalled = false;
14-
15-
var ContactStore = {
16-
17-
init: function () {
18-
if (_initCalled)
19-
return;
20-
21-
_initCalled = true;
22-
23-
getJSON(api, function (err, res) {
24-
res.contacts.forEach(function (contact) {
25-
_contacts[contact.id] = contact;
26-
});
27-
28-
ContactStore.notifyChange();
29-
});
30-
},
31-
32-
addContact: function (contact, cb) {
33-
postJSON(api, { contact: contact }, function (res) {
34-
_contacts[res.contact.id] = res.contact;
35-
ContactStore.notifyChange();
36-
if (cb) cb(res.contact);
37-
});
38-
},
39-
40-
removeContact: function (id, cb) {
41-
deleteJSON(api + '/' + id, cb);
42-
delete _contacts[id];
43-
ContactStore.notifyChange();
44-
},
45-
46-
getContacts: function () {
47-
var array = [];
48-
49-
for (var id in _contacts)
50-
array.push(_contacts[id]);
51-
52-
return array;
53-
},
54-
55-
getContact: function (id) {
56-
return _contacts[id];
57-
},
58-
59-
notifyChange: function () {
60-
_changeListeners.forEach(function (listener) {
61-
listener();
62-
});
63-
},
64-
65-
addChangeListener: function (listener) {
66-
_changeListeners.push(listener);
67-
},
68-
69-
removeChangeListener: function (listener) {
70-
_changeListeners = _changeListeners.filter(function (l) {
71-
return listener !== l;
72-
});
73-
}
74-
75-
};
9+
var ContactStore = require('./ContactStore');
7610

7711
var App = React.createClass({
7812
getInitialState: function() {
@@ -219,38 +153,6 @@ var NotFound = React.createClass({
219153
}
220154
});
221155

222-
// Request utils.
223-
224-
function getJSON(url, cb) {
225-
var req = new XMLHttpRequest();
226-
req.onload = function() {
227-
if (req.status === 404) {
228-
cb(new Error('not found'));
229-
} else {
230-
cb(null, JSON.parse(req.response));
231-
}
232-
};
233-
req.open('GET', url);
234-
req.send();
235-
}
236-
237-
function postJSON(url, obj, cb) {
238-
var req = new XMLHttpRequest();
239-
req.onload = function() {
240-
cb(JSON.parse(req.response));
241-
};
242-
req.open('POST', url);
243-
req.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
244-
req.send(JSON.stringify(obj));
245-
}
246-
247-
function deleteJSON(url, cb) {
248-
var req = new XMLHttpRequest();
249-
req.onload = cb;
250-
req.open('DELETE', url);
251-
req.send();
252-
}
253-
254156
var routes = (
255157
<Route handler={App}>
256158
<DefaultRoute handler={Index}/>

examples/query-params/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var App = React.createClass({
1414
<li><Link to="user" params={{userId: "123"}} query={{showAge: true}}>Bob With Query Params</Link></li>
1515
<li><Link to="user" params={{userId: "abc"}}>Sally</Link></li>
1616
</ul>
17-
{this.props.activeRouteHandler()}
17+
<this.props.activeRouteHandler />
1818
</div>
1919
);
2020
}

examples/shared-root/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var App = React.createClass({
1414
<li><Link to="signin">Sign in</Link></li>
1515
<li><Link to="forgot-password">Forgot Password</Link></li>
1616
</ol>
17-
{this.props.activeRouteHandler()}
17+
<this.props.activeRouteHandler />
1818
</div>
1919
);
2020
}
@@ -25,7 +25,7 @@ var SignedIn = React.createClass({
2525
return (
2626
<div>
2727
<h2>Signed In</h2>
28-
{this.props.activeRouteHandler()}
28+
<this.props.activeRouteHandler />
2929
</div>
3030
);
3131
}
@@ -44,7 +44,7 @@ var SignedOut = React.createClass({
4444
return (
4545
<div>
4646
<h2>Signed Out</h2>
47-
{this.props.activeRouteHandler()}
47+
<this.props.activeRouteHandler />
4848
</div>
4949
);
5050
}

0 commit comments

Comments
 (0)