Mithril Basic Stuff

by ramnathv

HTML

<div id="app"></div>

CSS

#app{margin-top: 20px;}

JavaScript

Page = 
  view: (ctrl, props) ->
    m '.container', 
      m '.row', 
        m '.col-xs-6.col-md-6', props.children

TextInput = 
  view: (ctrl, props) ->
    m 'input.form-control[type="text"]', {
      oninput: m.withAttr("value", props.value)
      value: props.value()
    }
  
View = 
  controller: ->
    value: m.prop("")
  view: (ctrl, props) ->
    m 'div',
      m TextInput, {value: ctrl.value}
      m 'h2', ctrl.value()
App = 
  view: (ctrl, props) ->
    m Page, {children:  m View}
    
m.mount(
  document.getElementById("app"),
  m App
)