-
Notifications
You must be signed in to change notification settings - Fork 330
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
How do I get Backbone-relational working with ES6? #576
Comments
Hi @gegenschall, we are working on migrating all of our existing code into an es6 and umd friendly package (as seen on the /next branch). Until then I would suggest creating the following shim: // relational-shim.js
import Backbone from 'backbone';
import 'backbone-relational';
export default {
Model: Backbone.RelationalModel,
Collection: Backbone.Collection,
HasMany: Backbone.HasMany,
HasOne: Backbone.HasOne,
store: Backbone.Relational.store,
View: Backbone.View
}; Then use it like the following: import { Model, Collection } from 'relational-shim';
let myModel = Model.extend(...);
let myCollection = Collection.extend({ model: myModel, ... }); |
Also, Backbone does not use es6's |
Ok, thanks for your response. Will use the shims until the next branch is stable. But still, I was under the impression that I could use the class concept of ES6 (works just fine with vanilla Backbone) and just call the setup() method of my relational models somewhere else? |
@gegenschall I don't think you can use es6 classes with backbone just yet. Here is the discussion over at Backbone jashkenas/backbone#3560 about using es6 classes. |
Nah, it works just fine if you find a way to navigate around the problem of setting properties like edit: That is, if you're using babel and the correct transform, which is probably no what you guys are aiming for. Anyway, thanks for answering. I'll fix this temporarily by using the |
btw: class MyModel extends Backbone.Model.extend({
idAttribute: 'id'
}) {
// ...
}; |
I'm trying to get Backbone-relational working with ES6 (I'm using System.js and Babel to transpile). I basically define a Model like so:
I'm using the model like so:
Now the
.get(...)
method always returnsundefined
for any relations that are defined on the model and should've been "initialized"(?). This means that the subsequent.add
call isn't working either.Calling
SomethingModel.setup()
does not change that, usingSomethingModel.build()
instead ofnew
-instantiation also does not work.Is there a way to use Backbone-relational with ES6?
The text was updated successfully, but these errors were encountered: