remy / bind.js

bind.js - simple two way data binding to HTML and callbacks
694 stars 62 forks source link

API to dynamically add and remove bindings #37

Open wkeese opened 7 years ago

wkeese commented 7 years ago

The Bind() function creates an "observable Object" (the return value from the function) and sets up bindings to other Objects (often DOM nodes). But AFAICT there's no way to dynamically add or remove bindings to an existing "observable Object". Something like:

var user = Bind({ first: "Bob", last: "Jones"});
user.bind("first", "#first");
user.bind("last", "#last");

The reason that would be nice is for code decoupling, i.e. so various pieces of code that don't know about each other can attach to user.

remy commented 7 years ago

I'd be up for a PR to add that functionality, but perhaps it should be inside of the Bind method instead of on the object, i.e.

var user = Bind({ first: "Bob", last: "Jones"});
Bind.update(user, { age: 30, location: 'foo' }, { age: '#age', location: { ... });