Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "persisto", | ||
"description": "Persist Javascript objects to localStorage and remote servers.", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": [ | ||
"dist/persisto.min.js" | ||
"dist/persisto.js" | ||
], | ||
@@ -8,0 +8,0 @@ "license": "MIT", |
@@ -9,4 +9,4 @@ /*! | ||
* | ||
* @version 0.0.2 | ||
* @date 2016-04-10T14:29 | ||
* @version 0.0.3 | ||
* @date 2016-04-17T17:26 | ||
*/ | ||
@@ -63,2 +63,3 @@ | ||
this.debugLevel: 1; // Set to 1 by 'grunt build' | ||
this._checkTimer = null; | ||
@@ -116,2 +117,5 @@ this.namespace = namespace; | ||
window.PersistentObject.prototype = { | ||
/** @type {string} */ | ||
version: "0.0.3", // Set to semver by 'grunt release' | ||
/* Trigger commit/push according to current settings. */ | ||
@@ -118,0 +122,0 @@ _invalidate: function(hint, deferredCall) { |
@@ -1,12 +0,4 @@ | ||
/*! | ||
* persisto.js | ||
* | ||
* Persistent, editable objects for Javascript. | ||
* | ||
* Copyright (c) 2016, Martin Wendt (http://wwWendt.de) | ||
* Released under the MIT license | ||
* | ||
* @version 0.0.2 | ||
* @date 2016-04-10T14:29 | ||
*/ | ||
!function(a,b,c,d){"use strict";function e(){return(new Date).getTime()}var f=9007199254740991;b.PersistentObject=function(c,f){var g,h=this,i=a.Deferred(),j=e();"string"!=typeof c&&a.error("Missing required argument: namespace"),this.opts=a.extend({remote:null,init:{},commitDelay:500,maxCommitDelay:3e3,pushDelay:5e3,maxPushDelay:3e4,debug:2,storage:b.localStorage,change:a.noop,commit:a.noop,conflict:a.noop,error:a.noop,pull:a.noop,push:a.noop,update:a.noop},f),this._checkTimer=null,this.namespace=c,this.storage=this.opts.storage,this._data=this.opts.init,this.offline=d,this.phase=null,this.uncommittedSince=null,this.unpushedSince=null,this.lastUpdate=0,this.lastPull=0,this.commitCount=0,this.pushCount=0,this.lastModified=j,this.ready=i.promise,g=this.storage?this.storage.getItem(this.namespace):null,this.opts.remote?this.pull().done(function(){h.offline=!1,i.resolve()}).fail(function(){h.offline=!0,null!=g?(console.warn(h+": could not init from remote; falling back to storage."),h._data=a.extend({},h.opts.init,JSON.parse(g))):console.warn(h+": could not init from remote; falling back default."),i.resolve()}):null!=g?(this.update(),this._data=a.extend({},this.opts.init,this._data),i.resolve()):i.resolve()},b.PersistentObject.prototype={_invalidate:function(a,b){var c=this,d=this.lastModified,g=e(),h=0,i=0,j=0;this._checkTimer&&(clearTimeout(this._checkTimer),this._checkTimer=null),b?this.debug("_invalidate recursive()"):(this.lastModified=g,this.uncommittedSince||(this.uncommittedSince=g),this.unpushedSince||(this.unpushedSince=g),this.opts.change(a)),this.storage&&(g-d>=this.opts.commitDelay||g-this.uncommittedSince>=this.opts.maxCommitDelay?(this.debug("_invalidate: force commit",g-d>=this.opts.commitDelay,g-this.uncommittedSince>=this.opts.maxCommitDelay),this.commit()):h=Math.min(g+this.opts.commitDelay+1,this.uncommittedSince+this.opts.maxCommitDelay+1)),this.opts.remote&&(g-d>=this.opts.pushDelay||g-this.unpushedSince>=this.opts.maxPushDelay?(this.debug("_invalidate: force push",g-d>=this.opts.pushDelay,g-this.unpushedSince>=this.opts.maxPushDelay),this.push()):i=Math.min(g+this.opts.pushDelay+1,this.unpushedSince+this.opts.maxPushDelay+1)),(h||i)&&(j=Math.min(h||f,i||f),this.debug("_invalidate defer ("+a+") by "+(j-g)+"ms"),this._checkTimer=setTimeout(function(){c._checkTimer=null,c._invalidate.call(c,null,!0)},j-g))},_update:function(a){this.uncommittedSince&&(console.warn("Updating an uncommitted object."),this.conflict(a,this._data)===!1)||(this._data=a,this.lastUpdate=e())},toString:function(){return"PersistentObject('"+this.namespace+"')"},debug:function(){this.opts.debug>=1&&(Array.prototype.unshift.call(arguments,this.toString()),console.log.apply(b.console,arguments))},isDirty:function(){return!!(this.storage&&this.uncommittedSince||this.opts.remote&&this.unpushedSince)},isReady:function(){return"pending"!==this.ready.state},get:function(a){var b,c=this._data,d=(""+a).replace(/\[(\w+)\]/g,".$1").replace(/^\./,"").split(".");for(b=0;b<d.length;b++)c=c[d[b]];return c},set:function(a,b){var c,d=this._data,e=(""+a).replace(/\[(\w+)\]/g,".$1").replace(/^\./,"").split("."),f=e.pop();for(c=0;c<e.length;c++)d=d[e[c]];d[f]!==b&&(d[f]=b,this._invalidate("set"))},remove:function(a){delete this._data[a],this._invalidate("remove")},reset:function(a){this._data=a||{},this._invalidate("reset")},setDirty:function(a){a===!1||this._invalidate("explicit")},update:function(){this.phase&&a.error(this+": Trying to update while '"+this.phase+"' is pending."),this.opts.debug>=2&&console.time&&console.time(this+".update");var b=this.storage.getItem(this.namespace);b=JSON.parse(b),this._update(b),this.opts.debug>=2&&console.time&&console.timeEnd(this+".update")},commit:function(){var b;return this.phase&&a.error(this+": Trying to commit while '"+this.phase+"' is pending."),this.opts.debug>=2&&console.time&&console.time(this+".commit"),b=JSON.stringify(this._data),this.storage.setItem(this.namespace,b),this.uncommittedSince=null,this.commitCount+=1,this.opts.debug>=2&&console.time&&console.timeEnd(this+".commit"),b},pull:function(){var b=this;return this.phase&&a.error(this+": Trying to pull while '"+this.phase+"' is pending."),this.opts.debug>=2&&console.time&&console.time(this+".pull"),this.phase="pull",a.ajax({type:"GET",url:this.opts.remote}).done(function(c){var d=c;a.isArray(c)||a.isPlainObject(c)?d=JSON.stringify(c):c=JSON.parse(c),b.storage.setItem(b.namespace,d),b._update(c),b.lastPull=e()}).fail(function(){b.opts.error(arguments)}).always(function(){b.phase=null,b.opts.debug>=2&&console.time&&console.timeEnd(b+".pull")})},push:function(){var b=this,c=this.commit();return this.phase&&a.error(this+": Trying to push while '"+this.phase+"' is pending."),this.opts.debug>=2&&console.time&&console.time(b+".push"),this.phase="push",this.opts.remote||a.error(this+": missing remote option"),a.ajax({type:"PUT",url:this.opts.remote,data:c}).done(function(){b.unpushedSince=null,b.pushCount+=1}).fail(function(){b.opts.error(arguments)}).always(function(){b.phase=null,b.opts.debug>=2&&console.time&&console.timeEnd(b+".push")})},readFromForm:function(b,c){var e=this,f=a(b),g=a.extend({addNew:!1,coerce:!0,trim:!0},c);g.addNew&&f.find("[name]").each(function(){var b=a(this).attr("name");e._data[b]===d&&(e._data[b]=null,e.debug("readFromForm: add field '"+b+"'"))}),a.each(this._data,function(b,c){var d,h=f.find("[name='"+b+"']"),i=h.attr("type");return h.length?("radio"===i?d=h.filter(":checked").val():"checkbox"===i&&1===h.length?d=!!h.filter(":checked").length:"checkbox"===i&&h.length>1?(d=[],h.filter(":checked").each(function(){d.push(a(this).val())})):(d=h.val(),g.trim&&"string"==typeof d&&(d=a.trim(d))),void e.set(b,d)):void e.debug("readFromForm: field not found: '"+b+"'")})},writeToForm:function(b,c){var d=a(b);a.each(this._data,function(b,c){var e=d.find("[name='"+b+"']"),f=e.attr("type");e.length&&("radio"===f?e.filter("[value='"+c+"']").prop("checked",!0):"checkbox"===f?1===e.length?e.prop("checked",!!c):e.each(function(){a(this).prop("checked",a.isArray(c)?a.inArray(this.value,c)>=0:this.value===c)}):e.is("select")?e.find("option").each(function(){a(this).prop("selected",a.isArray(c)?a.inArray(this.value,c)>=0:this.value===c)}):e.val(c))})}}}(jQuery,window,document); | ||
/*! Persistent, editable objects for Javascript. - v0.0.3 - 2016-04-17 | https://github.com/mar10/persisto | Copyright (c) 2016 Martin Wendt; Licensed MIT */ | ||
!function(a,b,c,d){"use strict";function e(){return(new Date).getTime()}var f=9007199254740991;b.PersistentObject=function(c,f){var g,h=this,i=a.Deferred(),j=e();"string"!=typeof c&&a.error("Missing required argument: namespace"),this.opts=a.extend({remote:null,init:{},commitDelay:500,maxCommitDelay:3e3,pushDelay:5e3,maxPushDelay:3e4,debug:2,storage:b.localStorage,change:a.noop,commit:a.noop,conflict:a.noop,error:a.noop,pull:a.noop,push:a.noop,update:a.noop},f),this.debugLevel: 1,this._checkTimer=null,this.namespace=c,this.storage=this.opts.storage,this._data=this.opts.init,this.offline=d,this.phase=null,this.uncommittedSince=null,this.unpushedSince=null,this.lastUpdate=0,this.lastPull=0,this.commitCount=0,this.pushCount=0,this.lastModified=j,this.ready=i.promise,g=this.storage?this.storage.getItem(this.namespace):null,this.opts.remote?this.pull().done(function(){h.offline=!1,i.resolve()}).fail(function(){h.offline=!0,null!=g?(console.warn(h+": could not init from remote; falling back to storage."),h._data=a.extend({},h.opts.init,JSON.parse(g))):console.warn(h+": could not init from remote; falling back default."),i.resolve()}):null!=g?(this.update(),this._data=a.extend({},this.opts.init,this._data),i.resolve()):i.resolve()},b.PersistentObject.prototype={version:"0.0.3",_invalidate:function(a,b){var c=this,d=this.lastModified,g=e(),h=0,i=0,j=0;this._checkTimer&&(clearTimeout(this._checkTimer),this._checkTimer=null),b?this.debug("_invalidate recursive()"):(this.lastModified=g,this.uncommittedSince||(this.uncommittedSince=g),this.unpushedSince||(this.unpushedSince=g),this.opts.change(a)),this.storage&&(g-d>=this.opts.commitDelay||g-this.uncommittedSince>=this.opts.maxCommitDelay?(this.debug("_invalidate: force commit",g-d>=this.opts.commitDelay,g-this.uncommittedSince>=this.opts.maxCommitDelay),this.commit()):h=Math.min(g+this.opts.commitDelay+1,this.uncommittedSince+this.opts.maxCommitDelay+1)),this.opts.remote&&(g-d>=this.opts.pushDelay||g-this.unpushedSince>=this.opts.maxPushDelay?(this.debug("_invalidate: force push",g-d>=this.opts.pushDelay,g-this.unpushedSince>=this.opts.maxPushDelay),this.push()):i=Math.min(g+this.opts.pushDelay+1,this.unpushedSince+this.opts.maxPushDelay+1)),(h||i)&&(j=Math.min(h||f,i||f),this.debug("_invalidate defer ("+a+") by "+(j-g)+"ms"),this._checkTimer=setTimeout(function(){c._checkTimer=null,c._invalidate.call(c,null,!0)},j-g))},_update:function(a){this.uncommittedSince&&(console.warn("Updating an uncommitted object."),this.conflict(a,this._data)===!1)||(this._data=a,this.lastUpdate=e())},toString:function(){return"PersistentObject('"+this.namespace+"')"},debug:function(){this.opts.debug>=1&&(Array.prototype.unshift.call(arguments,this.toString()),console.log.apply(b.console,arguments))},isDirty:function(){return!!(this.storage&&this.uncommittedSince||this.opts.remote&&this.unpushedSince)},isReady:function(){return"pending"!==this.ready.state},get:function(a){var b,c=this._data,d=(""+a).replace(/\[(\w+)\]/g,".$1").replace(/^\./,"").split(".");for(b=0;b<d.length;b++)c=c[d[b]];return c},set:function(a,b){var c,d=this._data,e=(""+a).replace(/\[(\w+)\]/g,".$1").replace(/^\./,"").split("."),f=e.pop();for(c=0;c<e.length;c++)d=d[e[c]];d[f]!==b&&(d[f]=b,this._invalidate("set"))},remove:function(a){delete this._data[a],this._invalidate("remove")},reset:function(a){this._data=a||{},this._invalidate("reset")},setDirty:function(a){a===!1||this._invalidate("explicit")},update:function(){this.phase&&a.error(this+": Trying to update while '"+this.phase+"' is pending."),this.opts.debug>=2&&console.time&&console.time(this+".update");var b=this.storage.getItem(this.namespace);b=JSON.parse(b),this._update(b),this.opts.debug>=2&&console.time&&console.timeEnd(this+".update")},commit:function(){var b;return this.phase&&a.error(this+": Trying to commit while '"+this.phase+"' is pending."),this.opts.debug>=2&&console.time&&console.time(this+".commit"),b=JSON.stringify(this._data),this.storage.setItem(this.namespace,b),this.uncommittedSince=null,this.commitCount+=1,this.opts.debug>=2&&console.time&&console.timeEnd(this+".commit"),b},pull:function(){var b=this;return this.phase&&a.error(this+": Trying to pull while '"+this.phase+"' is pending."),this.opts.debug>=2&&console.time&&console.time(this+".pull"),this.phase="pull",a.ajax({type:"GET",url:this.opts.remote}).done(function(c){var d=c;a.isArray(c)||a.isPlainObject(c)?d=JSON.stringify(c):c=JSON.parse(c),b.storage.setItem(b.namespace,d),b._update(c),b.lastPull=e()}).fail(function(){b.opts.error(arguments)}).always(function(){b.phase=null,b.opts.debug>=2&&console.time&&console.timeEnd(b+".pull")})},push:function(){var b=this,c=this.commit();return this.phase&&a.error(this+": Trying to push while '"+this.phase+"' is pending."),this.opts.debug>=2&&console.time&&console.time(b+".push"),this.phase="push",this.opts.remote||a.error(this+": missing remote option"),a.ajax({type:"PUT",url:this.opts.remote,data:c}).done(function(){b.unpushedSince=null,b.pushCount+=1}).fail(function(){b.opts.error(arguments)}).always(function(){b.phase=null,b.opts.debug>=2&&console.time&&console.timeEnd(b+".push")})},readFromForm:function(b,c){var e=this,f=a(b),g=a.extend({addNew:!1,coerce:!0,trim:!0},c);g.addNew&&f.find("[name]").each(function(){var b=a(this).attr("name");e._data[b]===d&&(e._data[b]=null,e.debug("readFromForm: add field '"+b+"'"))}),a.each(this._data,function(b,c){var d,h=f.find("[name='"+b+"']"),i=h.attr("type");return h.length?("radio"===i?d=h.filter(":checked").val():"checkbox"===i&&1===h.length?d=!!h.filter(":checked").length:"checkbox"===i&&h.length>1?(d=[],h.filter(":checked").each(function(){d.push(a(this).val())})):(d=h.val(),g.trim&&"string"==typeof d&&(d=a.trim(d))),void e.set(b,d)):void e.debug("readFromForm: field not found: '"+b+"'")})},writeToForm:function(b,c){var d=a(b);a.each(this._data,function(b,c){var e=d.find("[name='"+b+"']"),f=e.attr("type");e.length&&("radio"===f?e.filter("[value='"+c+"']").prop("checked",!0):"checkbox"===f?1===e.length?e.prop("checked",!!c):e.each(function(){a(this).prop("checked",a.isArray(c)?a.inArray(this.value,c)>=0:this.value===c)}):e.is("select")?e.find("option").each(function(){a(this).prop("selected",a.isArray(c)?a.inArray(this.value,c)>=0:this.value===c)}):e.val(c))})}}}(jQuery,window,document); | ||
//# sourceMappingURL=persisto.min.js.map |
@@ -5,3 +5,5 @@ { | ||
"description": "Persist Javascript objects to localStorage and remote servers.", | ||
"version": "0.0.2", | ||
"filename": "dist/persisto.min.js", | ||
"main": "dist/persisto.js", | ||
"version": "0.0.3", | ||
"homepage": "https://github.com/mar10/persisto", | ||
@@ -53,3 +55,14 @@ "author": { | ||
"test": "grunt ci --verbose" | ||
} | ||
}, | ||
"npmName": "persisto", | ||
"npmFileMap": [ | ||
{ | ||
"basePath": "dist", | ||
"files": [ | ||
"persisto.js", | ||
"persisto.min.js", | ||
"persisto.min.js.map" | ||
] | ||
} | ||
] | ||
} |
@@ -1,6 +0,5 @@ | ||
# persisto | ||
# persisto [![GitHub version](https://badge.fury.io/gh/mar10%2Fpersisto.svg)](https://github.com/mar10/persisto/releases/latest) [![Build Status](https://travis-ci.org/mar10/persisto.svg?branch=master)](https://travis-ci.org/mar10/persisto) | ||
> Persistent, editable objects for Javascript. | ||
Features | ||
@@ -22,3 +21,3 @@ | ||
![sample](architecture.png?raw=true) | ||
![sample](doc/architecture.png?raw=true) | ||
@@ -25,0 +24,0 @@ |
@@ -62,2 +62,3 @@ /*! | ||
this.debugLevel = 2; // Set to 1 by 'grunt build' | ||
this._checkTimer = null; | ||
@@ -115,2 +116,5 @@ this.namespace = namespace; | ||
window.PersistentObject.prototype = { | ||
/** @type {string} */ | ||
version: "@VERSION", // Set to semver by 'grunt release' | ||
/* Trigger commit/push according to current settings. */ | ||
@@ -117,0 +121,0 @@ _invalidate: function(hint, deferredCall) { |
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
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
156511
22
1499
357