backbone-view-switcher

0.0.6 • Public • Published

backbone-view-switcher

WORK IN PROGRESS

Build Status

Sauce Test Status

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);

Package Sidebar

Install

npm i backbone-view-switcher

Weekly Downloads

2

Version

0.0.6

License

MIT

Last publish

Collaborators

  • benjaminverble