Skip to content

Instantly share code, notes, and snippets.

@alshdavid
Created May 15, 2019 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alshdavid/9414064aefdc2547d77c9045a7a74c47 to your computer and use it in GitHub Desktop.
Save alshdavid/9414064aefdc2547d77c9045a7a74c47 to your computer and use it in GitHub Desktop.
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>
}
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