Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
f90a61b38b | |||
71af6f08f3 | |||
01e938274d | |||
c5a3eb63ad | |||
a4d43456d7 |
@ -34,31 +34,6 @@ snyk:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
sast:
|
||||
stage: security
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
||||
--volume "$PWD:/code"
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
||||
artifacts:
|
||||
reports:
|
||||
sast: gl-sast-report.json
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartstate",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.10",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartstate",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.10",
|
||||
"private": false,
|
||||
"description": "a package that handles state in a good way",
|
||||
"main": "dist/index.js",
|
||||
|
14
test/test.ts
14
test/test.ts
@ -30,12 +30,20 @@ tap.test('should create a new StatePart', async () => {
|
||||
|
||||
tap.test('should select something', async () => {
|
||||
testStatePart
|
||||
.select(state => state.deep)
|
||||
.select(state => state.deep.hi)
|
||||
.subscribe(substate => {
|
||||
console.log(substate);
|
||||
expect(substate).to.equal(2);
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should dispatch a state action', async () => {});
|
||||
tap.test('should dispatch a state action', async () => {
|
||||
const addFavourite = testStatePart.createAction<string>(async (statePart, payload) => {
|
||||
const currentState = statePart.getState();
|
||||
currentState.currentFavorites.push(payload);
|
||||
return currentState;
|
||||
});
|
||||
await testStatePart.dispatchAction(addFavourite, 'my favourite things');
|
||||
expect(testStatePart.getState().currentFavorites).to.include('my favourite things');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -1,8 +1,13 @@
|
||||
import * as plugins from './smartstate.plugins';
|
||||
import { StatePart } from './smartstate.classes.statepart';
|
||||
|
||||
export interface IActionDef<TStateType, TActionPayloadType> {
|
||||
(stateArg: StatePart<any, TStateType>, actionPayload: TActionPayloadType): Promise<TStateType>;
|
||||
}
|
||||
|
||||
/**
|
||||
* an actionmodifier for the state
|
||||
*/
|
||||
export class StateAction<StatePayload> {
|
||||
constructor(public actionDef: (stateArg: StatePayload) => StatePayload) {}
|
||||
export class StateAction<TStateType, TActionPayloadType> {
|
||||
constructor(public actionDef: IActionDef<TStateType, TActionPayloadType>) {}
|
||||
}
|
||||
|
@ -3,21 +3,21 @@ import * as plugins from './smartstate.plugins';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { startWith, takeUntil, map } from 'rxjs/operators';
|
||||
|
||||
import { StateAction } from './smartstate.classes.stateaction';
|
||||
import { StateAction, IActionDef } from './smartstate.classes.stateaction';
|
||||
|
||||
export class StatePart<StatePartNameType, PayloadType> {
|
||||
name: StatePartNameType;
|
||||
state = new Subject<PayloadType>();
|
||||
stateStore: PayloadType;
|
||||
export class StatePart<TStatePartName, TStatePayload> {
|
||||
name: TStatePartName;
|
||||
state = new Subject<TStatePayload>();
|
||||
stateStore: TStatePayload;
|
||||
|
||||
constructor(nameArg: StatePartNameType) {
|
||||
constructor(nameArg: TStatePartName) {
|
||||
this.name = nameArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the state from the state store
|
||||
*/
|
||||
getState(): PayloadType {
|
||||
getState(): TStatePayload {
|
||||
return this.stateStore;
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ export class StatePart<StatePartNameType, PayloadType> {
|
||||
* sets the stateStore to the new state
|
||||
* @param newStateArg
|
||||
*/
|
||||
setState(newStateArg: PayloadType) {
|
||||
setState(newStateArg: TStatePayload) {
|
||||
this.stateStore = newStateArg;
|
||||
this.notifyChange();
|
||||
}
|
||||
@ -40,9 +40,9 @@ export class StatePart<StatePartNameType, PayloadType> {
|
||||
/**
|
||||
* selects a state or a substate
|
||||
*/
|
||||
select<T = PayloadType>(selectorFn?: (state: PayloadType) => T): Observable<T> {
|
||||
select<T = TStatePayload>(selectorFn?: (state: TStatePayload) => T): Observable<T> {
|
||||
if (!selectorFn) {
|
||||
selectorFn = (state: PayloadType) => <T>(<any>state);
|
||||
selectorFn = (state: TStatePayload) => <T>(<any>state);
|
||||
}
|
||||
|
||||
const mapped = this.state.pipe(
|
||||
@ -53,11 +53,20 @@ export class StatePart<StatePartNameType, PayloadType> {
|
||||
return mapped;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates an action capable of modifying the state
|
||||
*/
|
||||
createAction<TActionPayload>(
|
||||
actionDef: IActionDef<TStatePayload, TActionPayload>
|
||||
): StateAction<TStatePayload, TActionPayload> {
|
||||
return new StateAction(actionDef);
|
||||
}
|
||||
|
||||
/**
|
||||
* dispatches an action on the statepart level
|
||||
*/
|
||||
async dispatch(stateAction: StateAction<PayloadType>) {
|
||||
const newState = stateAction.actionDef(this.getState());
|
||||
async dispatchAction<T>(stateAction: StateAction<TStatePayload, T>, actionPayload: T) {
|
||||
const newState = await stateAction.actionDef(this, actionPayload);
|
||||
this.setState(newState);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user