Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backbone + Vue #316

Closed
franciscolourenco opened this issue Jun 16, 2014 · 10 comments
Closed

Backbone + Vue #316

franciscolourenco opened this issue Jun 16, 2014 · 10 comments

Comments

@franciscolourenco
Copy link
Contributor

Is it possible to use Backbone models with Vue?

@yyx990803
Copy link
Member

Vue uses plain objects as models, in general it's not compatible with Backbone's Model. Also it's not necessary to use Backbone models with Vue because with plain objects it's fairly simple to implement your own validation/ajax functionalities with other libraries.

@franciscolourenco
Copy link
Contributor Author

Which other libraries are you thinking of for example?

@franciscolourenco
Copy link
Contributor Author

Thank you!
Closing for now..

@baer
Copy link

baer commented Oct 21, 2014

What about using adapters à la Rivets? I'm integrating Vue into an application written in Backbone and since my models have the parse and save logic already built and tested I either have to serialize back and forth by hand or buy in all the way and run multiple code paths.

Most APIs I've worked with (that are not big web startups) are kinda crappy and require some parsing before being passed into the web-app so I don't think that this use case would be so uncommon. This would be an especially rad feature with something like &model and other front end data modeling tools.

var customers = new Customers();
customers.fetch()

if (urlFragment === "customers") {
  // Written in Backbone
  var customersView = new CustomersView({ model: customers })
  customersView.render()
} else if (urlFragment === "customer/*") {
  // Written in Vue
  var customer = findCustomer(customers, urlFragment);
  customerVue(customer);
}

@franciscolourenco
Copy link
Contributor Author

When I started this issue I was coming precisely from Rivets adapters

@baer
Copy link

baer commented Oct 22, 2014

There is a need in js land for good stand data modeling and it's absence is being made conspicuously obvious by the new wave of view layer frameworks like Vue, React, Ractive etc. Full featured libraries saw the need but haven't opened up to the wider community yet. Ember has ember-data, Angular has $resource Backbone has Backbone.Model.

The best tool I've seen so far is ampersand-model and since it allows access to data with the . accessor it may even be observable in a way that Vue can deal with. I haven't looked deep enough into Vue source to know.

@yyx990803 I'm sure sure super busy getting 0.11 out the door but do you have any thoughts on how vue-resource would work or if adapters are possible?

@yyx990803
Copy link
Member

There's an example I once wrote using Vue with a Backbone Model: http://jsfiddle.net/x1jeawzv/2/
In it's essence, since vm.$data can be manipulated independently, anything that wraps and operates on a POJO can be used as the persistence layer.

@boussou
Copy link

boussou commented Jan 3, 2015

@yyx990803 This is awesome.
I'll try to make it work with collections too just for fun.
This is a relevant for people who has existing backbone apps & want to get rid of the BB view part.

@boussou
Copy link

boussou commented Jan 5, 2015

I made a test, it works partially : http://jsfiddle.net/x1jeawzv/4/

then if you do this it works partially

list.add(new Backbone.Model({
        name: 'hello'
    }))

incomplete, as I see a lot to do before it is complete: too much work (sync the other way, update newly added models because the stuff created() must be performed on them, ..)

it ends up in maintainning two arrays of objects syncrhonized, unless you choose to refresh the full array at each array change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants