dchambers / composerjs

The composable modelling library
1 stars 1 forks source link

FUTURE: Allow handlers to add and remove nodes #36

Open dchambers opened 9 years ago

dchambers commented 9 years ago

Handlers aren't presently allowed to add and remove nodes, since the only way to do that at present is via the public API, use of which hampers composability. Instead, if the parts of the public API used to add and remove nodes could optionally be mapped to a handler's properties, this would allow handlers to affect node cardinality yet remain composable.

Suppose, for example, we could add a handler using this notation:

person.set('married', false);
person.addDisabledNode('spouse');
person.spouse.addHandler([p('../married').as('married')], [('@exists').as('hasSpouse')], function(input, output, current, modified) {
    output.hasSpouse = input.married;
});

In this way, the node.exists(), node.create(), node.dispose() & nodes.removeNode() methods can all effectively be made available to handlers by referring to @exists in either input or output properties.

Similarly, @length could be used to make nodes.length() available, and @additions could be used to make nodes.addNode() available, where @additions can be passed an array of indices where new nodes will be created.

dchambers commented 9 years ago

@james-shaw-turner, although this can implemented after an initial release, I think this is a nice feature you should be aware of as it will enable all re-usable functionality to be expressed using handlers.