Last active
October 6, 2019 23:38
-
-
Save WreckedAvent/9b3b1580e945c44d741e868abf73eef8 to your computer and use it in GitHub Desktop.
basic data flow example
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
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 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(breadcrumbs, { link: model.nav.link() }), | |
view | |
]) |
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
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 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 modelFactory from './sharedModel' | |
// 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 = modelFactory | |
// 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(sharedView, state) |
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
import * as sharedView from './sharedView' | |
import modelFactory from './sharedModel' | |
// 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 = modelFactory | |
// 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(sharedView, state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment