Skip to content

Instantly share code, notes, and snippets.

@gr0uch
Last active October 19, 2016 14:50
Show Gist options
  • Save gr0uch/ba34ccd49f03b30033238ca5399831a1 to your computer and use it in GitHub Desktop.
Save gr0uch/ba34ccd49f03b30033238ca5399831a1 to your computer and use it in GitHub Desktop.

Reactive programming utility function that defines a property on a target object to depend on the values of other properties. Uses object getters & setters.

Strawman:

// Returns result of first run.
dependentKeys(
  [ target, 'targetKey' ],
  [ object1, 'key1' ],
  [ object2, 'key2' ],
  (key1, key2) => key1 + key2)

The first pair is the target, and the function receives arguments from the other properties. This assigns target.targetKey whenever key1 or key2 gets assigned to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment