dchambers / composerjs

The composable modelling library
1 stars 1 forks source link

What do we do when handlers refer to properties that may not exist? #24

Closed dchambers closed 9 years ago

dchambers commented 9 years ago

In the recursion section we see the following snippet of code:

node.addOptionalNode('leaf1');
node.addOptionalNode('leaf2');
node.set('value', 1);
node.addHandler([p('leaf1.value').as('value1'), p('leaf2.value').as('value2')], ['sum'], function(input, output) {
  output.sum = input.value1 + input.value2;
});
node.leaf1.defineAs(node);
node.leaf2.defineAs(node);

but this line of code contains references to properties that may or may not exist:

output.sum = input.value1 + input.value2;

What we should we do about this?

We could:

  1. Don't run the handler until all properties become available, but there may be use cases where we want the option to run the code anyway.
  2. Allow the code to check if the properties are null or not.
  3. Something else?