cassowary.js
cassowary.js copied to clipboard
Variable change notification support
The common use-case for Cassowary-based systems is for the solver to run in an incremental mode, moving to a new solution from an existing good solution. In interactive apps, the initial new values may be provided, but it's up to the solver to efficiently find new values for other affected variables. The updated values often need to be fed back into a UI framework to perform on-screen updates.
Cassowary should provide an (optional) facility for notifying observers of variables who values have changed, perhaps as a Map()/HashMap().
Note that the API and notification format should be broadly compatible with the Object.observe() straw-man:
http://wiki.ecmascript.org/doku.php?id=strawman:observe
I've been using Ember's Object Model & Observers, it's not compliant with the Object.observe() straw-man, but good-enough for my needs. Basically I just wrapped constraintVariable.change_value and constraintVariable.set_value
... I'm addicted to Ember's computed properties.
What is the intersection between this and the new API? Is it still worth making the internal Variable objects observable?
I think that a parser-based API would benefit from this by allowing you to register some sort of event handler to know that values of interest were modified.