git ssb

1+

Matt McKegg / mutant



Tree:
📄.gitignore
📄LICENSE
📄README.md
📄array.js
📄computed.js
📄concat.js
📄dict-to-collection.js
📄dict.js
📄for-each-pair.js
📄for-each.js
📄html-element.js
📄is-observable.js
📄keys.js
📁lib
📄lookup.js
📄map.js
📄mapped-array.js
📄mapped-dict.js
📄merge.js
📄package.json
📄proxy-collection.js
📄proxy-dict.js
📄proxy.js
📄resolve.js
📄send.js
📄set.js
📄struct.js
📁test
📄throttle.js
📄value.js
📄watch-all.js
📄watch-throttle.js
📄watch.js
📄when.js
README.md

mutant

Create observables and map them to DOM elements. Massively inspired by hyperscript and observ-*.

No virtual dom, just direct observable bindings. Unnecessary garbage collection is avoided by using mutable objects instead of blasting immutable junk all over the place.

Current Status: Experimental / Maintained

Expect breaking changes.

Used By

Install

npm install @mmckegg/mutant --save

Compatibility

Requires an environment that supports:

Use

var h = require('@mmckegg/mutant/html-element')
var Struct = require('@mmckegg/mutant/struct')
var send = require('@mmckegg/mutant/send')
var computed = require('@mmckegg/mutant/computed')
var when = require('@mmckegg/mutant/when')

var state = Struct({
  text: 'Test',
  color: 'red',
  value: 0
})

var isBlue = computed([state.color], color => color === 'blue')

var element = h('div.cool', {
  classList: ['cool', state.text],
  style: {
    'background-color': state.color
  }
}, [
  h('div', [
    state.text, ' ', state.value, ' ', h('strong', 'test')
  ]),
  h('div', [
    when(isBlue,
      h('button', {
        'ev-click': send(state.color.set, 'red')
      }, 'Change color to red'),
      h('button', {
        'ev-click': send(state.color.set, 'blue')
      }, 'Change color to blue')
    )

  ])
])

setTimeout(function () {
  state.text.set('Another value')
}, 5000)

setInterval(function () {
  state.value.set(state.value() + 1)
}, 1000)

setInterval(function () {
  // bulk update state
  state.set({
    text: 'Retrieved from server (not really)',
    color: '#FFEECC',
    value: 1337
  })
}, 10000)

document.body.appendChild(element)

License

MIT

Built with git-ssb-web