4 ms·
The examples for these kinds of frameworks always show you data binding for scalar values. That's easy. What's the story for more complex updates?
by nathansobo 13y ago
The examples for these kinds of frameworks always show you data binding for scalar values. That's easy. What's the story for more complex updates?
- rich_harris 13y agoRactive has a concept of 'expressions' - tutorial here: http://learn.ractivejs.org/#!/expressions/1 http://learn.ractivejs.org/#!/expressions/1 Hard to explain concisely but it allows fairly complex updates to be expressed very efficiently - see this animated chart for example. The path is created using an expression, which is reevaluated during animation and whenever the dimensions of the chart change: http://www.ractivejs.org/examples/animated-chart/ http://www.ractivejs.org/examples/animated-chart/
- seanmcdirmid 13y agoDeclarative data binding is intrinsically limited. If you want something that supports more complex updates, you need to start looking into things like incremental algorithms, self-adjusting computations, damage and repair, logged reversible effects, iterative processing methods, and so on. Say you want to write a compiler whose input is "bound" to a source file; when the input changes, you don't want to recompile the entire file all over again. Instead, you memoize at AST node boundaries, trace dependencies between AST nodes, and then "clean" nodes when they become dirty, detecting changes that affect other nodes to clean them also. To be honest, I find these data binding frameworks to be very boring, since we've been doing this forever (I did my dissertation on one myself). We really should be looking at the next level that supports incremental processing of more complicated updates.
- curveship 13y agoKnockout does incremental updates as well as memoization. It instruments the evaluation of computed observables to determine the dependency relationships. I haven't delved into Ractive.js closely, but it sounds like it does something similar. How is what they do different from what you're describing?
- seanmcdirmid 13y agoRe-evaluation is easy enough when your computation is pure. But once you throw in some imperative effects, like adding a name binding to a symbol table, all of the declarative data binding frameworks fall down very quickly. There is a lot of research in this area, concurrent revisions at MSR or self-adjusting computations at CMU to name a couple. Also, if you've seen Bret Victor's videos and wonder how any of those could be implemented for real, then this is where we need to go. It will be a fun trip though.
- curveship 13y agoYou're awesome. I've been playing around with a dependency network in JS recently, and I'd just been puzzling over exactly that question: how best to handle the case where a computation has side-effects. So I'm now busy googling concurrent revisions and self-adjusting computations. Got any further references to throw my way? Is there a standard literature on this stuff?
- seanmcdirmid 13y agoActually it's a problem I'm working on right now, but I have nothing to share yet. Some sort of restricted programming model is needed, in my current system effects must be reversible and commutative, the last one being a major restriction but workable for most programs (e.g. set add is typically commutative, list add is not but can be hacked, dictionary set to the same key is not but can restricted by set once semantics).