@fedeghe/pangjs 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +22 -22
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # PANGjs (0.0.8)
1
+ # PANGjs (0.0.9)
2
2
 
3
3
  ![alt text](https://github.com/fedeghe/pangjs/blob/main/pangjs.png?raw=true "Pang js")
4
4
 
package/dist/index.js CHANGED
@@ -1,30 +1,30 @@
1
1
  'use strict';
2
2
  /*
3
3
  PANGjs
4
- v. 0.0.8
4
+ v. 0.0.9
5
5
 
6
- Size: ~3.77KB
6
+ Size: ~3.92KB
7
7
  */
8
8
  var PANGjs=function(){"use strict";function t(t,e){if("function"!=typeof t)throw new Error(e)}function e(t,e){if("Promise"!==t.constructor.name)throw new Error(e)}function s(t,e){
9
- if("number"!=typeof t)throw new Error(e)}function i(t,e){this.initState=t,this.states=[t],this.stagedStates=[t],this.config=e,this.maxElements=Math.max(1,parseInt(this.config.maxElements,10))||1,
10
- this.index=0,this.stagedIndex=0}function n(t){this.subscribers.filter(function(t){return Boolean(t)}).forEach(function(e){e(t)})}function r(e,s,n){this.reducer=e||a,
11
- t(this.reducer,o.REDUCERS_FUNCTION),this.initState=s||{},this.config=n||{},this.config.check=this.config.check||function(){return!0},t(this.config.check,o.REDUCERS_FUNCTION),this.subscribers=[],
12
- this.previousAction="ORIGIN",this.HistoryManager=new i(this.initState,this.config)}var o={REDUCERS_FUNCTION:"[ERROR] Reducer must be a function!",
13
- REDUCERS_RETURN:"[ERROR] Reducer should return a promise!",REDUCERS_ASYNC:"[ERROR] Reducer should be asynchronous!",SUBSCRIBERS_FUNCTION:"[ERROR] Subscribers must be a functions!",
14
- ACTION_TYPE:"[ERROR] Actions needs a type!",UNAUTHORIZED_STATECHANGE:"[ERROR] State transition not allowed!",MOVE_TO_NUMBER:"[ERROR] Move requires a number!"};i.prototype.top=function(t){
15
- return this[t?"stagedStates":"states"][this[t?"stagedIndex":"index"]]},i.prototype.stage=function(t,e){var s=this.stagedStates.slice(0,this.stagedIndex+1);return s.push(t),
16
- this.maxElements&&s.length>this.maxElements?s.shift():this.stagedIndex++,this.stagedStates=s,e&&this.sync(),this},i.prototype.sync=function(){this.states=this.stagedStates,this.index=this.stagedIndex
17
- },i.prototype.reset=function(){this.index=0,this.states=[this.initState],this.stagedIndex=0,this.stagedStates=[this.initState]};var a=function(){return Promise.resolve({})}
18
- ;return r.prototype.getState=function(t){return this.HistoryManager.top(t)},r.prototype.unstage=function(){if(1===this.HistoryManager.maxElements)return this
9
+ if("number"!=typeof t)throw new Error(e)}function i(t,e){this.initState=t,this.states=[t],this.stagedStates=[t],this.subscribers=[],this.config=e,
10
+ this.maxElements=Math.max(1,parseInt(this.config.maxElements,10))||1,this.index=0,this.stagedIndex=0}function r(e,s,r){this.reducer=e||o,t(this.reducer,n.REDUCERS_FUNCTION),this.initState=s||{},
11
+ this.config=r||{},this.config.check=this.config.check||function(){return!0},t(this.config.check,n.REDUCERS_FUNCTION),this.previousAction="ORIGIN",this.HistoryManager=new i(this.initState,this.config)}
12
+ var n={REDUCERS_FUNCTION:"[ERROR] Reducer must be a function!",REDUCERS_RETURN:"[ERROR] Reducer should return a promise!",REDUCERS_ASYNC:"[ERROR] Reducer should be asynchronous!",
13
+ SUBSCRIBERS_FUNCTION:"[ERROR] Subscribers must be a functions!",ACTION_TYPE:"[ERROR] Actions needs a type!",UNAUTHORIZED_STATECHANGE:"[ERROR] State transition not allowed!",
14
+ MOVE_TO_NUMBER:"[ERROR] Move requires a number!"};i.prototype.top=function(t){return this[t?"stagedStates":"states"][this[t?"stagedIndex":"index"]]},i.prototype.subscribe=function(e){
15
+ t(e,n.SUBSCRIBERS_FUNCTION);var s,i=this;return this.subscribers.push(e),s=this.subscribers.length-1,function(){i.subscribers[s]=null}},i.prototype.stage=function(t,e){
16
+ var s=this.stagedStates.slice(0,this.stagedIndex+1);return s.push(t),this.maxElements&&s.length>this.maxElements?s.shift():this.stagedIndex++,this.stagedStates=Array.from(s),e&&this.sync(),this},
17
+ i.prototype.sync=function(){this.states=Array.from(this.stagedStates),this.index=this.stagedIndex},i.prototype.emit=function(t){this.subscribers.filter(function(t){return Boolean(t)
18
+ }).forEach(function(e){e(t)})},i.prototype.reset=function(){this.index=0,this.states=[this.initState],this.stagedIndex=0,this.stagedStates=[this.initState]};var o=function(){return Promise.resolve({})
19
+ };return r.prototype.getState=function(t){return this.HistoryManager.top(t)},r.prototype.unstage=function(){if(1===this.HistoryManager.maxElements)return this
19
20
  ;this.HistoryManager.stagedIndex=this.HistoryManager.index,this.HistoryManager.stagedStates=this.HistoryManager.states},r.prototype.stage=function(t,s){
20
- if(!("type"in t))return Promise.reject(new Error(o.ACTION_TYPE));var i=this,r=t.type,a=t.payload||{},h=this.getState(!0)
21
- ;if(!i.config.check(h,i.previousAction,r,a))return Promise.reject(new Error(o.UNAUTHORIZED_STATECHANGE));var u=this.reducer(h,r,a);return e(u,o.REDUCERS_RETURN),this.previousAction=r,
22
- u.then(function(t){return i.HistoryManager.stage(t,s),s&&n.call(i,t),t})},r.prototype.dispatch=function(t){if(t)return this.stage(t,!0);this.HistoryManager.sync();var e=this.HistoryManager.top()
23
- ;return n.call(this,e),Promise.resolve(e)},r.prototype.subscribe=function(e){t(e,o.SUBSCRIBERS_FUNCTION);var s,i=this;return this.subscribers.push(e),s=this.subscribers.length-1,function(){
24
- i.subscribers[s]=null}},r.prototype.move=function(t){
25
- if(s(t,o.MOVE_TO_NUMBER),1===this.HistoryManager.maxElements||this.HistoryManager.index!==this.HistoryManager.stagedIndex||void 0===t||0===t)return this
26
- ;var e=this.HistoryManager.index+t,i=e>-1&&e<this.HistoryManager.states.length,n=i?e:this.HistoryManager.index;return this.HistoryManager.index=n,this.HistoryManager.stagedIndex=n,this},
27
- r.prototype.replaceReducer=function(e){return t(e,o.SUBSCRIBERS_FUNCTION),this.reducer=e,this},r.prototype.reset=function(){return this.HistoryManager.reset(),n.call(this,this.initState),this},{
28
- ERRORS:o,getStore:function(t,e,s){return new r(t,e,s)},isStore:function(t){return t instanceof r},combine:function(e){return e.forEach(function(e){t(e,o.REDUCERS_FUNCTION)}),function(t,s,i){
29
- var n=Object.assign({},t),r=e.length;return new Promise(function(t){return e.reduce(function(e,n,o){return e.then(function(e){return r-1===o?t(n(e,s,i)):n(e,s,i)})},Promise.resolve(n))})}}}}()
21
+ if(!("type"in t))return Promise.reject(new Error(n.ACTION_TYPE));var i=this,r=t.type,o=t.payload||{},a=this.getState(!0)
22
+ ;if(!i.config.check(a,i.previousAction,r,o))return Promise.reject(new Error(n.UNAUTHORIZED_STATECHANGE));var u=this.reducer(a,r,o);return e(u,n.REDUCERS_RETURN),this.previousAction=r,
23
+ u.then(function(t){return i.HistoryManager.stage(t,s),s&&i.HistoryManager.emit(t),t})},r.prototype.dispatch=function(t){if(t)return this.stage(t,!0);this.HistoryManager.sync()
24
+ ;var e=this.HistoryManager.top(!0);return this.HistoryManager.emit(e),Promise.resolve(e)},r.prototype.subscribe=function(t){return this.HistoryManager.subscribe(t)},r.prototype.move=function(t){
25
+ if(s(t,n.MOVE_TO_NUMBER),1===this.HistoryManager.maxElements||this.HistoryManager.index!==this.HistoryManager.stagedIndex||void 0===t||0===t)return this
26
+ ;var e=this.HistoryManager.index+t,i=e>-1&&e<this.HistoryManager.states.length,r=i?e:this.HistoryManager.index;return this.HistoryManager.index=r,this.HistoryManager.stagedIndex=r,this},
27
+ r.prototype.replaceReducer=function(e){return t(e,n.SUBSCRIBERS_FUNCTION),this.reducer=e,this},r.prototype.reset=function(){return this.HistoryManager.emit(this.initState),this.HistoryManager.reset(),
28
+ this},{ERRORS:n,getStore:function(t,e,s){return new r(t,e,s)},isStore:function(t){return t instanceof r},combine:function(e){return e.forEach(function(e){t(e,n.REDUCERS_FUNCTION)}),function(t,s,i){
29
+ var r=Object.assign({},t),n=e.length;return new Promise(function(t){return e.reduce(function(e,r,o){return e.then(function(e){return n-1===o?t(r(e,s,i)):r(e,s,i)})},Promise.resolve(r))})}}}}()
30
30
  ;"object"==typeof exports&&(module.exports=PANGjs);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedeghe/pangjs",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "main": "dist/index.js",
5
5
  "author": "fedeghe <fedeghe@gmail.com>",
6
6
  "description": "Lightweight asynchronous state manager",