omniscientjs / immstruct

Immutable data structures with history for top-to-bottom properties in component based libraries like React. Based on Immutable.js
374 stars 21 forks source link

Computed values based on sets of cursors #19

Closed torgeir closed 9 years ago

torgeir commented 9 years ago

This is more an idea than a specific feature suggestion.

I often find myself wanting to update pieces of a structure based on when other specific pieces of a structure or other structures change; think knockout computed observables but with cursors.

How about

var m = immstruct({ m: 42 }).cursor('m');

var somewhere = immstruct({ somewhere: { else: { n : 42 } } });
var n = somewhere.cursor(['somewhere', 'else', 'n']);

var result = immstruct({ sum: undefined });
immstruct.listen([m, n], (m, n) => result.set('sum', m.deref() + n.deref());
dashed commented 9 years ago

Interesting. For this to happen, it would require something like this https://github.com/facebook/immutable-js/issues/242

Otherwise, we need a way to track keyPaths externally if we don't want to depend on immutable internals.

mikaelbr commented 9 years ago

You can kind of do the this using #60, no? So this can be closed?