datavis-tech / reactive-model

A library for reactive dataflow programming.
MIT License
61 stars 6 forks source link

Implement link function #5

Closed curran closed 8 years ago

curran commented 8 years ago

Based on this https://github.com/datavis-tech/reactive-function/blob/master/test.js#L379

Should support unidirectional as well as bidirectional

curran commented 8 years ago

Part of reactive-model 1.0 https://github.com/datavis-tech/reactive-model/issues/31

curran commented 8 years ago

Should not be named bind as there is already Function.prototype.bind()

Maybe it could look like this:

# ReactiveModel.link(model1, propertyName1, model2, propertyName2[, twoWay])

var link1 = ReactiveModel.link(modelA, "foo", modelB, "bar");
link1.destroy();
var link2 = ReactiveModel.link(modelA, "a", modelB, "b", true);
link2.destroy();
curran commented 8 years ago

Better yet, no need to reference the models actually:

# ReactiveModel.link(propertyA, propertyB[, twoWay])

var link1 = ReactiveModel.link(modelA.foo, modelB.bar);
link1.destroy();
var link2 = ReactiveModel.link(modelA.a, modelB.b, true);
link2.destroy();

Perhaps this could be pushed down to reactive-function and simply exposed in reactive-model.

curran commented 8 years ago
curran commented 8 years ago

Maybe it would actually be a cleaner API if there were two functions:

# ReactiveModel.link(propertyA, propertyB)

# ReactiveModel.linkTwoWay(propertyA, propertyB)

curran commented 8 years ago

It turns out that bidirectional data binding was never working correctly. The test was bad. It also seems tricky to implement.

Leaving out two-way binding for now.