Permalink
Browse files

Added minifying script for convenience + instructions in the readme

  • Loading branch information...
1 parent 8343753 commit c3681f1359f8164b45d427c2a06fb881ca2a8a55 @jeromegn committed Mar 26, 2012
Showing with 37 additions and 3 deletions.
  1. +1 −0 .gitignore
  2. +5 −0 Makefile
  3. +11 −0 README.md
  4. +2 −3 backbone.localStorage-min.js
  5. +18 −0 package.json
View
@@ -0,0 +1 @@
+node_modules
View
@@ -0,0 +1,5 @@
+test:
+ npm test
+
+minified:
+ uglifyjs -o backbone.localStorage-min.js backbone.localStorage.js
View
@@ -25,6 +25,17 @@ window.SomeCollection = Backbone.Collection.extend({
Feel free to use Backbone as you usually would, this is a drop-in replacement.
+## Contributing
+
+1. Fork;
+2. Write code;
+3. Write tests (or vice et versa);
+4. `make test`;
+5. `make minified`;
+6. Create a pull request.
+
+Have fun!
+
## Credits
Thanks to [Mark Woodall](https://github.com/llad) for the QUnit tests.
@@ -1,5 +1,4 @@
/**
- * Backbone localStorage Adapter v1.0
+ * Backbone localStorage Adapter
* https://github.com/jeromegn/Backbone.localStorage
- */
-(function(){function b(){return(((1+Math.random())*65536)|0).toString(16).substring(1)}function a(){return(b()+b()+"-"+b()+"-"+b()+"-"+b()+"-"+b()+b()+b())}Backbone.LocalStorage=window.Store=function(d){this.name=d;var c=this.localStorage().getItem(this.name);this.records=(c&&c.split(","))||[]};_.extend(Backbone.LocalStorage.prototype,{save:function(){this.localStorage().setItem(this.name,this.records.join(","))},create:function(c){if(!c.id){c.id=c.attributes[c.idAttribute]=a()}this.localStorage().setItem(this.name+"-"+c.id,JSON.stringify(c));this.records.push(c.id.toString());this.save();return c},update:function(c){this.localStorage().setItem(this.name+"-"+c.id,JSON.stringify(c));if(!_.include(this.records,c.id.toString())){this.records.push(c.id.toString())}this.save();return c},find:function(c){return JSON.parse(this.localStorage().getItem(this.name+"-"+c.id))},findAll:function(){return _(this.records).chain().map(function(c){return JSON.parse(this.localStorage().getItem(this.name+"-"+c))},this).compact().value()},destroy:function(c){this.localStorage().removeItem(this.name+"-"+c.id);this.records=_.reject(this.records,function(d){return d==c.id.toString()});this.save();return c},localStorage:function(){return localStorage}});Backbone.LocalStorage.sync=window.Store.sync=Backbone.localSync=function(h,f,e,d){if(typeof e=="function"){e={success:e,error:d}}var g;var c=f.localStorage||f.collection.localStorage;switch(h){case"read":g=f.id!=undefined?c.find(f):c.findAll();break;case"create":g=c.create(f);break;case"update":g=c.update(f);break;case"delete":g=c.destroy(f);break}if(g){e.success(g)}else{e.error("Record not found")}};Backbone.ajaxSync=Backbone.sync;Backbone.sync=Backbone.LocalStorage.sync})();
+ */(function(){function a(){return((1+Math.random())*65536|0).toString(16).substring(1)}function b(){return a()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a()}Backbone.LocalStorage=window.Store=function(a){this.name=a;var b=this.localStorage().getItem(this.name);this.records=b&&b.split(",")||[]},_.extend(Backbone.LocalStorage.prototype,{save:function(){this.localStorage().setItem(this.name,this.records.join(","))},create:function(a){return a.id||(a.id=a.attributes[a.idAttribute]=b()),this.localStorage().setItem(this.name+"-"+a.id,JSON.stringify(a)),this.records.push(a.id.toString()),this.save(),a},update:function(a){return this.localStorage().setItem(this.name+"-"+a.id,JSON.stringify(a)),_.include(this.records,a.id.toString())||this.records.push(a.id.toString()),this.save(),a},find:function(a){return JSON.parse(this.localStorage().getItem(this.name+"-"+a.id))},findAll:function(){return _(this.records).chain().map(function(a){return JSON.parse(this.localStorage().getItem(this.name+"-"+a))},this).compact().value()},destroy:function(a){return this.localStorage().removeItem(this.name+"-"+a.id),this.records=_.reject(this.records,function(b){return b==a.id.toString()}),this.save(),a},localStorage:function(){return localStorage}}),Backbone.LocalStorage.sync=window.Store.sync=Backbone.localSync=function(a,b,c,d){var e=b.localStorage||b.collection.localStorage;typeof c=="function"&&(c={success:c,error:d});var f;switch(a){case"read":f=b.id!=undefined?e.find(b):e.findAll();break;case"create":f=e.create(b);break;case"update":f=e.update(b);break;case"delete":f=e.destroy(b)}f?c.success(f):c.error("Record not found")},Backbone.ajaxSync=Backbone.sync,Backbone.getSyncMethod=function(a){return a.localStorage||a.collection&&a.collection.localStorage?Backbone.localSync:Backbone.ajaxSync},Backbone.sync=function(a,b,c,d){Backbone.getSyncMethod(b).apply(this,[a,b,c,d])}})();
View
@@ -0,0 +1,18 @@
+{
+ "author": "Jerome Gravel-Niquet <jeromegn@gmail.com> (http://jgn.me)",
+ "name": "Backbone.localStorage",
+ "version": "0.0.0",
+ "repository": {
+ "type": "git"
+ , "url": "git://github.com/jeromegn/Backbone.localStorage.git"
+ },
+ "scripts": {
+ "test" : "open tests/test.html"
+ },
+ "dependencies": {
+ "uglify-js" : "~1.2.6"
+ },
+ "engines": {
+ "node": "*"
+ }
+}

0 comments on commit c3681f1

Please sign in to comment.