Skip to content
Ulric Wilfred edited this page Jan 30, 2015 · 4 revisions

Description

Stores the Model of the Node Network, the root for all the events. Manages nodes.

Events

  • model/new(Model) — fired when new model was started; {model}
  • node/add(Node) — fired when new node was added to this model; {node}
  • node/remove(Node) — fired when a node was removed from this model; {node}

Methods

static

  • Model.start([String])Model — static method to create a new model, takes optional model name;

instance

  • model.renderWith(String)Model — use given renderer to render this model, i.e. 'html', 'canvas', 'svg';
  • model.attachTo(DOMElement)Model — render this model to the given element;
  • model.addNode(Node)Model — add a node to the model; don't use it, though, since new nodes are always automatically added to current model;
  • model.removeNode(Node)Model — remove node from the model;

Examples

Create an empty model:

Rpd.Model.start().renderWith('html')
                 .attachTo(document.body);

Start new model and add a node to it:

Rpd.Model.start().renderWith('html')
                 .attachTo(document.body);
// new nodes are added automatically to current model
var node = new Rpd.Node('core/empty', 'Empty');

Subscribe to node/add event:

// there's no canvas renderer for now, it's just an example
var model = Rpd.Model.start('my-model')
                     .renderWith('canvas')
                     .attachTo(document.getElementById('target'));
model.event['node/add'].onValue(function(node) {
    console.log(node);
});
Clone this wiki locally