Created
May 15, 2019 12:35
-
-
Save alshdavid/9414064aefdc2547d77c9045a7a74c47 to your computer and use it in GitHub Desktop.
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
import React from 'react' | |
import * as item from './item' | |
export const ListView = (store) => () => { | |
const [ items, setItems ] = useState([]) | |
useEffect(() => { | |
const sub = store.onChanges(items => setItems(items)) | |
return () => sub() | |
}, [ store ]) | |
const add = () => { | |
const value = prompt('Name of todo') | |
store.add(item.create(value)) | |
} | |
return <main> | |
<button>Add</button> | |
<ul> | |
{ items.map(item => ( | |
<li | |
onClick={() => store.complete(item.id)} | |
key={item.id}> | |
{item.body} | |
</li> | |
)} | |
</ul> | |
</main> | |
} |
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
import * as crayon from 'crayon' | |
import * as react from 'crayon/react' | |
import * as item from './item' | |
import { ListView } from './list-view' | |
// Creating store | |
const store = item.createStore() | |
// Creating router | |
const app = crayon.create() | |
app.use(react.router()) | |
// Using property injection to pass the store into my component | |
app.path('/', (res, res) => res.mount(ListView(store))) | |
app.load() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment