Skip to content

Instantly share code, notes, and snippets.

@cristianp6
Last active August 23, 2019 14:11
Show Gist options
  • Save cristianp6/1678b63d73a4415f523658d251b010ae to your computer and use it in GitHub Desktop.
Save cristianp6/1678b63d73a4415f523658d251b010ae to your computer and use it in GitHub Desktop.
Typed Meiosis with Function Patches and mithril-stream
import stream from 'mithril/stream'
import * as Stream from 'mithril/stream'
export type StatePatch<S> = (state: S) => S
export type AppState = {
step: string
}
export type AppActions = {
show: (step: string) => void
}
const app = ({
initial: (): AppState => ({
step: '',
}),
actions: (update: Stream<StatePatch<AppState>>): AppActions => {
return ({
show: (step) => {
update((state: AppState) => {
return Object.assign(state, { step })
})
}
})
}
})
const update = stream<StatePatch<AppState>>()
const states = Stream.scan<StatePatch<AppState>, AppState>(
(state, patch) => patch(state),
app.initial(),
update
)
const actions = app.actions(update)
export {
actions,
states,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment