Last active
April 4, 2018 23:36
-
-
Save jmas/afb39dc66748d9e4b57f0030b0365fdf to your computer and use it in GitHub Desktop.
alahaka.js
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
const edit = { | |
initialState: null, | |
actions: { | |
edit: something => state => something | |
}, | |
view: (state, dispatch, connect) => ( | |
<div> | |
Editing: {JSON.stringify(state)} | |
<button onClick={() => dispatch(edit.actions.edit({ name: 'Name!' }))}>Edit!</button> | |
</div> | |
) | |
} | |
const events = { | |
initialState: { | |
events: [], | |
editing: edit.initialState | |
}, | |
actions: { | |
edit: edit.actions.edit | |
}, | |
view: (state, dispatch, connect) => ( | |
<div> | |
Events: {JSON.stringify(state.editing)} | |
<button onClick={() => dispatch(users.actions.edit({ name: 'Name!' }))}>Edit</button> | |
</div> | |
) | |
} | |
const users = { | |
initialState: { | |
users: [], | |
editing: null | |
}, | |
actions: { | |
edit: user => state => ({ | |
...state, | |
editing: user | |
}) | |
}, | |
view: (state, dispatch, connect) => ( | |
<div> | |
Users: {JSON.stringify(state.editing)} | |
<button onClick={() => dispatch(users.actions.edit({ name: 'Name!' }))}>Edit</button> | |
</div> | |
) | |
} | |
const initialState = { | |
events: events.initialState, | |
users: users.initialState | |
} | |
app(initialState, (state, dispatch, connect) => ( | |
<div> | |
{connect('events', events.view, state => dispatch())})} | |
{connect('users', users.view, state => dispatch())})} | |
</div> | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment