ridof 1.3.0 → 1.3.2

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,3 @@
1
1
  ### Changelog
2
2
 
3
- **1.2.7**: update vulnerable deps
3
+ **1.2.7**: update vulnerable deps
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 <Federico Ghedina <fedeghe@gmail.com>>
3
+ Copyright (c) 2024 <Federico Ghedina <fedeghe@gmail.com>>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this
6
6
  software and associated documentation files (the "Software"), to deal in the Software
package/README.md CHANGED
@@ -1,5 +1,4 @@
1
1
  [![Coverage Status](https://coveralls.io/repos/github/fedeghe/ridof/badge.svg?branch=master)](https://coveralls.io/github/fedeghe/ridof?branch=master)
2
- [![Build Status](https://travis-ci.org/fedeghe/ridof.svg?branch=master)](https://travis-ci.org/fedeghe/ridof)
3
2
 
4
3
  # Ridof
5
4
 
@@ -174,7 +173,7 @@ Restrict state transitions
174
173
  From version 1.3.0 is possible to restrict the state transitions passing to `getStore` a third config parameter as a function:
175
174
 
176
175
  ``` js
177
- Ridof.getStore(reducer, initState, (currentTag, nextTag, state) => {
176
+ Ridof.getStore(reducer, initState, (currentTag, nextTag, state, action) => {
178
177
  // here tags are corresponds to action types
179
178
  // let's say we want only one plugin to be added
180
179
  if (currentTag === 'ADDPLUGIN' && nextTag === 'ADDPLUGIN') return false
package/dist/index.js CHANGED
@@ -8,24 +8,24 @@
8
8
  d88 d88 88b ,88b 88b d88 d88
9
9
  d88' d88' `?88P'`88b`?8888P'd88'
10
10
 
11
- v. 1.3.0
11
+ v. 1.3.2
12
12
 
13
13
  Size: ~3KB
14
14
  */
15
15
  var Ridof=function(){"use strict";function t(t,e){if("function"!=typeof t)throw new Error(e)}function e(t,e){if(void 0===t)throw new Error(e)}function s(t,e){this.activeCheck=!!e,this.config=e,
16
- this.tags=[t],this.index=0}function n(e,n,i){t(e,r.REDUCERS_FUNCTION),this.reducer=e,this.state=void 0!==n?n:this.reducer(),this.states=[this.state],this.config=i,
17
- this.tagsManager=new s("INITIAL",this.config),this.currentIndex=0,this.listeners=[]}function i(t){const e={};var s;for(s in t)e[s]=t[s]();return function(n,i,r){n=n||e;var o=Object.assign({},n)
18
- ;for(s in t)o[s]=t[s](o[s],i,r);return o}}const r={REDUCERS_FUNCTION:"[ERROR] Reducer must be a function!",REDUCERS_RETURN:"[ERROR] Reducer should return something!",
16
+ this.tags=[t],this.index=0}function i(e,i,n){t(e,r.REDUCERS_FUNCTION),this.reducer=e,this.state=void 0!==i?i:this.reducer(),this.states=[this.state],this.config=n,
17
+ this.tagsManager=new s("INITIAL",this.config),this.currentIndex=0,this.listeners=[]}function n(t){const e={};var s;for(s in t)e[s]=t[s]();return function(i,n,r){i=i||e;var o=Object.assign({},i)
18
+ ;for(s in t)o[s]=t[s](o[s],n,r);return o}}const r={REDUCERS_FUNCTION:"[ERROR] Reducer must be a function!",REDUCERS_RETURN:"[ERROR] Reducer should return something!",
19
19
  SUBSCRIBERS_FUNCTION:"[ERROR] Subscribers must be a functions!",ACTION_TYPE:"[ERROR] Actions needs a type",UNAUTHORIZED_STATECHANGE:"[ERROR] State transition not allowed"}
20
- ;return s.prototype.getCurrent=function(){return this.tags[this.index]},s.prototype.canMoveTo=function(t,e){var s=this.getCurrent();return!this.activeCheck||this.config(s,t,e)},
21
- s.prototype.add=function(t,e){this.index=e,this.tags[this.index]=t},s.prototype.reset=function(t){this.tags=t?this.tags.slice(0,t):[]},n.prototype.pushState=function(t,e){
22
- var s=this.states[this.currentIndex];this.listeners.forEach(function(n){n(s,t,e)}),this.currentIndex<this.states.length-1&&(this.states=this.states.slice(0,this.currentIndex),
23
- this.tagsManager.reset(this.currentIndex+1)),++this.currentIndex,this.tagsManager.add(e,this.currentIndex),this.states[this.currentIndex]=t},n.prototype.getState=function(){
24
- return this.states[this.currentIndex]},n.prototype.dispatch=function(t,s){if(!("type"in t))throw new Error(r.ACTION_TYPE)
25
- ;if(!this.tagsManager.canMoveTo(t.type,this.state))throw new Error(r.UNAUTHORIZED_STATECHANGE);var n,i=t.type,o=this.reducer(this.states[this.currentIndex],i,t);if(e(o,r.REDUCERS_RETURN),
26
- delete o.type,s)for(n in t)"type"===n||n in o||(o[n]=t[n]);return this.pushState(o,i),this},n.prototype.subscribe=function(e){t(e,r.SUBSCRIBERS_FUNCTION);var s,n=this;return this.listeners.push(e),
27
- s=this.listeners.length-1,function(){n.listeners=n.listeners.slice(0,s).concat(n.listeners.slice(s+1))}},n.prototype.replaceReducer=function(e){t(e,r.REDUCERS_FUNCTION),this.reducer=e},
28
- n.prototype.reset=function(){var t=this.states[0];this.states=[t],this.currentIndex=0,this.tagsManager.reset(),this.listeners=[]},n.prototype.move=function(t){if(0===t)return this
29
- ;var e=this,s=this.currentIndex+t,n=this.getState(),i=t>0?"FORWARD":"BACKWARD",r=s>-1&&s<this.states.length;return this.currentIndex=r?s:this.currentIndex,r&&this.listeners.forEach(function(t){
30
- t(n,e.getState(),{type:["TIMETRAVEL_",i].join("")})}),this},{combine:i,getStore:function(t,e,s){return new n(t,e,s)},isStore:function(t){return t instanceof n},ERRORS:r}}()
20
+ ;return s.prototype.getCurrent=function(){return this.tags[this.index]},s.prototype.canMoveTo=function(t,e,s){var i=this.getCurrent();return!this.activeCheck||this.config(i,t,e,s)},
21
+ s.prototype.save=function(t,e){this.index=e,this.tags=this.tags.slice(0,e),this.tags[this.index]=t},s.prototype.reset=function(t){this.tags=t?this.tags.slice(0,t):[]},
22
+ i.prototype.pushState=function(t,e){var s=this.states[this.currentIndex];JSON.stringify(s)!==JSON.stringify(t)&&(this.listeners.forEach(function(i){i(s,t,e)}),
23
+ this.currentIndex<this.states.length-1&&(this.states=this.states.slice(0,this.currentIndex),this.tagsManager.reset(this.currentIndex+1)),++this.currentIndex,this.tagsManager.save(e,this.currentIndex),
24
+ this.states[this.currentIndex]=t)},i.prototype.getState=function(){return this.states[this.currentIndex]},i.prototype.dispatch=function(t,s){if(!("type"in t))throw new Error(r.ACTION_TYPE)
25
+ ;if(!this.tagsManager.canMoveTo(t.type,this.state,t))throw new Error(r.UNAUTHORIZED_STATECHANGE);var i,n=t.type,o=this.reducer(this.states[this.currentIndex],n,t);if(e(o,r.REDUCERS_RETURN),
26
+ delete o.type,s)for(i in t)"type"===i||i in o||(o[i]=t[i]);return this.pushState(o,n),this},i.prototype.subscribe=function(e){t(e,r.SUBSCRIBERS_FUNCTION);var s,i=this;return this.listeners.push(e),
27
+ s=this.listeners.length-1,function(){i.listeners=i.listeners.slice(0,s).concat(i.listeners.slice(s+1))}},i.prototype.replaceReducer=function(e){t(e,r.REDUCERS_FUNCTION),this.reducer=e},
28
+ i.prototype.reset=function(){var t=this.states[0];this.states=[t],this.currentIndex=0,this.tagsManager.reset(),this.listeners=[]},i.prototype.move=function(t){if(0===t)return this
29
+ ;var e=this,s=this.currentIndex+t,i=this.getState(),n=t>0?"FORWARD":"BACKWARD",r=s>-1&&s<this.states.length;return this.currentIndex=r?s:this.currentIndex,r&&this.listeners.forEach(function(t){
30
+ t(i,e.getState(),{type:["TIMETRAVEL_",n].join("")})}),this},{combine:n,getStore:function(t,e,s){return new i(t,e,s)},isStore:function(t){return t instanceof i},ERRORS:r}}()
31
31
  ;"object"==typeof exports&&(module.exports=Ridof);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ridof",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Simple isomorphic state manager",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {