synapse icon indicating copy to clipboard operation
synapse copied to clipboard

Allow syncWith() to specify interfaces

Open dbushong opened this issue 13 years ago • 1 comments
trafficstars

Currently syncWith() takes no options, AFAICT. (Contradicting the docs, BTW)

It would be nice to be able to bidirectionally link two objects that don't share the same interface. Unfortunately, the obvious method for doing this, passing an object with observerInterface and subjectInterface wouldn't help because they switch roles. However, it's entirely possible (likely?) that the interface for each specific object would stay the same for both directions, we just need a way of specifying them, but I'm not sure the best way to do that.. leftInterface and rightInterface ? Blech.

Example:

var a = Synapse($('#foo')), b = Synapse(new Backbone.Model());

// tedious
a.observe(b, 'some_prop_on_b', 'attr.some_attr_on_a')
  .notify(b, 'attr.some_attr_on_a', 'some_prop_on_b');

// better?
a.syncWith(b, { leftInterface: 'attr.some_attr_on_a', rightInterface: 'some_prop_on_b' });

// a.k.a.
a.syncWith(b, 'attr.some_attr_on_a', 'some_prop_on_b');

Probably also helpful to have a way to specify triggerOnBind with a direction in the options (i.e. which object is the source of authority for the initial one-way sync)

dbushong avatar Jan 21 '12 20:01 dbushong

I too have not come to a clear/clean solution for this. It most likely will need to be denoted by left and right. When interfaces and/or events are not detected, the verbosity of defining a binding is miserable. An alternate approach for configuring the DOM-based hooks (jQuery, Zepto, and Backbone View) is to extend these: https://github.com/bruth/synapse/blob/master/src/synapse/hooks/jquery.coffee#L206-231 which are exposed, but not documented.

bruth avatar Jan 21 '12 23:01 bruth