-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.js
47 lines (37 loc) · 1.13 KB
/
ajax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React from 'react';
import {render} from 'react-dom';
import Router from 'falcor-router';
import {Root, Get, Model, routeByCollectionId} from '../src';
// import {renderToString} from '../src/server';
import 'isomorphic-fetch';
// a 'service' that fetches user details from github
const user = async id =>
await (await fetch(`https://api.github.com/users/${id}`)).json();
const model = new Model({
cache: {input: 'octocat'},
source: new Router([
routeByCollectionId('users', user)
])
});
export function App(){
return <Root model={model}>
<Search/>
</Root>;
}
function Search(){
return <Get query='input'>{
({input = 'octocat', $}) =>
<div>
<input value={input} onChange={e => $.setValue('input', e.target.value)}/>
<Get query={`users.${input}['avatar_url', 'name']`}>{
({users, loading}) =>
<div>
{loading ? 'loading...' : null}
<pre>{JSON.stringify(users, null, ' ')}</pre>
</div>
}</Get>
</div>
}</Get>;
}
render(<App/>, document.getElementById('app'));
// renderToString(<App/>, model).then(::console.log);