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 +1 -1
- package/LICENSE.md +1 -1
- package/README.md +1 -2
- package/dist/index.js +15 -15
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
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
|
[](https://coveralls.io/github/fedeghe/ridof?branch=master)
|
|
2
|
-
[](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.
|
|
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
|
|
17
|
-
this.tagsManager=new s("INITIAL",this.config),this.currentIndex=0,this.listeners=[]}function
|
|
18
|
-
;for(s in t)o[s]=t[s](o[s],
|
|
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
|
|
21
|
-
s.prototype.
|
|
22
|
-
var s=this.states[this.currentIndex];this.listeners.forEach(function(
|
|
23
|
-
this.tagsManager.reset(this.currentIndex+1)),++this.currentIndex,this.tagsManager.
|
|
24
|
-
return this.states[this.currentIndex]},
|
|
25
|
-
;if(!this.tagsManager.canMoveTo(t.type,this.state))throw new Error(r.UNAUTHORIZED_STATECHANGE);var n
|
|
26
|
-
delete o.type,s)for(
|
|
27
|
-
s=this.listeners.length-1,function(){
|
|
28
|
-
|
|
29
|
-
;var e=this,s=this.currentIndex+t,
|
|
30
|
-
t(
|
|
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);
|