Giter VIP home page Giter VIP logo

wishcard's People

Contributors

fzaninotto avatar manuquentin avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

60thsec

wishcard's Issues

Consistency between callbacks and promises

In https://github.com/marmelab/wishcard/blob/master/js/views/ShapesView.js#L50 you use the promise returned by fetch to attach a "success" callback with the done method. But in https://github.com/marmelab/wishcard/blob/master/js/views/ShapesView.js#L201 you pass a callback to the Shapes#addRaphaelElement method. And this callback use the "node-ism" callback(err, result), rarely seen in the front-end world (apart with async.js).

You'd better return the promise of the save call from https://github.com/marmelab/wishcard/blob/master/js/collections/Shapes.js#L36, but replace this call by :

return this.save(data);

This way you would use the promise way in https://github.com/marmelab/wishcard/blob/master/js/views/ShapesView.js#L201 the same way you did at L50, with the done and fail promise callbacks.

The router is useless

In Backbone, routers are useful to listen to change in urls. Their instanciation is almost always followed by Backbone.history.start() to start the listening process.

Here, there's no use of the urls, and the Router is used only as an application initializer to create the view. So no need to use a Backbone construct for an initializer, a plain old javascript object will do.

Further reading from the creator of Marionnette, a Backbone based application framework : http://lostechies.com/derickbailey/2012/02/06/3-stages-of-a-backbone-applications-startup/

Why _.bindAll(this) in collections/shapes ?

In https://github.com/marmelab/wishcard/blob/master/js/collections/Shapes.js#L11 you use _.bindAll(this);. It's pretty dangerous to use this, unless the collection's methods are going to be used as response callbacks to events triggered somewhere else, where the meaning of this is lost. Try to test without the call to see if it works (I think it should), then remove it. It can cause very malicious bug very hard to track (I know, it happened to me yesterday, really).

Restful urls for Models

No need to set a custom url property for Shape models in https://github.com/marmelab/wishcard/blob/master/js/models/Shape.js#L15, as long as you fetch a model from shapes/[id]. A model uses its collection's url property and append its id to it automatically for you. Furthermore, it's more restful to use shapes/[id] than shape/[id] if the collection's url is shapes. See http://documentcloud.github.io/backbone/#Model-url.

If you really want to stick to a custom Model's url, you can just redefine the url property as function instead of using the initialize function, like :

var Shape =  Backbone.Model.extend({
  defaults: {} // your defaults here,

  url: function() {
    return 'shape/' + this.get('id'); 
    // Better to use the getter than directly tap into the model's properties.
    // Getters/setters trigger events that maybe be listened somewhere else in your app.
  }
});

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.