ridof 1.3.2 → 1.3.4

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,4 @@
1
1
  ### Changelog
2
2
 
3
- **1.2.7**: update vulnerable deps
3
+ **1.2.7**: update vulnerable deps.
4
+ **1.3.4**: fix major problem due to previous dependencies update.
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2024 <Federico Ghedina <fedeghe@gmail.com>>
3
+ Copyright (c) 2025 <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
@@ -8,12 +8,6 @@ Simple isomorphic state manager
8
8
 
9
9
  @ yarn add ridof
10
10
 
11
- ## Run the tests coverage
12
-
13
-
14
- @ cd node_modules/ridof
15
- @ yarn && yarn build && yarn cover
16
-
17
11
  ## Use it
18
12
 
19
13
  Create a store
@@ -26,7 +20,7 @@ const initialState = {
26
20
  }
27
21
  // The reducer function
28
22
  // params holds all the values passed to dispatch but the type
29
- const reducer = (oldState, action, params) => {
23
+ const reducer = (oldState, action, payload) => {
30
24
  const newState = Object.assign({}, oldState)
31
25
  switch (action) {
32
26
  case 'INCREMENT':
@@ -39,7 +33,7 @@ const reducer = (oldState, action, params) => {
39
33
  newState.num *= newState.num;
40
34
  break;
41
35
  case 'RENAME':
42
- newState.name = params.name || 'no name given';
36
+ newState.name = payload.name || 'no name given';
43
37
  break;
44
38
  }
45
39
  return newState;
@@ -58,7 +52,7 @@ Store.dispatch({type: 'POW'}) // -> {num: 64, name: 'Federico'}
58
52
  Store.dispatch({type: 'INCREMENT'}) // -> {num: 65, name: 'Federico'}
59
53
  Store.dispatch({type: 'POW'}) // -> {num: 4225, name: 'Federico'}
60
54
  Store.dispatch({type: 'RENAME'}) // -> {num: 4225, name: 'no name given'}
61
- Store.dispatch({type: 'RENAME', name: 'Foo'}) // -> {num: 4225, name: 'Foo'}
55
+ Store.dispatch({type: 'RENAME', payload: {name: 'Foo'}}) // -> {num: 4225, name: 'Foo'}
62
56
  ...
63
57
  ```
64
58
  ## Time travel
@@ -74,9 +68,9 @@ Creates a store given one reducer function
74
68
  const Store = Ridof.getStore(reducer, [initialStatus || {}]);
75
69
  ```
76
70
  the reducer function will receive the following:
77
- - **state**: the current state
71
+ - **oldState**: the current state
78
72
  - **action**: the action label
79
- - **params**: all passed to ‘dispatch’ but the type
73
+ - **payload**: the ones passed to ‘dispatch’
80
74
 
81
75
  Return the current state
82
76
  ``` js
@@ -97,20 +91,10 @@ Dispatch an action:
97
91
  ``` js
98
92
  Store.dispatch({
99
93
  type:'INCREMENT', // needs at least a type field
100
- all: 'others',
101
- params: 'follows'
94
+ payload: {}
102
95
  });
103
96
  ```
104
- a second `Boolean` parameter is accepted by the `dispatch`; when `true` it allows to add (after reducer action on the state) the parameters passed that are missing on the state:
105
- ``` js
106
- // { num: 0 }
107
- Store.dispatch({
108
- type:'INCREMENT', // this action only increments `num`
109
- all: 'others',
110
- params: 'follows'
111
- }, true); // it is passed so missing ones will be added
112
- // { num: 0, all: 'others', params: 'follows'}
113
- ```
97
+
114
98
  -----
115
99
  Move in the states:
116
100
  ``` js
@@ -132,18 +116,18 @@ Store.reset();
132
116
  Combine two or more reducers
133
117
  ``` js
134
118
  var reducer = Ridof.combine({
135
- mods: (state = [], action, params) => {
136
- const newState = [...state];
119
+ mods: (oldState = [], action, payload) => {
120
+ const newState = [...oldState];
137
121
  switch (action) {
138
- case 'ADDMOD': newState.push(params.name); break;
122
+ case 'ADDMOD': newState.push(payload.name); break;
139
123
  default:;
140
124
  }
141
125
  return newState;
142
126
  },
143
- plugins: (state = [], action, params) => {
144
- const newState = [...state];
127
+ plugins: (oldState = [], action, payload) => {
128
+ const newState = [...oldState];
145
129
  switch (action) {
146
- case 'ADDPLUGIN': newState.push(params.name); break;
130
+ case 'ADDPLUGIN': newState.push(payload.name); break;
147
131
  default:;
148
132
  }
149
133
  return newState;
@@ -161,9 +145,22 @@ store.subscribe((oldState, newState, action) => {
161
145
  */
162
146
  }
163
147
  });
164
- store.dispatch({ type: 'ADDPLUGIN', name: 'myplugin' });
165
- store.dispatch({ type: 'ADDMOD', name: 'mymod1' });
166
- store.dispatch({ type: 'ADDMOD', name: 'mymod2' });
148
+ store.dispatch({
149
+ type: 'ADDPLUGIN',
150
+ payload: { name: 'myplugin' }
151
+ });
152
+ store.dispatch({
153
+ type: 'ADDMOD',
154
+ payload: {
155
+ name: 'mymod1'
156
+ }
157
+ });
158
+ store.dispatch({
159
+ type: 'ADDMOD',
160
+ payload: {
161
+ name: 'mymod2'
162
+ }
163
+ });
167
164
  store.dispatch({ type: 'END' });
168
165
  ```
169
166
  -----
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.2
11
+ v. 1.3.4
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 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!",
16
+ this.tags=[t],this.index=0}function r(e,r,i){t(e,n.REDUCERS_FUNCTION),this.reducer=e,this.state=void 0!==r?r:this.reducer(),this.states=[this.state],this.config=i,
17
+ this.tagsManager=new s("INITIAL",this.config),this.currentIndex=0,this.subscribers=[]}function i(t){const e={};var s;for(s in t)e[s]=t[s]();return function(r,i,n){r=r||e;var o=Object.assign({},r)
18
+ ;for(s in t)o[s]=t[s](o[s],i,n);return o}}const n={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,s){var i=this.getCurrent();return!this.activeCheck||this.config(i,t,e,s)},
20
+ ;return s.prototype.getCurrent=function(){return this.tags[this.index]},s.prototype.canMoveTo=function(t,e,s){var r=this.getCurrent();return!this.activeCheck||this.config(r,t,e,s)},
21
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)}),
22
+ r.prototype.pushState=function(t,e){var s=this.states[this.currentIndex];JSON.stringify(s)!==JSON.stringify(t)&&(this.subscribers.forEach(function(r){r(s,t,e)}),
23
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}}()
24
+ this.states[this.currentIndex]=t)},r.prototype.getState=function(){return this.states[this.currentIndex]},r.prototype.dispatch=function(t){if(!("type"in t))throw new Error(n.ACTION_TYPE)
25
+ ;if(!this.tagsManager.canMoveTo(t.type,this.state,t))throw new Error(n.UNAUTHORIZED_STATECHANGE);var s=t.type,r=t.payload||{},i=this.reducer(this.states[this.currentIndex],s,r)
26
+ ;return e(i,n.REDUCERS_RETURN),delete i.type,this.pushState(i,s),this},r.prototype.subscribe=function(e){t(e,n.SUBSCRIBERS_FUNCTION);var s,r=this;return this.subscribers.push(e),
27
+ s=this.subscribers.length-1,function(){r.subscribers=r.subscribers.slice(0,s).concat(r.subscribers.slice(s+1))}},r.prototype.replaceReducer=function(e){t(e,n.REDUCERS_FUNCTION),this.reducer=e},
28
+ r.prototype.reset=function(){var t=this.states[0];this.states=[t],this.currentIndex=0,this.tagsManager.reset(),this.subscribers=[]},r.prototype.move=function(t){if(0===t)return this
29
+ ;var e=this,s=this.currentIndex+t,r=this.getState(),i=t>0?"FORWARD":"BACKWARD",n=s>-1&&s<this.states.length;return this.currentIndex=n?s:this.currentIndex,n&&this.subscribers.forEach(function(t){
30
+ t(r,e.getState(),{type:["TIMETRAVEL_",i].join("")})}),this},{combine:i,getStore:function(t,e,s){return new r(t,e,s)},isStore:function(t){return t instanceof r},ERRORS:n}}()
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.2",
3
+ "version": "1.3.4",
4
4
  "description": "Simple isomorphic state manager",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {