-
-
Save orbitbot/0c854140630d03c9b7a533072b420498 to your computer and use it in GitHub Desktop.
basic data flow example
This file contains hidden or 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 m from 'mithril' | |
import * as x from './x' | |
import * as y from './y' | |
m.route(document.body, '/', { | |
'x': x, | |
'y': y | |
}) |
This file contains hidden or 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 m from 'mithril' | |
import * as breadcrumbs from './breadcrumbs' | |
// this is a "container" compnoent and is aware of at least some of our model | |
export const view = (_, { model, view }) => m('.container', [ | |
m.component(breadcrumbs, { link: model.nav.link() }), | |
view | |
]) |
This file contains hidden or 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 m from 'mithril' | |
// we only export a factory so components cannot inexplicably require our state out of proper flow | |
export default () => ({ | |
nav: { | |
link: m.prop() | |
}, | |
main: { | |
something: m.prop() | |
} | |
}) |
This file contains hidden or 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 m from 'mithril' | |
// this is a "presentation" component and knows nothing about the world | |
export const view = (_, { text }) => m('p', text) |
This file contains hidden or 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 sharedView from './sharedView' | |
import model from './model' | |
// controller is understandable as our view's state | |
// we make it our model factory function so that we get | |
// a fresh state as the component is created | |
export const controller = model | |
// in a real app, we'd have more diversity between our views, | |
// but here we just call the shared view component directly in this toy example | |
export const view = (state) => m.component(sharedView, state) |
This file contains hidden or 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 sharedView from './sharedView' | |
import model from './model' | |
// controller is understandable as our view's state | |
// we make it our model factory function so that we get | |
// a fresh state as the component is created | |
export const controller = model | |
// in a real app, we'd have more diversity between our views, | |
// but here we just call the shared view component directly in this toy example | |
export const view = (state) => m.component(sharedView, state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment