bruth / synapse

Hooks to support data binding between virtually any object.
http://bruth.github.com/synapse/docs/
BSD 2-Clause "Simplified" License
150 stars 6 forks source link

Examples for syncWith #29

Closed virajsanghvi closed 12 years ago

virajsanghvi commented 12 years ago

I'm trying to use this library to sync between objects (not the dom), i.e. Backbone.Model -> Backbone.Model, or Backbone.Model -> Plain Object. In this case, I really just want one model to stay in sync with another.

Unfortunately, I seem to always get Interface not detected errors. It seems like detectInterface and others methods aren't defined on the backbone-model and object hooks.

I'm guessing this isn't the intended use of this library?

Some example code to better illustrate what I'm trying to do:

        var Test = Backbone.Model.extend();
        var a = new Test({});
        var b = new Test({test:5});
        var A = new Synapse(a);
        var B = new Synapse(b)
        console.log(a.toJSON(), b.toJSON());
        A.syncWith(B);
        b.set({hi:4});
        console.log(a.toJSON(), b.toJSON());

The main reason I'm trying to do this is so I can create a bridge from a Backbone.Model to an object that jsViews could use.

Thanks for your help!

bruth commented 12 years ago

It is behaving correctly to how it is implemented. Since the contents of a Backbone.Model instance is arbitrary, there is no default interface that can be inferred.

virajsanghvi commented 12 years ago

Closing this issue as my question was answered. Thanks!