BenjaminVerble / backbone-view-switcher

places Backbone.js views into a container with an #id. can also attach a collection to an instantiated Backbone View

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

backbone-view-switcher

!! NO MAINTENANCE INTENDED !!

Backbone View Switcher places Backbone.js views into a container that has an #id. It can also attach a collection to a view when the view is instantiated by Backbone View Switcher. This module currently requires Browserify.

Installation

  • npm install backbone-view-switcher --save
  • for tests:
    • cd to package root
    • npm install
    • npm test
  • for examples: gulp (will browserify every app.js in each example)
    • cd to each example and open in a browser or serve. (harpjs is pretty nice for this. it will always serve an index.html file in a directory)
    • to remove bundle files created by browserify: gulp clean

Usage

In general, the primary intention of this module is to help with code-repetition / boilerplate code in a Backbone.js router or parent view.

Always start with this:

var putInto = require('backbone-view-switcher'); // call it what you want :-)

two-step process with collection (suggested use)

key benefit is reuse of putIntoMain in a Backbone Router or elsewhere

// require some depencencies
var putIntoMain = putInto('#main');

var router = Backbone.Router.extend({

  routes: {
    "contact": "contact",
    "help": "help",
    "about": "about"
  },

  contact: function () {
    putIntoMain(ContactView, Collection);
  },

  about: function () {
    putIntoMain(AboutView, AnotherCollection);
  },

  help: function () {
    putIntoMain(HelpView, YetAnotherCollection)
  }

});

one-step process with collection

putInto('#main', PieView, Collection);

two-step process without collection

var putIntoMain = putInto('#main');
putIntoMain(SimpleView);

one-step process without collection

putInto('#main', SimpleView);

two step process with null passed as collection

var putIntoMain = putInto('#main');
putIntoMain(SimpleView, null);

one-step process with null passed as a collection

putInto('#main', SimpleView, null);

About

places Backbone.js views into a container with an #id. can also attach a collection to an instantiated Backbone View

License:MIT License


Languages

Language:JavaScript 100.0%