smallseo.info

backbone

Give your JS App some Backbone with Models, Views, Collections, and Events Backbone.js

What are the key differences between Meteor, Ember.js and Backbone.js? [closed]

Learning Ember.js / Backbone.js has been on my to-do list for a while. Now that Meteor is out, I am just wondering if anyone with experience of Meteor, Ember.js and Backbone.js can summarize the key differences and pros and cons of these three JavaScript frameworks for a person without any experience for any of them.

Specifically, I would like to know which tasks each framework is more suitable for, and why the others aren't.

Edit: now that I read a little bit more on Meteor, it seems to be more similar to Knockout.js rather than Backbone.js. So any comparison with Knockout.js is welcome too.


Source: (StackOverflow)

What is the purpose of backbone.js?

I tried to understand the utility of backbone.js from its site http://documentcloud.github.com/backbone, but I still couldn't figure out much.

Can anybody help me by explaining how it works and how could it be helpful in writing better JavaScript?


Source: (StackOverflow)

Angular.js Backbone.js or which has better performance

I am a web developer and I'm starting to develop a web application on a large scale, but I'm not sure what framework to use. I was thinking of Angular.js, but I also considered Backbone.js. For you, what would be the best framework? or at least have a comparison between the two to see the performance.


Source: (StackOverflow)

Backbone.js: get current route

Using Backbone, is it possible for me to get the name of the current route? I know how to bind to route change events, but I'd like to be able to determine the current route at other times, in between changes.


Source: (StackOverflow)

Backbone.js fetch with parameters

Following the documentation, I did:

var collection = new Backbone.Collection.extend({
        model: ItemModel,
        url: '/Items'
})

collection.fetch({ data: { page: 1} });

the url turned out to be: http://localhost:1273/Items?[object%20Object]

I was expecting something like http://localhost:1273/Items?page=1

So how do I pass params in the fetch method?


Source: (StackOverflow)

Angular.js vs Knockout.js vs Backbone.js [closed]

I am considering to use either Knockout or Angular or Backbone for my personal project. I need to build some bigger, longer-running client-side interactions to go with my server-side stuff.

I want a simple and effective way to manage data-driven user interfaces.

Which framework would you choose to solve my problem described above based on the feasibility as well as the performance aspect?


Source: (StackOverflow)

How to override Backbone.sync?

I'm trying out Backbone.js, and one of the things I'm trying is to make a call to a remote API, so I need to be able to override Backbone.sync, as I understand the documentation.

There isn't an example of how to do that in the documentation itself, and there doesn't appear to be a google group for Backbone... can someone point out an example for doing this?


Source: (StackOverflow)

How to use if statements in underscore.js templates?

I'm using the underscore.js templating function and have done a template like this:

<script type="text/template" id="gridItem">
    <div class="griditem <%= gridType %> <%= gridSize %>">
        <img src="<%= image %>" />
        <div class="content">
            <span class="subheading"><%= categoryName %></span>
            <% if (date) { %><span class="date"><%= date %></span><% }  %>
            <h2><%= title %></h2>
        </div>
    </div>
</script>

As you can see I have an if statement in there because all of my models won't have the date parameter. However this way of doing it gives me an error date is not defined. So, how can I do if statements within a template?


Source: (StackOverflow)

backbone.js & underscore.js CDN recommendation?

Is there any CDN sources for backbone.js and also underscore.js to use in our projects?


Source: (StackOverflow)

How to handle initializing and rendering subviews in Backbone.js?

I have three different ways to initialize and render a view and its subviews, and each one of them has different problems. I'm curious to know if there is a better way that solves all of the problems:


Scenario One:

Initialize the children in the parent's initialize function. This way, not everything gets stuck in render so that there is less blocking on rendering.

initialize : function () {

    //parent init stuff

    this.child = new Child();
},

