Last active
January 2, 2016 17:09
-
-
Save nnance/8335349 to your computer and use it in GitHub Desktop.
Backbone session management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
'underscore', | |
'backbone', | |
'backbone.localstorage', | |
], function (_, Backbone, BBLocalStorage) { | |
'use strict'; | |
var SessionModel = Backbone.Model.extend({ | |
defaults: { | |
signedIn: false | |
}, | |
signin: function(userid, token) { | |
this.set({ | |
userid: userid, | |
token: token, | |
signedIn: true | |
}); | |
this.save(); | |
}, | |
signout: function() { | |
this.set('signedIn', false); | |
this.save(); | |
}, | |
}); | |
var SessionCollection = Backbone.Collection.extend({ | |
model: SessionModel, | |
localStorage: new Backbone.LocalStorage('eventshero') | |
}); | |
return { SessionCollection, SessionModel }; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment