backbone.localstorage
Advanced tools
Comparing version 1.1.14 to 1.1.15
/** | ||
* Backbone localStorage Adapter | ||
* Version 1.1.14 | ||
* Version 1.1.15 | ||
* | ||
* https://github.com/jeromegn/Backbone.localStorage | ||
*/(function(a,b){typeof exports=="object"&&typeof require=="function"?module.exports=b(require("backbone")):typeof define=="function"&&define.amd?define(["backbone"],function(c){return b(c||a.Backbone)}):b(Backbone)})(this,function(a){function b(){return((1+Math.random())*65536|0).toString(16).substring(1)}function c(){return b()+b()+"-"+b()+"-"+b()+"-"+b()+"-"+b()+b()+b()}function d(a){return a===Object(a)}function e(a,b){var c=a.length;while(c--)if(a[c]===b)return!0;return!1}function f(a,b){for(var c in b)a[c]=b[c];return a}function g(a,b){if(a==null)return void 0;var c=a[b];return typeof c=="function"?a[b]():c}return a.LocalStorage=window.Store=function(a,b){if(!this.localStorage)throw"Backbone.localStorage: Environment does not support localStorage.";this.name=a,this.serializer=b||{serialize:function(a){return d(a)?JSON.stringify(a):a},deserialize:function(a){return a&&JSON.parse(a)}};var c=this.localStorage().getItem(this.name);this.records=c&&c.split(",")||[]},f(a.LocalStorage.prototype,{save:function(){this.localStorage().setItem(this.name,this.records.join(","))},create:function(a){return!a.id&&a.id!==0&&(a.id=c(),a.set(a.idAttribute,a.id)),this.localStorage().setItem(this._itemName(a.id),this.serializer.serialize(a)),this.records.push(a.id.toString()),this.save(),this.find(a)},update:function(a){this.localStorage().setItem(this._itemName(a.id),this.serializer.serialize(a));var b=a.id.toString();return e(this.records,b)||(this.records.push(b),this.save()),this.find(a)},find:function(a){return this.serializer.deserialize(this.localStorage().getItem(this._itemName(a.id)))},findAll:function(){var a=[];for(var b=0,c,d;b<this.records.length;b++)c=this.records[b],d=this.serializer.deserialize(this.localStorage().getItem(this._itemName(c))),d!=null&&a.push(d);return a},destroy:function(a){this.localStorage().removeItem(this._itemName(a.id));var b=a.id.toString();for(var c=0,d;c<this.records.length;c++)this.records[c]===b&&this.records.splice(c,1);return this.save(),a},localStorage:function(){return localStorage},_clear:function(){var a=this.localStorage(),b=new RegExp("^"+this.name+"-");a.removeItem(this.name);for(var c in a)b.test(c)&&a.removeItem(c);this.records.length=0},_storageSize:function(){return this.localStorage().length},_itemName:function(a){return this.name+"-"+a}}),a.LocalStorage.sync=window.Store.sync=a.localSync=function(b,c,d){var e=g(c,"localStorage")||g(c.collection,"localStorage"),f,h,i=a.$?a.$.Deferred&&a.$.Deferred():a.Deferred&&a.Deferred();try{switch(b){case"read":f=c.id!=undefined?e.find(c):e.findAll();break;case"create":f=e.create(c);break;case"update":f=e.update(c);break;case"delete":f=e.destroy(c)}}catch(j){j.code===22&&e._storageSize()===0?h="Private browsing is unsupported":h=j.message}return f?(d&&d.success&&(a.VERSION==="0.9.10"?d.success(c,f,d):d.success(f)),i&&i.resolve(f)):(h=h?h:"Record Not Found",d&&d.error&&(a.VERSION==="0.9.10"?d.error(c,h,d):d.error(h)),i&&i.reject(h)),d&&d.complete&&d.complete(f),i&&i.promise()},a.ajaxSync=a.sync,a.getSyncMethod=function(b){return b.localStorage||b.collection&&b.collection.localStorage?a.localSync:a.ajaxSync},a.sync=function(b,c,d){return a.getSyncMethod(c).apply(this,[b,c,d])},a.LocalStorage}); | ||
*/(function(a,b){typeof exports=="object"&&typeof require=="function"?module.exports=b(require("backbone")):typeof define=="function"&&define.amd?define(["backbone"],function(c){return b(c||a.Backbone)}):b(Backbone)})(this,function(a){function b(){return((1+Math.random())*65536|0).toString(16).substring(1)}function c(){return b()+b()+"-"+b()+"-"+b()+"-"+b()+"-"+b()+b()+b()}function d(a){return a===Object(a)}function e(a,b){var c=a.length;while(c--)if(a[c]===b)return!0;return!1}function f(a,b){for(var c in b)a[c]=b[c];return a}function g(a,b){if(a==null)return void 0;var c=a[b];return typeof c=="function"?a[b]():c}return a.LocalStorage=window.Store=function(a,b){if(!this.localStorage)throw"Backbone.localStorage: Environment does not support localStorage.";this.name=a,this.serializer=b||{serialize:function(a){return d(a)?JSON.stringify(a):a},deserialize:function(a){return a&&JSON.parse(a)}};var c=this.localStorage().getItem(this.name);this.records=c&&c.split(",")||[]},f(a.LocalStorage.prototype,{save:function(){this.localStorage().setItem(this.name,this.records.join(","))},create:function(a){return!a.id&&a.id!==0&&(a.id=c(),a.set(a.idAttribute,a.id)),this.localStorage().setItem(this._itemName(a.id),this.serializer.serialize(a)),this.records.push(a.id.toString()),this.save(),this.find(a)},update:function(a){this.localStorage().setItem(this._itemName(a.id),this.serializer.serialize(a));var b=a.id.toString();return e(this.records,b)||(this.records.push(b),this.save()),this.find(a)},find:function(a){return this.serializer.deserialize(this.localStorage().getItem(this._itemName(a.id)))},findAll:function(){var a=[];for(var b=0,c,d;b<this.records.length;b++)c=this.records[b],d=this.serializer.deserialize(this.localStorage().getItem(this._itemName(c))),d!=null&&a.push(d);return a},destroy:function(a){this.localStorage().removeItem(this._itemName(a.id));var b=a.id.toString();for(var c=0,d;c<this.records.length;c++)this.records[c]===b&&this.records.splice(c,1);return this.save(),a},localStorage:function(){return localStorage},_clear:function(){var a=this.localStorage(),b=new RegExp("^"+this.name+"-");a.removeItem(this.name);for(var c in a)b.test(c)&&a.removeItem(c);this.records.length=0},_storageSize:function(){return this.localStorage().length},_itemName:function(a){return this.name+"-"+a}}),a.LocalStorage.sync=window.Store.sync=a.localSync=function(b,c,d){var e=g(c,"localStorage")||g(c.collection,"localStorage"),f,h,i=a.$?a.$.Deferred&&a.$.Deferred():a.Deferred&&a.Deferred();try{switch(b){case"read":f=c.id!=undefined?e.find(c):e.findAll();break;case"create":f=e.create(c);break;case"update":f=e.update(c);break;case"delete":f=e.destroy(c)}}catch(j){j.code===22&&e._storageSize()===0?h="Private browsing is unsupported":h=j.message}return f?(d&&d.success&&(a.VERSION==="0.9.10"?d.success(c,f,d):d.success(f)),i&&i.resolve(f)):(h=h?h:"Record Not Found",d&&d.error&&(a.VERSION==="0.9.10"?d.error(c,h,d):d.error(h)),i&&i.reject(h)),d&&d.complete&&d.complete(f),i&&i.promise()},a.ajaxSync=a.sync,a.getSyncMethod=function(b,c){var d=c&&c.ajaxSync;return!d&&(b.localStorage||b.collection&&b.collection.localStorage)?a.localSync:a.ajaxSync},a.sync=function(b,c,d){return a.getSyncMethod(c,d).apply(this,[b,c,d])},a.LocalStorage}); |
/** | ||
* Backbone localStorage Adapter | ||
* Version 1.1.14 | ||
* Version 1.1.15 | ||
* | ||
@@ -241,4 +241,6 @@ * https://github.com/jeromegn/Backbone.localStorage | ||
Backbone.getSyncMethod = function(model) { | ||
if(model.localStorage || (model.collection && model.collection.localStorage)) { | ||
Backbone.getSyncMethod = function(model, options) { | ||
var forceAjaxSync = options && options.ajaxSync; | ||
if(!forceAjaxSync && (model.localStorage || (model.collection && model.collection.localStorage))) { | ||
return Backbone.localSync; | ||
@@ -253,3 +255,3 @@ } | ||
Backbone.sync = function(method, model, options) { | ||
return Backbone.getSyncMethod(model).apply(this, [method, model, options]); | ||
return Backbone.getSyncMethod(model, options).apply(this, [method, model, options]); | ||
}; | ||
@@ -256,0 +258,0 @@ |
# Changelog | ||
## 1.1.15 - January 7, 2015 | ||
- You can now pass `{ajaxSync: true}` as an option to `fetch` and `save` to force remote syncing. (@adamterlson) | ||
- Various fixes. Thanks to @nbergseng, @richardchen331, @eush77, @malept, @HenriqueSilverio | ||
## 1.1.14 - skipped due to some weirdness, inconsistent versioning. | ||
## 1.1.13 - August 5, 2014 | ||
@@ -4,0 +11,0 @@ |
{ | ||
"author": "Jerome Gravel-Niquet <jeromegn@gmail.com> (http://jgn.me)", | ||
"name": "backbone.localstorage", | ||
"version": "1.1.14", | ||
"version": "1.1.15", | ||
"repository": { | ||
@@ -9,14 +9,13 @@ "type": "git", | ||
}, | ||
"dependencies": { | ||
"backbone": "~1.x.x", | ||
"mocha-phantomjs": "^3.5.1", | ||
"phantomjs": "^1.9.12" | ||
}, | ||
"devDependencies": { | ||
"uglify-js": "~1.2.6", | ||
"mocha-phantomjs": "~1.1.2", | ||
"mocha-phantomjs": "^3.5.1", | ||
"browserify": "~2.x.x", | ||
"jquery": "~2.1.0", | ||
"backbone": "~1.x.x", | ||
"underscore": ">=1.4.0" | ||
}, | ||
"peerDependencies": { | ||
"backbone": "~1.x.x" | ||
}, | ||
"keywords": [ | ||
@@ -23,0 +22,0 @@ "backbone", |
@@ -1,2 +0,2 @@ | ||
# Backbone localStorage Adapter v1.1.10 | ||
# Backbone localStorage Adapter v1.1.15 | ||
@@ -29,2 +29,11 @@ [![Build Status](https://secure.travis-ci.org/jeromegn/Backbone.localStorage.png?branch=master)](http://travis-ci.org/jeromegn/Backbone.localStorage) | ||
``` | ||
If needed, you can use the default `Backbone.sync` (instead of local storage) by passing the `ajaxSync` option flag to any Backbone AJAX function, for example: | ||
```javascript | ||
var myModel = new SomeModel(); | ||
myModel.fetch({ ajaxSync: true }); | ||
myModel.save({ new: "value" }, { ajaxSync: true }); | ||
``` | ||
### RequireJS | ||
@@ -31,0 +40,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
1
132
0
1
16985
6
8
227
- Removedbackbone@~1.x.x
- Removedmocha-phantomjs@^3.5.1
- Removedphantomjs@^1.9.12
- Removedabbrev@1.1.1(transitive)
- Removedadm-zip@0.2.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedasn1@0.1.110.2.6(transitive)
- Removedassert-plus@0.1.50.2.01.0.0(transitive)
- Removedasync@0.9.22.6.4(transitive)
- Removedaws-sign2@0.5.00.6.0(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbl@1.0.3(transitive)
- Removedboom@0.4.22.10.1(transitive)
- Removedcaseless@0.11.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedcombined-stream@0.0.71.0.8(transitive)
- Removedcommander@0.6.12.0.02.20.3(transitive)
- Removedconcat-stream@1.5.0(transitive)
- Removedconfig-chain@1.1.13(transitive)
- Removedcore-util-is@1.0.21.0.3(transitive)
- Removedcryptiles@0.2.22.0.5(transitive)
- Removedctype@0.5.3(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddebug@0.7.44.3.7(transitive)
- Removeddelayed-stream@0.0.51.0.0(transitive)
- Removeddiff@1.0.7(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedextend@3.0.2(transitive)
- Removedextract-zip@1.5.0(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfd-slicer@1.0.1(transitive)
- Removedforever-agent@0.5.20.6.1(transitive)
- Removedform-data@0.1.41.0.1(transitive)
- Removedfs-extra@0.26.7(transitive)
- Removedgenerate-function@2.3.1(transitive)
- Removedgenerate-object-property@1.2.0(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedglob@3.2.3(transitive)
- Removedgraceful-fs@2.0.34.2.11(transitive)
- Removedgrowl@1.7.0(transitive)
- Removedhar-validator@2.0.6(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhasha@2.2.0(transitive)
- Removedhawk@1.0.03.1.3(transitive)
- Removedhoek@0.9.12.16.3(transitive)
- Removedhttp-signature@0.10.11.1.1(transitive)
- Removedinherits@1.0.22.0.4(transitive)
- Removedini@1.1.01.3.8(transitive)
- Removedis-my-ip-valid@1.0.1(transitive)
- Removedis-my-json-valid@2.20.6(transitive)
- Removedis-property@1.0.2(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisarray@1.0.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjade@0.26.3(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsonfile@2.4.0(transitive)
- Removedjsonpointer@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedkew@0.1.70.7.0(transitive)
- Removedklaw@1.3.1(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedmime@1.2.11(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedminimatch@0.2.14(transitive)
- Removedminimist@0.0.8(transitive)
- Removedmkdirp@0.3.00.3.50.5.0(transitive)
- Removedmocha@1.20.1(transitive)
- Removedmocha-phantomjs@3.6.0(transitive)
- Removedms@2.1.3(transitive)
- Removedncp@0.4.2(transitive)
- Removednode-uuid@1.4.8(transitive)
- Removednopt@2.2.1(transitive)
- Removednpmconf@0.0.24(transitive)
- Removedoauth-sign@0.3.00.8.2(transitive)
- Removedonce@1.1.1(transitive)
- Removedosenv@0.0.3(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpend@1.2.0(transitive)
- Removedphantomjs@1.9.201.9.7-15(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedprocess-nextick-args@1.0.7(transitive)
- Removedprogress@1.1.8(transitive)
- Removedproto-list@1.2.4(transitive)
- Removedqs@0.6.65.2.1(transitive)
- Removedreadable-stream@2.0.6(transitive)
- Removedrequest@2.36.02.67.0(transitive)
- Removedrequest-progress@0.3.12.0.1(transitive)
- Removedrimraf@2.2.8(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsemver@1.1.4(transitive)
- Removedsigmund@1.0.1(transitive)
- Removedsntp@0.2.41.0.9(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedstringstream@0.0.6(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedthrottleit@0.0.21.0.1(transitive)
- Removedtough-cookie@2.2.2(transitive)
- Removedtunnel-agent@0.4.3(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removedtypedarray@0.0.7(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedverror@1.10.0(transitive)
- Removedwhich@1.0.91.2.14(transitive)
- Removedxtend@4.0.2(transitive)
- Removedyauzl@2.4.1(transitive)