rafa
Version:
Rafa.js is a Javascript framework for building concurrent applications.
29 lines (25 loc) • 958 B
Markdown
The Property object is a Stream that holds a value and can depend on other
properties forming a graph. The constructor accepts any type of value or
a function that is called each time the property is set. When constructed
with a function, that function is executed immediately to set an initial
value for the property. If the function references the value of other
properties then those properties are considered dependants and stores as
such in the properties attribute. Each time this property is set, all
dependants are also set.
<aside>
```js
var propertyA = Rafa.property(1);
var propertyB = Rafa.property(() => propertyA + 1);
var propertyC = Rafa.property(() => propertyB.get() + propertyA + 1);
// propertyA.get(): 1
// propertyB.get(): 2
// propertyC.get(): 4
var values = [];
propertyC.each(v => values.push(v)); // also a stream
propertyA.set(2);
// propertyA.get(): 1
// propertyB.get(): 2
// propertyC.get(): 4
// values[0]: 4
```
</aside>