Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
2da2a43a09 | |||
f7887a6663 | |||
be505ee915 | |||
9584f403b1 | |||
993a100eae | |||
29f0307ef8 |
@ -12,6 +12,9 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
@ -19,23 +22,36 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
audit:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm audit --audit-level=high
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -50,9 +66,7 @@ testStable:
|
|||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
@ -63,9 +77,7 @@ testBuild:
|
|||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@ -85,6 +97,8 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"projectType": {
|
"projectType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["website", "element", "service", "npm"]
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartstate",
|
"gitrepo": "smartstate",
|
||||||
"shortDescription": "a package that handles state in a good way",
|
"description": "a package that handles state in a good way",
|
||||||
"npmPackagename": "@pushrocks/smartstate",
|
"npmPackagename": "@pushrocks/smartstate",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
26530
package-lock.json
generated
26530
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartstate",
|
"name": "@pushrocks/smartstate",
|
||||||
"version": "1.0.19",
|
"version": "1.0.22",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a package that handles state in a good way",
|
"description": "a package that handles state in a good way",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -9,23 +9,24 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild && tsbundle npm)",
|
"build": "(tsbuild --web && tsbundle npm)"
|
||||||
"format": "(gitzone format)"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.24",
|
"@gitzone/tsbuild": "^2.1.29",
|
||||||
"@gitzone/tsbundle": "^1.0.69",
|
"@gitzone/tsbundle": "^1.0.89",
|
||||||
"@gitzone/tstest": "^1.0.28",
|
"@gitzone/tstest": "^1.0.60",
|
||||||
"@pushrocks/tapbundle": "^3.2.1",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^14.0.5",
|
"@types/node": "^17.0.10",
|
||||||
"tslint": "^6.1.2",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^4.0.12",
|
"@pushrocks/isohash": "^1.0.2",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/lik": "^5.0.1",
|
||||||
"@pushrocks/smartrx": "^2.0.15",
|
"@pushrocks/smartjson": "^4.0.6",
|
||||||
"rxjs": "^6.5.5"
|
"@pushrocks/smartobject": "^1.0.6",
|
||||||
|
"@pushrocks/smartpromise": "^3.1.6",
|
||||||
|
"@pushrocks/smartrx": "^2.0.20"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
@ -38,5 +39,8 @@
|
|||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
21
readme.md
21
readme.md
@ -8,13 +8,20 @@ a package that handles state in a good way
|
|||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartstate/)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartstate/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[](https://gitlab.com/pushrocks/smartstate/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartstate/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartstate)
|
-- | --
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartstate)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://prettier.io/)
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@ tap.test('should create a new StatePart', async () => {
|
|||||||
testStatePart = testState.getStatePart<TStatePartPayload>('testStatePart', {
|
testStatePart = testState.getStatePart<TStatePartPayload>('testStatePart', {
|
||||||
currentFavorites: [],
|
currentFavorites: [],
|
||||||
deep: {
|
deep: {
|
||||||
hi: 2
|
hi: 2,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
expect(testStatePart).to.be.instanceOf(smartstate.StatePart);
|
expect(testStatePart).to.be.instanceOf(smartstate.StatePart);
|
||||||
console.log(testStatePart);
|
console.log(testStatePart);
|
||||||
@ -30,13 +30,13 @@ tap.test('should create a new StatePart', async () => {
|
|||||||
|
|
||||||
tap.test('should select something', async () => {
|
tap.test('should select something', async () => {
|
||||||
testStatePart
|
testStatePart
|
||||||
.select(state => state.deep.hi)
|
.select((state) => state.deep.hi)
|
||||||
.subscribe(substate => {
|
.subscribe((substate) => {
|
||||||
expect(substate).to.equal(2);
|
expect(substate).to.equal(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should dispatch a state action', async tools => {
|
tap.test('should dispatch a state action', async (tools) => {
|
||||||
const done = tools.defer();
|
const done = tools.defer();
|
||||||
const addFavourite = testStatePart.createAction<string>(async (statePart, payload) => {
|
const addFavourite = testStatePart.createAction<string>(async (statePart, payload) => {
|
||||||
const currentState = statePart.getState();
|
const currentState = statePart.getState();
|
||||||
@ -44,7 +44,7 @@ tap.test('should dispatch a state action', async tools => {
|
|||||||
return currentState;
|
return currentState;
|
||||||
});
|
});
|
||||||
testStatePart
|
testStatePart
|
||||||
.waitUntilPresent(state => {
|
.waitUntilPresent((state) => {
|
||||||
return state.currentFavorites[0];
|
return state.currentFavorites[0];
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
@ -1,5 +1,3 @@
|
|||||||
export * from './smartstate.classes.smartstate';
|
export * from './smartstate.classes.smartstate';
|
||||||
export * from './smartstate.classes.statepart';
|
export * from './smartstate.classes.statepart';
|
||||||
export * from './smartstate.classes.statecollection';
|
|
||||||
export * from './smartstate.classes.stateaction';
|
export * from './smartstate.classes.stateaction';
|
||||||
export * from './smartstate.classes.stateobservable';
|
|
||||||
|
@ -5,17 +5,26 @@ import { StatePart } from './smartstate.classes.statepart';
|
|||||||
* Smartstate takes care of providing state
|
* Smartstate takes care of providing state
|
||||||
*/
|
*/
|
||||||
export class Smartstate<StatePartNameType> {
|
export class Smartstate<StatePartNameType> {
|
||||||
public statePartMap: { [key: string]: StatePart<StatePartNameType, unknown> } = {};
|
public statePartMap: { [key: string]: StatePart<StatePartNameType, any> } = {};
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows getting and initializing a new statepart
|
||||||
|
* initMode === 'soft' it will allow existing stateparts
|
||||||
|
* initMode === 'mandatory' will fail if there is an exiting statepart
|
||||||
|
* initMode === 'force' will overwrite any existing statepart
|
||||||
|
* @param statePartNameArg
|
||||||
|
* @param initialArg
|
||||||
|
* @param initMode
|
||||||
|
*/
|
||||||
public getStatePart<PayloadType>(
|
public getStatePart<PayloadType>(
|
||||||
statePartNameArg: string & StatePartNameType,
|
statePartNameArg: string & StatePartNameType,
|
||||||
initialArg?: PayloadType,
|
initialArg?: PayloadType,
|
||||||
initMode?: 'soft' | 'mandatory'
|
initMode?: 'soft' | 'mandatory' | 'force'
|
||||||
): StatePart<StatePartNameType, PayloadType> {
|
): StatePart<StatePartNameType, PayloadType> {
|
||||||
if (this.statePartMap[statePartNameArg as any]) {
|
if (this.statePartMap[statePartNameArg as any]) {
|
||||||
if (initialArg && (!initMode || initMode !== 'soft')) {
|
if (initialArg && (!initMode || initMode !== 'soft')) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`${statePartNameArg} already exists, yet you try to set an initial state again`
|
`${statePartNameArg} already exists, yet you try to set an initial state again`
|
||||||
);
|
);
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
import * as plugins from './smartstate.plugins';
|
|
||||||
import { StatePart } from './smartstate.classes.statepart';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A StatePartCollection is a collection of StateParts.
|
|
||||||
* It can be used for expressing interest in a certain set of StateParts.
|
|
||||||
*/
|
|
||||||
export class StatePartCollection<StatePartNameType, T> extends StatePart<StatePartNameType, T> {
|
|
||||||
constructor(nameArg: StatePartNameType) {
|
|
||||||
super(nameArg);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
import * as plugins from './smartstate.plugins';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* State observable observes a StatePart and notifies everyone interested
|
|
||||||
*/
|
|
||||||
export class StateObservable {
|
|
||||||
/**
|
|
||||||
* creates an observable from a StateCollection
|
|
||||||
*/
|
|
||||||
public static fromStatePartCollection(filterArg?: () => any) {}
|
|
||||||
|
|
||||||
constructor() {}
|
|
||||||
}
|
|
@ -30,8 +30,17 @@ export class StatePart<TStatePartName, TStatePayload> {
|
|||||||
* notifies of a change on the state
|
* notifies of a change on the state
|
||||||
*/
|
*/
|
||||||
public notifyChange() {
|
public notifyChange() {
|
||||||
|
const createStateHash = (stateArg: any) => {
|
||||||
|
return plugins.isohash.sha256FromString(plugins.smartjson.stringify(stateArg));
|
||||||
|
};
|
||||||
|
if (this.stateStore && this.lastStateNotificationPayloadHash && createStateHash(this.stateStore) === createStateHash(this.lastStateNotificationPayloadHash)) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
this.lastStateNotificationPayloadHash = this.stateStore;
|
||||||
|
}
|
||||||
this.state.next(this.stateStore);
|
this.state.next(this.stateStore);
|
||||||
}
|
}
|
||||||
|
private lastStateNotificationPayloadHash: any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* selects a state or a substate
|
* selects a state or a substate
|
||||||
@ -45,7 +54,7 @@ export class StatePart<TStatePartName, TStatePayload> {
|
|||||||
|
|
||||||
const mapped = this.state.pipe(
|
const mapped = this.state.pipe(
|
||||||
plugins.smartrx.rxjs.ops.startWith(this.getState()),
|
plugins.smartrx.rxjs.ops.startWith(this.getState()),
|
||||||
plugins.smartrx.rxjs.ops.map(stateArg => {
|
plugins.smartrx.rxjs.ops.map((stateArg) => {
|
||||||
try {
|
try {
|
||||||
return selectorFn(stateArg);
|
return selectorFn(stateArg);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -83,7 +92,7 @@ export class StatePart<TStatePartName, TStatePayload> {
|
|||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const done = plugins.smartpromise.defer<T>();
|
const done = plugins.smartpromise.defer<T>();
|
||||||
const selectedObservable = this.select(selectorFn);
|
const selectedObservable = this.select(selectorFn);
|
||||||
const subscription = selectedObservable.subscribe(async value => {
|
const subscription = selectedObservable.subscribe(async (value) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
done.resolve(value);
|
done.resolve(value);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
import * as isohash from '@pushrocks/isohash';
|
||||||
|
import * as smartjson from '@pushrocks/smartjson';
|
||||||
|
import * as smartobject from '@pushrocks/smartobject';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartrx from '@pushrocks/smartrx';
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
|
|
||||||
export { smartpromise, smartrx };
|
export { isohash, smartjson, smartobject, smartpromise, smartrx };
|
||||||
|
Reference in New Issue
Block a user