@fedeghe/pangjs 0.0.9 → 0.0.11
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/.github/workflows/codecov.yml +31 -0
- package/.yarn/install-state.gz +0 -0
- package/README.md +2 -2
- package/dist/index.js +18 -17
- package/package.json +3 -12
- package/.coveralls.yml +0 -2
- package/.travis.yml +0 -7
|
@@ -0,0 +1,31 @@
|
|
|
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 }}
|
|
Binary file
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# PANGjs (0.0.
|
|
1
|
+
# PANGjs (0.0.11)
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
|
-
[](https://codecov.io/gh/fedeghe/pangjs)
|
|
6
6
|
|
|
7
7
|
# Simple asynchronous state manager
|
|
8
8
|
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/*
|
|
3
3
|
PANGjs
|
|
4
|
-
v. 0.0.
|
|
4
|
+
v. 0.0.11
|
|
5
5
|
|
|
6
|
-
Size: ~3.
|
|
6
|
+
Size: ~3.93KB
|
|
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
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
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="
|
|
12
|
-
var n={REDUCERS_FUNCTION:"[ERROR] Reducer must be a function!",REDUCERS_RETURN:"[ERROR] Reducer should return a promise!",
|
|
13
|
-
|
|
14
|
-
MOVE_TO_NUMBER:"[ERROR] Move requires a number!"};i.prototype.top=function(t){
|
|
15
|
-
t(e,n.SUBSCRIBERS_FUNCTION);var s,i=this;return this.subscribers.push(e),
|
|
16
|
-
var s=this.stagedStates.slice(0,this.stagedIndex+1);return s.push(t),
|
|
17
|
-
|
|
18
|
-
}).forEach(function(e){e(t)})},i.prototype.reset=function(){this.index=0,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
if(!("type"in t))return Promise.reject(new Error(n.ACTION_TYPE))
|
|
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)
|
|
23
|
-
u.then(function(t){return i.HistoryManager.stage(t,s),s&&i.HistoryManager.emit(t),t})},r.prototype.dispatch=function(t){
|
|
24
|
-
;var e=this.HistoryManager.top(!0);return this.HistoryManager.emit(e),Promise.resolve(e)},r.prototype.subscribe=function(t){
|
|
25
|
-
if(s(t,n.MOVE_TO_NUMBER),
|
|
11
|
+
this.config=r||{},this.config.check=this.config.check||function(){return!0},t(this.config.check,n.REDUCERS_FUNCTION),this.previousAction="pIG-pANG",
|
|
12
|
+
this.HistoryManager=new i(this.initState,this.config)}var n={REDUCERS_FUNCTION:"[ERROR] Reducer must be a function!",REDUCERS_RETURN:"[ERROR] Reducer should return a promise!",
|
|
13
|
+
REDUCERS_ASYNC:"[ERROR] Reducer should be asynchronous!",SUBSCRIBERS_FUNCTION:"[ERROR] Subscribers must be a functions!",ACTION_TYPE:"[ERROR] Actions needs a type!",
|
|
14
|
+
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.subscribe=function(e){t(e,n.SUBSCRIBERS_FUNCTION);var s,i=this;return this.subscribers.push(e),
|
|
16
|
+
s=this.subscribers.length-1,function(){i.subscribers[s]=null}},i.prototype.stage=function(t,e){var s=this.stagedStates.slice(0,this.stagedIndex+1);return s.push(t),
|
|
17
|
+
this.maxElements&&s.length>this.maxElements?s.shift():this.stagedIndex++,this.stagedStates=Array.from(s),e&&this.sync(),this},i.prototype.sync=function(){this.states=Array.from(this.stagedStates),
|
|
18
|
+
this.index=this.stagedIndex},i.prototype.emit=function(t){this.subscribers.filter(function(t){return Boolean(t)}).forEach(function(e){e(t)})},i.prototype.reset=function(){this.index=0,
|
|
19
|
+
this.states=[this.initState],this.stagedIndex=0,this.stagedStates=[this.initState]};var o=function(){return Promise.resolve({})};return r.prototype.getState=function(t){
|
|
20
|
+
return this.HistoryManager.top(t)},r.prototype.unstage=function(){if(1===this.HistoryManager.maxElements)return this;this.HistoryManager.stagedIndex=this.HistoryManager.index,
|
|
21
|
+
this.HistoryManager.stagedStates=this.HistoryManager.states},r.prototype.stage=function(t,s){if(!("type"in t))return Promise.reject(new Error(n.ACTION_TYPE))
|
|
22
|
+
;var i=this,r=t.type,o=t.payload||{},a=this.getState(!0);if(!i.config.check(a,i.previousAction,r,o))return Promise.reject(new Error(n.UNAUTHORIZED_STATECHANGE));var u=this.reducer(a,r,o)
|
|
23
|
+
;return e(u,n.REDUCERS_RETURN),this.previousAction=r,u.then(function(t){return i.HistoryManager.stage(t,s),s&&i.HistoryManager.emit(t),t})},r.prototype.dispatch=function(t){
|
|
24
|
+
if(t)return this.stage(t,!0);this.HistoryManager.sync();var e=this.HistoryManager.top(!0);return this.HistoryManager.emit(e),Promise.resolve(e)},r.prototype.subscribe=function(t){
|
|
25
|
+
return this.HistoryManager.subscribe(t)},r.prototype.move=function(t){if(s(t,n.MOVE_TO_NUMBER),
|
|
26
|
+
1===this.HistoryManager.maxElements||this.HistoryManager.index!==this.HistoryManager.stagedIndex||void 0===t||0===t)return this
|
|
26
27
|
;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
28
|
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
29
|
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){
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedeghe/pangjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"author": "fedeghe <fedeghe@gmail.com>",
|
|
6
6
|
"description": "Lightweight asynchronous state manager",
|
|
@@ -20,23 +20,14 @@
|
|
|
20
20
|
"dev": "malta source/buildev.json",
|
|
21
21
|
"test": "jest --coverage --rootDir=test",
|
|
22
22
|
"watch": "jest --watch --coverage --rootDir=test",
|
|
23
|
-
"cover": "jest --coverage --rootDir=test --coverageReporters=text"
|
|
24
|
-
"coveralls": "jest --coverage --rootDir=test --coverageReporters=text && cat ./test/coverage/lcov.info | coveralls"
|
|
23
|
+
"cover": "jest --coverage --rootDir=test --coverageReporters=text"
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|
|
27
|
-
"coveralls": "^3.1.1",
|
|
28
26
|
"eslint": "^9.17.0",
|
|
29
|
-
"eslint-config-standard": "^17.1.0",
|
|
30
|
-
"eslint-plugin-import": "^2.31.0",
|
|
31
|
-
"eslint-plugin-node": "^11.1.0",
|
|
32
|
-
"eslint-plugin-promise": "^7.2.1",
|
|
33
|
-
"eslint-plugin-standard": "^5.0.0",
|
|
34
27
|
"jest": "^29.7.0",
|
|
35
28
|
"malta": "^4.1.41",
|
|
36
29
|
"malta-header-comment": "^1.0.12",
|
|
37
|
-
"malta-js-uglify": "^1.0.13"
|
|
38
|
-
"mocha-lcov-reporter": "^1.3.0",
|
|
39
|
-
"nyc": "^17.1.0"
|
|
30
|
+
"malta-js-uglify": "^1.0.13"
|
|
40
31
|
},
|
|
41
32
|
"jest": {
|
|
42
33
|
"collectCoverage": true,
|
package/.coveralls.yml
DELETED