Code Monkey home page Code Monkey logo

backbone-session's Introduction

##Backbone Session

A uniform approach to session control for backbone.js apps.

Install

Using Bower:

bower install backbone.session

Usage

To load a new session, simply instantiate APP.Session :

app.session = new APP.Session();

If a remote is defined it will immediately be requested with a fetch(). Results will be saved locally and used for subsequent requests to the server.

Get info from the session like in any other Backbone Model:

app.session.get("user");
...

Options

  • local: Boolean, defining if the session will be saved locally
  • remote: Boolean, defining if a remote service will be called
  • persist: Boolean, using localStorage instead of sessionStorage (where available)

Conventions

There are a few things the plugin takes for granted and is good to note:

  • In the examples we're assuming there is an app in the global namespace.
  • Prefered api URL is "/session" (on the same domain)
  • The session is stored preferably in sessionStorage unless the persist : true in which case localStorage is used.
  • If the remote has no session an attempt will be made for the local info to be passed to the remote service.

Credits

Created by Makis Tracend ( @tracend )

Originally released as gist:1824154 (still maintained to sustain bower support...)

Distributed through Makesites.org

Released under the MIT license

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.