render : function () {

    this.$el.html(this.template());

    this.child.render().appendTo(this.$('.container-placeholder');
}

The problems:

  • The biggest problem is that calling render on the parent for a second time will remove all of the childs event bindings. (This is because of how jQuery's $.html() works.) This could be mitigated by calling this.child.delegateEvents().render().appendTo(this.$el); instead, but then the first, and the most often case, you're doing more work unnecessarily.

  • By appending the children, you force the render function to have knowledge of the parents DOM structure so that you get the ordering you want. Which means changing a template might require updating a view's render function.


Scenario Two:

Initialize the children in the parent's initialize() still, but instead of appending, use setElement().delegateEvents() to set the child to an element in the parents template.

initialize : function () {

    //parent init stuff

    this.child = new Child();
},

render : function () {

    this.$el.html(this.template());

    this.child.setElement(this.$('.placeholder-element')).delegateEvents().render();
}

Problems:

  • This makes the delegateEvents() necessary now, which is a slight negative over it only being necessary on subsequent calls in the first scenario.

Scenario Three:

Initialize the children in the parent's render() method instead.

initialize : function () {

    //parent init stuff
},

render : function () {

    this.$el.html(this.template());

    this.child = new Child();

    this.child.appendTo($.('.container-placeholder').render();
}

Problems:

  • This means that the render function now has to be tied down with all of the initialization logic as well.

  • If I edit the state of one of the child views, and then call render on the parent, a completely new child will be made and all of its current state will be lost. Which also seems like it could get dicey for memory leaks.


Really curious to get your guys' take on this. Which scenario would you use? or is there a fourth magical one that solves all of these problems?

Have you ever kept track of a rendered state for a View? Say a renderedBefore flag? Seems really janky.


Source: (StackOverflow)

What are the real-world strengths and weaknesses of the many frameworks based on backbone.js?

Hope that someone can share their experience with some of the latest emerging backbone.js variants out there. I have some good experience with backbone/underscore/require in several projects and I will like to take the next step towards more advanced solutions for complex application structure.

I know the following frameworks are available:

And probably I missed a few.

There is a short introduction about the differences here:

but it's very general. I was wondering if someone can share their experience with real life applications using these frameworks.

What is the benefit of choosing one over the other? When will marionette be a better solution over chaplin, or why is vetebrae better for certain applications, for example.

Sure, the obvious answer will be "use whats best for your needs", but I lack of the experience with these frameworks to know their strength/purpose/advantages or preferred scenarios.

Thanks!

Edit 1: found this post: Backbone.Marionette vs Backbone-Boilerplate

Edit 2: *Answer by Mathias schafer (Chaplin) by mail:*

In short, the current structure is close to version 1.0 since it’s already used in production. We’re not planning to add big new feature or breaking API changes until 1.0.

Marionette is for sure the most comprehensive and stable library out there. It addresses several aspects of JS app development with Backbone. For example, it has a strong view layer which Backbone itself leaves completely void. Of course, you will find that some of the aspects won’t meet your demands and you might feel the need to set up a structure around Marionette.

In contrast, Chaplin focusses on a rather small, but very important aspect of Backbone apps, namely the overall app structure and module lifecycle. In this regard Chaplin is very opionated and is more like a framework than a library (like in “your code calls a library, a framework calls your code”). Chaplin provides some central classes which sit above individual application modules and control the overall app state. This gives your app a conventional structure like Ruby on Rails does it for example.

In Chaplin, you declare some routes which map to controllers, and Chaplin starts the controller once the route match. It also takes care of the disposal of old controllers, and the showing and hiding of main views, which a controller is supposed to create. This is the basic idea, but Chaplin takes care of the ugly details to make this run smoothly.

There are two principals which come along with this structure: - Modularization, decoupling and sandboxing - Cross-module communication using Publish/Subscribe and Mediator(s)

Of course these patterns are not new in the software development world, and Chaplin is not the only library which applies them to Backbone.js apps.

Chaplin also provides enhancements for the View layer, for example a highly sophisticated CollectionView, but in total not as much as Marionette with its Regions and Layouts. But it’s relatively easy to write such meta classes using the means Chaplin Views provide.


Source: (StackOverflow)

What does `void 0` mean? [duplicate]

Possible Duplicate:
What does “javascript:void(0)” mean?

Reading through the Backbone.js source code:

validObj[attr] = void 0;

What is void 0? What is the purpose of using it here?


Source: (StackOverflow)

Explanation of

I just stumbled upon something I've never seen before. In the source of Backbone.js's example TODO application (Backbone TODO Example) they had their templates inside a <script type = "text/template"></script>, which contained code that looks like something out of PHP but with JavaScript tags.

Can someone explain this to me? Is this legit?


Source: (StackOverflow)

Separate REST JSON API server and client?

I'm about to create a bunch of web apps from scratch. (See http://50pop.com/code for overview.) I'd like for them to be able to be accessed from many different clients: front-end websites, smartphone apps, backend webservices, etc. So I really want a JSON REST API for each one.

Also, I prefer working on the back-end, so I daydream of me keeping my focus purely on the API, and hiring someone else to make the front-end UI, whether a website, iPhone, Android, or other app.

Please help me decide which approach I should take:

TOGETHER IN RAILS

Make a very standard Rails web-app. In the controller, do the respond_with switch, to serve either JSON or HTML. The JSON response is then my API.

Pro: Lots of precedent. Great standards & many examples of doing things this way.

Con: Don't necessarily want API to be same as web app. Don't like if/then respond_with switch approach. Mixing two very different things (UI + API).

REST SERVER + JAVASCRIPT-HEAVY CLIENT

Make a JSON-only REST API server. Use Backbone or Ember.js for client-side JavaScript to access API directly, displaying templates in browser.

Pro: I love the separation of API & client. Smart people say this is the way to go. Great in theory. Seems cutting-edge and exciting.

Con: Not much precedent. Not many examples of this done well. Public examples (twitter.com) feel sluggish & are even switching away from this approach.

REST SERVER + SERVER-SIDE HTML CLIENT

Make a JSON-only REST API server. Make a basic HTML website client, that accesses the REST API only. Less client-side JavaScript.

Pro: I love the separation of API & client. But serving plain HTML5 is quite foolproof & not client-intensive.

Con: Not much precedent. Not many examples of this done well. Frameworks don't support this as well. Not sure how to approach it.

Especially looking for advice from experience, not just in-theory.


Source: (StackOverflow)

Backbone.View "el" confusion

How should a view's el be handled? It has to be set, otherwise events don't fire (see here).

But should it be an element that is already on the page? In my app, I render a (jQuery Templates) template into a Fancybox. What should the el be in that case?


Source: (StackOverflow)