Skip to content

Commit 6f17ea6

Browse files
authored
Merge pull request #3 from emileber/ie-compatibility
Refactored to ensure Internet Explorer compatibility
2 parents a674604 + 059a43d commit 6f17ea6

File tree

8 files changed

+66
-47
lines changed

8 files changed

+66
-47
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
6+
[*.{js,json,yaml,yml,jshintrc}]
7+
indent_size = 2
8+
indent_style = space

.jshintrc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
{
2+
"globals": {
3+
"localStorage": false,
4+
"define": false,
5+
"module": false,
6+
"require": false,
7+
"exports": false,
8+
"__dirname": false
9+
},
210
"bitwise": false,
311
"camelcase": false,
412
"curly": true,
513
"eqeqeq": true,
6-
"esnext": true,
714
"forin": true,
815
"immed": true,
916
"indent": 2,

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ session.fetch()
2727
.then(function () {
2828
console.log('Logged in as %s', session.get('name'));
2929
})
30-
.catch(function () {
30+
.fail(function () {
3131
console.log('Not yet logged in!');
3232
});
3333
```
@@ -60,7 +60,7 @@ Either a Function or a String that represents the key used to access `localStora
6060

6161
### signIn([options])
6262

63-
Returns: [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
63+
Returns: [jQuery Promise](https://api.jquery.com/promise/)
6464

6565
Example:
6666
```js
@@ -69,14 +69,14 @@ session.signIn({
6969
password: 'hunter2'
7070
}).then(function () {
7171
// Do stuff after logging in ...
72-
}).catch(function () {
72+
}).fail(function () {
7373
// Handle the failed log in attempt ...
7474
});
7575
```
7676

7777
### signOut([options])
7878

79-
Returns: [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
79+
Returns: [jQuery Promise](https://api.jquery.com/promise/)
8080

8181
Example:
8282
```js
@@ -87,15 +87,15 @@ session.signOut().then(function () {
8787

8888
### getAuthStatus([options])
8989

90-
Returns: [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
90+
Returns: [jQuery Promise](https://api.jquery.com/promise/)
9191

9292
Example:
9393
```js
9494
session.getAuthStatus()
9595
.then(function () {
9696
// The user is already logged in ...
9797
})
98-
.catch(function () {
98+
.fail(function () {
9999
// The user is not yet logged in ...
100100
});
101101
```

backbone-session.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,64 @@
1-
(function (root, factory) {
1+
(function(root, factory) {
22
if (typeof define === 'function' && define.amd) {
33
define(['underscore', 'backbone'], factory);
44
} else if (typeof exports === 'object') {
55
module.exports = factory(require('underscore'), require('backbone'));
66
} else {
77
root.BackboneSession = factory(root._, root.Backbone);
88
}
9-
}(this, function (_, Backbone) {
9+
}(this, function(_, Backbone) {
1010
return Backbone.Model.extend({
11-
url: function () {
11+
url: function() {
1212
return 'Backbone.Session';
1313
},
14-
initialize: function (properties, options) {
14+
initialize: function(properties, options) {
1515
this.options = options || {};
1616
},
17-
destroy: function (options) {
17+
destroy: function(options) {
1818
return this.sync('delete', this, options);
1919
},
20-
sync: function (method, model, options) {
20+
sync: function(method, model, options) {
2121
options = options || {};
2222
var url = model.options.url || model.url;
2323
var key = _.isFunction(url) ? url() : '' + url;
2424
var response;
2525
switch (method) {
26-
case 'create':
27-
case 'update':
28-
var data = model.toJSON();
29-
var text = JSON.stringify(data);
30-
response = localStorage.setItem(key, text);
31-
break;
32-
case 'delete':
33-
response = localStorage.removeItem(key);
34-
break;
35-
case 'read':
36-
response = JSON.parse(localStorage.getItem(key));
37-
break;
26+
case 'create':
27+
case 'update':
28+
var data = model.toJSON();
29+
var text = JSON.stringify(data);
30+
response = localStorage.setItem(key, text);
31+
break;
32+
case 'delete':
33+
response = localStorage.removeItem(key);
34+
break;
35+
case 'read':
36+
response = JSON.parse(localStorage.getItem(key));
37+
break;
3838
}
3939
if (_.isFunction(options.success)) {
4040
options.success(response);
4141
}
42-
return Promise.resolve(response);
42+
return Backbone.$.Deferred()
43+
.resolve(response)
44+
.promise();
4345
},
44-
signIn: function (options) {
45-
return Promise.reject(Error(
46-
'Override the signIn method'
47-
));
46+
signIn: function(options) {
47+
return Backbone.$.Deferred()
48+
.reject(Error('Override the signIn method'))
49+
.promise();
4850
},
49-
signOut: function (options) {
51+
signOut: function(options) {
5052
options = options || {};
5153
this.destroy();
5254
this.clear();
5355
this.trigger('signOut');
54-
return Promise.resolve();
56+
return Backbone.$.Deferred().resolve().promise();
5557
},
56-
getAuthStatus: function (options) {
57-
return Promise.reject(Error(
58-
'Override the getAuthStatus method'
59-
));
58+
getAuthStatus: function(options) {
59+
return Backbone.$.Deferred()
60+
.reject(Error('Override the getAuthStatus method'))
61+
.promise();
6062
},
6163
Model: Backbone.Model,
6264
Collection: Backbone.Collection

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "backbone-session",
33
"main": "backbone-session.js",
4-
"version": "0.0.1",
4+
"version": "1.0.0",
55
"homepage": "https://github.com/cofounders/backbone-session",
66
"authors": [
77
"Sebastiaan Deckers <[email protected]>"
8+
"Émile Bergeron <[email protected]>"
89
],
910
"description": "Flexible and simple session management for Backbone apps",
1011
"keywords": [

package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
{
22
"name": "backbone-session",
33
"description": "Flexible and simple session management for Backbone apps",
4-
"version": "0.1.0",
4+
"version": "1.0.0",
55
"author": {
66
"name": "Sebastiaan Deckers",
77
"email": "[email protected]"
88
},
9+
"contributors": [
10+
{
11+
"name": "Émile Bergeron",
12+
"email": "[email protected]",
13+
"url": "http://www.prismalstudio.com"
14+
}
15+
],
916
"repository": {
1017
"type": "git",
1118
"url": "[email protected]:cofounders/backbone-session.git"
1219
},
13-
"licenses": [{
14-
"type": "MIT"
15-
}],
20+
"licenses": "MIT",
1621
"scripts": {
1722
"test": "grunt test"
1823
},
1924
"dependencies": {
25+
"backbone": "^1.3.3",
2026
"grunt": "0.4.1",
2127
"grunt-cli": "~0.1",
2228
"grunt-contrib-jshint": "0.10.0",
@@ -25,8 +31,7 @@
2531
"requirejs": "*",
2632
"underscore": "*"
2733
},
28-
"devDependencies": {
29-
},
34+
"devDependencies": {},
3035
"keywords": [
3136
"backbone",
3237
"session",

tests/amd_test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
var requirejs = require('requirejs');
42

53
requirejs.config({

tests/commonjs_test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
exports['CommonJS compatibility'] = {
42

53
default: function (test) {

0 commit comments

Comments
 (0)