0.2.0 • Published 10 years ago

vnode-immutable-thunk v0.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

vnode-immutable-thunk

An immutable thunk optimization for virtual-dom.

Build Status npm version

Installation

npm install vnode-immutable-thunk

Example

Use ImmutableThunk when you want to avoid rerendering subtrees. ImmutableThunk will only reevaluate the subtree if the argument you pass to it change. This means you should use an immutable data structure.

var ImmutableThunk = require('vnode-immutable-thunk');
var h = require('virtual-dom/h');

function render(state) {
  return h('div', [
    ImmutableThunk(header, state.head),
    main(),
    ImmutableThunk(footer, state.foot)
  ]);
}

function header(head) { ... }
function main() { ... }
function footer(foot) { ... }

The above example demonstrates how we can only evaluate the header() function when state.head changes. The ImmutableThunk will internally cache the previous state.head and not re-evaluate the expensive header() function unless the state.head state has changed.

Docs

See API reference.

Author

Alexander Kurakin <kuraga333@mail.ru>

Inspired by

Inspired by vdom-thunk.

Feedback and contribute

https://github.com/kuraga/vnode-immutable-thunk/issues

License

MIT