Level: beginner • Mithril.js Version: latest
form m.mount m.stream two-way-binding
This is an example showing two-way binding with Mithril.js' own stream library.
Here we can see the use of m.stream
for a single variable which is then updated in the oninput event handler.
Type | Name | URL |
---|---|---|
script | mithril@latest | https://unpkg.com/mithril@latest |
script | mithril-stream/stream.js | https://unpkg.com/mithril-stream/stream.js |
const s = m.stream
const app = () => {
const text = s('')
return {
view: () => [
m('h1', `text: ${text()}`),
m('input', {
oninput: e => text(e.target.value)
})
]
}
}
m.mount(document.body, app)
The snippet requires the latest version of Mithril.js framework. It is ideal for beginners showing some basic recipes.
In this example we can see some Mithril.js API methods like m.stream
or m.mount
, besides Mithril.js' basic m() hyperscript function.
The code sample was authored by osban. It was last modified on 24 September 2020. Want to see more examples written by osban? Then Click here.
Do you see some improvements, that could be addressed here? Then let me know by opening an issue. As an alternative, you can fork the repository on GitHub, push your commits and send a pull request. To start your work, click on the edit link below. Thank you for contributing to this repo.