Compare commits

...

8 Commits

Author SHA1 Message Date
9413c5bcdc 1.0.19 2020-11-29 23:31:32 +00:00
1d5fb320f4 fix(core): update 2020-11-29 23:31:31 +00:00
69e905ad76 1.0.18 2020-11-29 23:28:45 +00:00
7b9ed9ee78 fix(core): update 2020-11-29 23:28:44 +00:00
f884807f33 1.0.17 2020-07-27 18:17:53 +00:00
f167800113 fix(core): update 2020-07-27 18:17:52 +00:00
c549d06a6b 1.0.16 2020-05-27 20:47:16 +00:00
23061c86eb fix(core): update 2020-05-27 20:47:15 +00:00
6 changed files with 1921 additions and 79 deletions

1948
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartstate",
"version": "1.0.15",
"version": "1.0.19",
"private": false,
"description": "a package that handles state in a good way",
"main": "dist_ts/index.js",
@ -9,20 +9,22 @@
"license": "MIT",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild)",
"build": "(tsbuild && tsbundle npm)",
"format": "(gitzone format)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.24",
"@gitzone/tsbundle": "^1.0.69",
"@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.2.1",
"@types/node": "^14.0.1",
"@types/node": "^14.0.5",
"tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@pushrocks/lik": "^4.0.0",
"@pushrocks/lik": "^4.0.12",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrx": "^2.0.15",
"rxjs": "^6.5.5"
},
"files": [

View File

@ -20,7 +20,6 @@ a package that handles state in a good way
Use TypeScript for best in class intellisense.
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)

View File

@ -5,21 +5,22 @@ import { StatePart } from './smartstate.classes.statepart';
* Smartstate takes care of providing state
*/
export class Smartstate<StatePartNameType> {
public statePartMap: { [key: string]: StatePart<StatePartNameType, any> } = {};
public statePartMap: { [key: string]: StatePart<StatePartNameType, unknown> } = {};
constructor() {}
public getStatePart<PayloadType>(
statePartNameArg: StatePartNameType,
initialArg?: PayloadType
statePartNameArg: string & StatePartNameType,
initialArg?: PayloadType,
initMode?: 'soft' | 'mandatory'
): StatePart<StatePartNameType, PayloadType> {
if (this.statePartMap[statePartNameArg as any]) {
if (initialArg) {
if (initialArg && (!initMode || initMode !== 'soft')) {
throw new Error(
`${statePartNameArg} already exists, yet you try to set an initial state again`
);
}
return this.statePartMap[statePartNameArg as any];
return this.statePartMap[statePartNameArg] as StatePart<StatePartNameType, PayloadType>;
} else {
if (!initialArg) {
throw new Error(
@ -44,9 +45,4 @@ export class Smartstate<StatePartNameType> {
this.statePartMap[statePartName as any] = newState;
return newState;
}
/**
* dispatches an action on the main level
*/
public dispatch() {}
}

View File

@ -1,13 +1,9 @@
import * as plugins from './smartstate.plugins';
import { Observable, Subject } from 'rxjs';
import { startWith, takeUntil, map } from 'rxjs/operators';
import { StateAction, IActionDef } from './smartstate.classes.stateaction';
export class StatePart<TStatePartName, TStatePayload> {
public name: TStatePartName;
public state = new Subject<TStatePayload>();
public state = new plugins.smartrx.rxjs.Subject<TStatePayload>();
public stateStore: TStatePayload;
constructor(nameArg: TStatePartName) {
@ -40,14 +36,16 @@ export class StatePart<TStatePartName, TStatePayload> {
/**
* selects a state or a substate
*/
public select<T = TStatePayload>(selectorFn?: (state: TStatePayload) => T): Observable<T> {
public select<T = TStatePayload>(
selectorFn?: (state: TStatePayload) => T
): plugins.smartrx.rxjs.Observable<T> {
if (!selectorFn) {
selectorFn = (state: TStatePayload) => <T>(<any>state);
}
const mapped = this.state.pipe(
startWith(this.getState()),
map(stateArg => {
plugins.smartrx.rxjs.ops.startWith(this.getState()),
plugins.smartrx.rxjs.ops.map(stateArg => {
try {
return selectorFn(stateArg);
} catch (e) {

View File

@ -1,11 +1,4 @@
import { Observable } from 'rxjs';
const rxjsPart = {
Observable
};
export { rxjsPart };
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrx from '@pushrocks/smartrx';
export { smartpromise };
export { smartpromise, smartrx };