Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the node accessor to create composite nodes #18

Closed
shiftyp opened this issue Jul 12, 2016 · 0 comments
Closed

Extend the node accessor to create composite nodes #18

shiftyp opened this issue Jul 12, 2016 · 0 comments
Assignees
Milestone

Comments

@shiftyp
Copy link
Owner

shiftyp commented Jul 12, 2016

The idea here would be to not limit nodes to a particular tree shape, and allow you to create new nodes that are composites of other nodes in the tree. The api might look something like this:

const state = createState({
  foo: {
    bar: 1,
    baz: 2
  },
  quz: 3
});

const composite = state.compose({
  baz: 'foo.baz',
  qux: 'qux'
});

Then you could reduce this node using the defined keys, and the state of both the composite node, the original nodes, and their original parent nodes would be updated.

const action = createAction();

composite.reduce(action, (compositeState, val) => {
  return {
    baz: compositeState.baz + val,
    qux: compositeState.qux + val  
  };
});

state('foo.baz').asObservable()
  .subscribe(val => console.log(val));

state.connect();
// 2
action(3);
// 6

The main use for this feature wouldn't be reducing the composite node, but rather subscribing to the composite node. So if you have a component in your view system that requires widespread elements of state you could create a composite observable to observe when those properties change.

@shiftyp shiftyp added this to the v0.4.0 milestone Jul 12, 2016
shiftyp added a commit that referenced this issue Jul 13, 2016
#18: Added compose function to nodes which creates composite nodes.
@shiftyp shiftyp self-assigned this Jul 13, 2016
@shiftyp shiftyp closed this as completed Jul 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant