Giter VIP home page Giter VIP logo

Comments (8)

paulmillr avatar paulmillr commented on September 6, 2024

class App.collections.people extends backbone.collections.

Colelections != Collection. Seems like a simple typo to me.

from backbone-relational.

codyhatch avatar codyhatch commented on September 6, 2024

Grr, sorry. Unfortunately, that's not the problem - the typo was introduced when I typed up the issue; my actual CoffeeScript file had it correct. To clarify code that (for me) fails is:

class App.Collections.People extends Backbone.Collection
  model: App.Models.Person
  url: '/api/people'

class App.Collections.Companies extends Backbone.Collection
  model: App.Models.Company
  url: '/api/companies'

#`App.Collections.People = Backbone.Collection.extend({
#  model: App.Models.Person,
#  url: '/api/people/'
#});
#
#App.Collections.Companies = Backbone.Collection.extend({
#  model: App.Models.Company,
#  url: '/api/companies/'
#});`

But this works (using backticks to pass raw JS through the CS compiler):

#class App.Collections.People extends Backbone.Collection
#  model: App.Models.Person
#  url: '/api/people'
#
#class App.Collections.Companies extends Backbone.Collection
#  model: App.Models.Company
#  url: '/api/companies'

`App.Collections.People = Backbone.Collection.extend({
  model: App.Models.Person,
  url: '/api/people/'
});

App.Collections.Companies = Backbone.Collection.extend({
  model: App.Models.Company,
  url: '/api/companies/'
});`

And I've triple checked that that is the precise code I actually used to create the error, this time. :) Thoughts?

from backbone-relational.

PaulUithol avatar PaulUithol commented on September 6, 2024

Hmm, this type of crazy stuff is why I tend to stay away from intermediate languages being compiled into another language, that gets compiled into.. etc ;).

How does collection.create behave? Do that actually make proper new persons/companies, instead of plain Backbone.Model instances (which is the default)?

from backbone-relational.

paulmillr avatar paulmillr commented on September 6, 2024

Does the problem exists in coffeescript 1.1.2? I've written some production code in the past and coffeescript class extension worked flawlessly.

If not, then it's a backbone-relational bug that was introduced in master, because I've used 0.4.0.

from backbone-relational.

codyhatch avatar codyhatch commented on September 6, 2024

Paul Uithol: Yeah, I decided to try Backbone.js for the first time, and in an excess of enthusiasm, node.js and CoffeeScript, all on the same project. Maybe I should have tried a more incremental approach. sigh

Regardly, while creating a simple test case, I figured out the problem: As I believed was best practice, I was splitting up my Backbone project into different files for models, collections, and views, and then running coffee -j on the source tree to generate a single app.js file. This worked great, right up until it didn't. It turns out the CoffeeScript compiler was sticking my collections above my models in the compiled JS file. (Of course, every time I wrote some test code, I put it all in the same file - so my simple test cases always worked, but my "real" code never did. This also explains why my "hack" to define collections in pure JS worked - I was putting it in a different file, which was getting compiled into the "right" place. FML.)

Anyhow, if I put collections and models in the SAME CS file like this:

class App.Models.Person extends Backbone.RelationalModel
  urlRoot: '/api/people'

class App.Collections.People extends Backbone.Collection
  model: App.Models.Person
  url: '/api/people'

then I can do:

>people = new App.Collections.People()
People
>people.model
function Person() {
      Person.__super__.constructor.apply(this, arguments);
    }
>people.create({name: 'me'})
Person

Presto, everything works. But if I do this:

class App.Collections.People extends Backbone.Collection
  model: App.Models.Person
  url: '/api/people'

class App.Models.Person extends Backbone.RelationalModel
  urlRoot: '/api/people'

Then I get:

> people = new App.Collections.People()
People
> people.model
undefined
> people.create({name: 'me'})
TypeError: undefined is not a function

sigh Damn but that wasted about uh...three days of my time. I love the CoffeeScript syntax, but I guess I'm seeing your point about intermediate languages.

Thanks a ton for your help; that question about collection.create was the clue I needed. >< I'm marking this as closed since it doesn't seem to be a bug at all, much less a bug with your excellent code.

from backbone-relational.

paulmillr avatar paulmillr commented on September 6, 2024

@codyhatch have you tried @brunch? It was designed to support backbone & coffeescript out-of-box, with a nice modularity (require.js support etc). I've used backbone-relational with it, every model / collection had a separate file for it.

from backbone-relational.

codyhatch avatar codyhatch commented on September 6, 2024

@paulmillr Thanks for the pointer. Looks interesting, although the documentation is a little contradictory re: what node version it supports, etc. Also, does it currently support any templates other than Eco?

from backbone-relational.

paulmillr avatar paulmillr commented on September 6, 2024

yup, the docs need some updates.

brunch 0.8 supports node 0.4 & eco, brunch 0.9-beta (I'll release in a couple days) supports jade, eco, mustache & node 0.4/0.6. 0.9 also has nice api for custom languages e.g. haml etc.

from backbone-relational.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.