“dgraph is a dependency graph library for Clojure.
“This code is inspired by Kenny Tilton’s Cells project (http://common-lisp.net/project/cells/).
“dgraph aims to offer a (mostly) pure functional data structure whose nodes behave like cells in a spreadsheet, i.e., they form a dependency graph. This data structure has two kinds of nodes: stored and computed. Stored nodes contain constant values, whereas computed nodes behave more like functions. In typical use, computed nodes calculate and cache their values lazily, when needed. Changing the value of a stored node does not destructively modify the graph; instead, it returns a new graph with the node’s value changed and the node’s dependent (child) computed values invalidated.
“This data structure has many uses. In particular, it helps eliminate repeated clutter in UI code where the state of a display element may depend on the state of several other elements. Consider, for example, an action button which needs to be activated if and only if several other input elements are filled in and validate correctly. Normally, each of these elements’ callbacks would have to enable the action button separately, while also checking the state of the other fields. Although this mess may be abstracted out into a function, each callback would still have to be sure to call that function. On the other hand, if the state of each input element and the action button become nodes on a dependency graph, then the button can just activate itself when the other nodes all achieve valid state.”