Skip to content

Instantly share code, notes, and snippets.

@pmros pmros/README.md
Created Jul 7, 2016

Embed
What would you like to do?
Composition in Act
import guard from '@act/main/helpers/reducer/guard'
const view = (state) =>
state.status === 'confirm' ? viewConfirm(state) : viewWaiting(state)
const viewConfirm = (state) =>
['span', [
['button', {click: 'cancelSubmit'}, 'Cancel'],
['button', {click: 'confirmSubmit'}, 'Confirm']
]]
const viewWaiting = (state) =>
['button', {click: 'maybeSubmit', disabled: state.disabled}, 'Submit']
const reducer = guard({
maybeSubmit: (state, payload) => ({...state, status: 'confirm'}),
cancelSubmit: (state, payload) => ({...state, status: 'waiting'})
})
export default { view, reducer, model: { status: 'waiting', disabled: true } }
import confirm from './submission'
import main from '@act/main/devtools'
const { view, model, reducer } = confirm
main(view, { model, reducer })
import confirm from './confirm'
import nest from '@act/main/nest'
import guard from '@act/main/helpers/reducer/guard'
import value from '@act/main/processes/value'
const view = (state) =>
['div', [
['input', {value: state.field, keyup: {setField: value}}],
nest.view('confirm', confirm.view(state.confirm)),
['p', `Submitted value: ${state.submission}`]
]]
const reducerConfirm = nest.reducers({ confirm: confirm.reducer })
const reducer = (state, { type, payload }) => {
switch (type) {
case 'setField':
return {...state, field: payload,
confirm: {...state.confirm, disabled: !payload}}
case 'confirm.confirmSubmit':
return {...state, field: '', submission: state.field}
default:
return reducerConfirm(state, { type, payload })
}
}
const model = {
field: '',
submission: '',
confirm: confirm.model
}
export default { view, reducer, model }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.