Compare commits

...

5 Commits

Author SHA1 Message Date
f90a61b38b 1.0.10 2019-03-22 12:03:58 +01:00
71af6f08f3 fix(core): update 2019-03-22 12:03:58 +01:00
01e938274d 1.0.9 2019-02-27 02:00:47 +01:00
c5a3eb63ad fix(core): update 2019-02-27 02:00:47 +01:00
a4d43456d7 update action generation 2019-02-26 18:09:38 +01:00
6 changed files with 41 additions and 44 deletions

View File

@ -34,31 +34,6 @@ snyk:
- docker - docker
- notpriv - 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 # test stage
# ==================== # ====================

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartstate", "name": "@pushrocks/smartstate",
"version": "1.0.8", "version": "1.0.10",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartstate", "name": "@pushrocks/smartstate",
"version": "1.0.8", "version": "1.0.10",
"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/index.js", "main": "dist/index.js",

View File

@ -30,12 +30,20 @@ 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) .select(state => state.deep.hi)
.subscribe(substate => { .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(); tap.start();

View File

@ -1,8 +1,13 @@
import * as plugins from './smartstate.plugins'; 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 * an actionmodifier for the state
*/ */
export class StateAction<StatePayload> { export class StateAction<TStateType, TActionPayloadType> {
constructor(public actionDef: (stateArg: StatePayload) => StatePayload) {} constructor(public actionDef: IActionDef<TStateType, TActionPayloadType>) {}
} }

View File

@ -3,21 +3,21 @@ import * as plugins from './smartstate.plugins';
import { Observable, Subject } from 'rxjs'; import { Observable, Subject } from 'rxjs';
import { startWith, takeUntil, map } from 'rxjs/operators'; 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> { export class StatePart<TStatePartName, TStatePayload> {
name: StatePartNameType; name: TStatePartName;
state = new Subject<PayloadType>(); state = new Subject<TStatePayload>();
stateStore: PayloadType; stateStore: TStatePayload;
constructor(nameArg: StatePartNameType) { constructor(nameArg: TStatePartName) {
this.name = nameArg; this.name = nameArg;
} }
/** /**
* gets the state from the state store * gets the state from the state store
*/ */
getState(): PayloadType { getState(): TStatePayload {
return this.stateStore; return this.stateStore;
} }
@ -25,7 +25,7 @@ export class StatePart<StatePartNameType, PayloadType> {
* sets the stateStore to the new state * sets the stateStore to the new state
* @param newStateArg * @param newStateArg
*/ */
setState(newStateArg: PayloadType) { setState(newStateArg: TStatePayload) {
this.stateStore = newStateArg; this.stateStore = newStateArg;
this.notifyChange(); this.notifyChange();
} }
@ -40,9 +40,9 @@ export class StatePart<StatePartNameType, PayloadType> {
/** /**
* selects a state or a substate * 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) { if (!selectorFn) {
selectorFn = (state: PayloadType) => <T>(<any>state); selectorFn = (state: TStatePayload) => <T>(<any>state);
} }
const mapped = this.state.pipe( const mapped = this.state.pipe(
@ -53,11 +53,20 @@ export class StatePart<StatePartNameType, PayloadType> {
return mapped; 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 * dispatches an action on the statepart level
*/ */
async dispatch(stateAction: StateAction<PayloadType>) { async dispatchAction<T>(stateAction: StateAction<TStatePayload, T>, actionPayload: T) {
const newState = stateAction.actionDef(this.getState()); const newState = await stateAction.actionDef(this, actionPayload);
this.setState(newState); this.setState(newState);
} }
} }