ridof 1.3.3 → 1.3.5

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.
@@ -0,0 +1,33 @@
1
+ name: Run tests and upload coverage
2
+
3
+ on:
4
+ push
5
+
6
+ jobs:
7
+ test:
8
+ name: Run tests and collect coverage
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - name: Checkout
12
+ uses: actions/checkout@v4
13
+ with:
14
+ fetch-depth: 2
15
+
16
+ - name: Set up Node
17
+ uses: actions/setup-node@v4
18
+
19
+ - name: Install dependencies
20
+ run: npm install
21
+
22
+ - name: Build
23
+ run: npm run build
24
+
25
+ - name: Run tests
26
+ run: npm run cover
27
+
28
+ - name: Upload results to Codecov
29
+ uses: codecov/codecov-action@v5
30
+ with:
31
+ token: ${{ secrets.CODECOV_TOKEN }}
32
+ files: ./tests/coverage/lcov.info
33
+ fail_ci_if_error: true
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
1
  ### Changelog
2
2
 
3
- **1.2.7**: update vulnerable deps
3
+ **1.3.5**: small migrations
4
+ - coveralls -> codecov
5
+ - mocha -> jest
6
+ **1.3.4**: fix major problem due to previous dependencies update.
7
+ **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) 2024 <Federico Ghedina <fedeghe@gmail.com>>
3
+ Copyright (c) 2026 <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,4 +1,4 @@
1
- [![Coverage Status](https://coveralls.io/repos/github/fedeghe/ridof/badge.svg?branch=master)](https://coveralls.io/github/fedeghe/ridof?branch=master)
1
+ [![codecov](https://codecov.io/gh/fedeghe/ridof/graph/badge.svg?token=WNRdYZb9Kn)](https://codecov.io/gh/fedeghe/ridof)
2
2
 
3
3
  # Ridof
4
4
 
@@ -20,7 +20,7 @@ const initialState = {
20
20
  }
21
21
  // The reducer function
22
22
  // params holds all the values passed to dispatch but the type
23
- const reducer = (oldState, action, params) => {
23
+ const reducer = (oldState, action, payload) => {
24
24
  const newState = Object.assign({}, oldState)
25
25
  switch (action) {
26
26
  case 'INCREMENT':
@@ -33,7 +33,7 @@ const reducer = (oldState, action, params) => {
33
33
  newState.num *= newState.num;
34
34
  break;
35
35
  case 'RENAME':
36
- newState.name = params.name || 'no name given';
36
+ newState.name = payload.name || 'no name given';
37
37
  break;
38
38
  }
39
39
  return newState;
@@ -52,7 +52,7 @@ Store.dispatch({type: 'POW'}) // -> {num: 64, name: 'Federico'}
52
52
  Store.dispatch({type: 'INCREMENT'}) // -> {num: 65, name: 'Federico'}
53
53
  Store.dispatch({type: 'POW'}) // -> {num: 4225, name: 'Federico'}
54
54
  Store.dispatch({type: 'RENAME'}) // -> {num: 4225, name: 'no name given'}
55
- Store.dispatch({type: 'RENAME', name: 'Foo'}) // -> {num: 4225, name: 'Foo'}
55
+ Store.dispatch({type: 'RENAME', payload: {name: 'Foo'}}) // -> {num: 4225, name: 'Foo'}
56
56
  ...
57
57
  ```
58
58
  ## Time travel
@@ -68,9 +68,9 @@ Creates a store given one reducer function
68
68
  const Store = Ridof.getStore(reducer, [initialStatus || {}]);
69
69
  ```
70
70
  the reducer function will receive the following:
71
- - **state**: the current state
71
+ - **oldState**: the current state
72
72
  - **action**: the action label
73
- - **params**: all passed to ‘dispatch’ but the type
73
+ - **payload**: the ones passed to ‘dispatch’
74
74
 
75
75
  Return the current state
76
76
  ``` js
@@ -91,20 +91,10 @@ Dispatch an action:
91
91
  ``` js
92
92
  Store.dispatch({
93
93
  type:'INCREMENT', // needs at least a type field
94
- all: 'others',
95
- params: 'follows'
94
+ payload: {}
96
95
  });
97
96
  ```
98
- 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:
99
- ``` js
100
- // { num: 0 }
101
- Store.dispatch({
102
- type:'INCREMENT', // this action only increments `num`
103
- all: 'others',
104
- params: 'follows'
105
- }, true); // it is passed so missing ones will be added
106
- // { num: 0, all: 'others', params: 'follows'}
107
- ```
97
+
108
98
  -----
109
99
  Move in the states:
110
100
  ``` js
@@ -126,18 +116,18 @@ Store.reset();
126
116
  Combine two or more reducers
127
117
  ``` js
128
118
  var reducer = Ridof.combine({
129
- mods: (state = [], action, params) => {
130
- const newState = [...state];
119
+ mods: (oldState = [], action, payload) => {
120
+ const newState = [...oldState];
131
121
  switch (action) {
132
- case 'ADDMOD': newState.push(params.name); break;
122
+ case 'ADDMOD': newState.push(payload.name); break;
133
123
  default:;
134
124
  }
135
125
  return newState;
136
126
  },
137
- plugins: (state = [], action, params) => {
138
- const newState = [...state];
127
+ plugins: (oldState = [], action, payload) => {
128
+ const newState = [...oldState];
139
129
  switch (action) {
140
- case 'ADDPLUGIN': newState.push(params.name); break;
130
+ case 'ADDPLUGIN': newState.push(payload.name); break;
141
131
  default:;
142
132
  }
143
133
  return newState;
@@ -155,9 +145,22 @@ store.subscribe((oldState, newState, action) => {
155
145
  */
156
146
  }
157
147
  });
158
- store.dispatch({ type: 'ADDPLUGIN', name: 'myplugin' });
159
- store.dispatch({ type: 'ADDMOD', name: 'mymod1' });
160
- 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
+ });
161
164
  store.dispatch({ type: 'END' });
162
165
  ```
163
166
  -----
@@ -167,10 +170,15 @@ Restrict state transitions
167
170
  From version 1.3.0 is possible to restrict the state transitions passing to `getStore` a third config parameter as a function:
168
171
 
169
172
  ``` js
170
- Ridof.getStore(reducer, initState, (currentTag, nextTag, state, action) => {
171
- // here tags are corresponds to action types
172
- // let's say we want only one plugin to be added
173
- if (currentTag === 'ADDPLUGIN' && nextTag === 'ADDPLUGIN') return false
174
- return true
175
- });
173
+ Ridof.getStore(
174
+ reducer,
175
+ initState,
176
+ (previousAction, currentAction, state, action) => {
177
+ // here tags are corresponds to action types
178
+ // let's say we want forbid a plugins to be added
179
+ // right after a mod was added
180
+ if (previousAction === 'ADDMOD' && currentAction === 'ADDPLUGIN') return false
181
+ return true
182
+ }
183
+ );
176
184
  ```
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.3
11
+ v. 1.3.5
12
12
 
13
- Size: ~3KB
13
+ Size: ~3.21KB
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,16 +1,28 @@
1
1
  {
2
2
  "name": "ridof",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "Simple isomorphic state manager",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
+ "dev": "malta source/buildev.json",
7
8
  "build": "malta source/build.json",
8
- "buildev": "malta source/buildev.json",
9
9
  "clean": "malta source/clean.json",
10
10
  "lint": "eslint --ignore-path .eslintignore .",
11
- "test": "mocha",
12
- "cover": "nyc yarn test && nyc report --reporter=html",
13
- "coveralls": "nyc yarn test && nyc report --reporter=text-lcov | coveralls"
11
+ "test": "jest",
12
+ "cover": "jest --coverage"
13
+ },
14
+ "jest": {
15
+ "testMatch": [
16
+ "<rootDir>/source/tests/**/*.js"
17
+ ],
18
+ "testPathIgnorePatterns": [
19
+ "/node_modules/",
20
+ "<rootDir>/source/tests/index.js",
21
+ "<rootDir>/source/tests/jest.setup.js"
22
+ ],
23
+ "setupFilesAfterEnv": [
24
+ "<rootDir>/source/tests/jest.setup.js"
25
+ ]
14
26
  },
15
27
  "repository": {
16
28
  "type": "git",
@@ -24,19 +36,11 @@
24
36
  },
25
37
  "homepage": "https://github.com/fedeghe/ridof#readme",
26
38
  "devDependencies": {
27
- "coveralls": "^3.0.9",
28
39
  "eslint": "^7.8.1",
29
- "eslint-config-standard": "^14.1.1",
30
- "eslint-plugin-import": "^2.20.1",
31
- "eslint-plugin-node": "^11.0.0",
32
- "eslint-plugin-promise": "^4.2.1",
33
- "eslint-plugin-standard": "^4.0.1",
34
- "malta": "4.1.17",
40
+ "jest": "^30.2.0",
41
+ "malta": "^4.1.17",
35
42
  "malta-header-comment": "^1.0.5",
36
- "malta-js-uglify": "^1.0.3",
37
- "malta-mocha": "^1.0.17",
38
- "mocha": "^8.1.3",
39
- "mocha-lcov-reporter": "^1.3.0",
40
- "nyc": "^15.0.0"
43
+ "malta-jest": "^0.0.2",
44
+ "malta-js-uglify": "^1.0.3"
41
45
  }
42
46
  }