Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Latest commit

 

History

History
21 lines (14 loc) · 942 Bytes

rendering.md

File metadata and controls

21 lines (14 loc) · 942 Bytes

Rendering

When you have assembled your modules and populated them with the required data you can call .render(). Render recursively renders the nested module structure by calling each module's render function, from the bottom up, and then turns the output html string into a DOM node (view.el). Module#render() (like most module methods) returns the module instance (this) to allow for chaining.

Re-rendering

Often data changes and you need to re-render your modules. Render replaces the root element with a new one, which means you can easily keep Views up to date. This will remove any child module elements and immediately re-mount them.

var model = new fruitmachine.Model({ name: 'Wilson' });
var apple = new Apple({ model: model });

apple
  .render()
  .inject(document.body);

//...some time later

apple.model.set('name', 'Matt');
apple.render();