view.json

Shims

Switching shims

jQuery

The jQuery shim uses jQuery to perform DOM operations.

DOM

The DOM shim uses the DOM directly to perform DOM operations. It is the largest shim, about ~200 lines, since it actually implements the operations natively instead of delegating to another library. Compared to jQuery or even Zepto, it is much smaller, but also less well tested (it is essentially a subset of Zepto).

Node

The Node shim emulates a DOM inside Node.js, making it possible to render and interact with views without a real DOM. The DOM is emulated as a plain object tree (of elements with properties), and can be converted into the corresponding HTML for storage or for responding to a client.

The Node shim can be instantiated multiple times. This is because you can have multiple "documents" (DOM environments) within Node; this makes it possible for a server to render multiple pages at the same time for different clients.

Debug

The debug shim can take any other shim, and wrap it so as to collect statistics about the calls made to the shim.

This makes it possible to find out how many DOM operations were needed to perform a render, and how the DOM changed as the result of an action. You could also replace the shim with another dependency to capture information about DOM and event registrations.

Shim functions

The shim functions generally follow the jQuery conventions for names. You can access these functions from the view, though you probably only want to use the first four. append, before and remove are only used by the CollectionView. replaceWith is only used by the ConditionalView.

  • html(token, value)
  • attr(token, value)
  • css(token, value)
  • toggle(token, value)
  • append(token, value)
  • before(token, value)
  • remove(token)
  • onDom(token, event, callback)
  • replaceWith(token, html)
  • id()
  • embed(tag, attr, content)
  • on(event, callback)