fix(core): update
This commit is contained in:
parent
3a119b50a2
commit
fe81307ca6
@ -18,7 +18,7 @@ tap.test('should create a new SmartState', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should create a new StatePart', async () => {
|
tap.test('should create a new StatePart', async () => {
|
||||||
testStatePart = testState.getStatePart<TStatePartPayload>('testStatePart', {
|
testStatePart = await testState.getStatePart<TStatePartPayload>('testStatePart', {
|
||||||
currentFavorites: [],
|
currentFavorites: [],
|
||||||
deep: {
|
deep: {
|
||||||
hi: 2,
|
hi: 2,
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartstate',
|
name: '@push.rocks/smartstate',
|
||||||
version: '2.0.13',
|
version: '2.0.14',
|
||||||
description: 'a package that handles state in a good way'
|
description: 'a package that handles state in a good way'
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,11 @@ export class Smartstate<StatePartNameType> {
|
|||||||
* @param initialArg
|
* @param initialArg
|
||||||
* @param initMode
|
* @param initMode
|
||||||
*/
|
*/
|
||||||
public getStatePart<PayloadType>(
|
public async getStatePart<PayloadType>(
|
||||||
statePartNameArg: string & StatePartNameType,
|
statePartNameArg: string & StatePartNameType,
|
||||||
initialArg?: PayloadType,
|
initialArg?: PayloadType,
|
||||||
initMode?: TInitMode
|
initMode?: TInitMode
|
||||||
): StatePart<StatePartNameType, PayloadType> {
|
): Promise<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(
|
||||||
@ -47,11 +47,11 @@ export class Smartstate<StatePartNameType> {
|
|||||||
* @param statePartName
|
* @param statePartName
|
||||||
* @param initialPayloadArg
|
* @param initialPayloadArg
|
||||||
*/
|
*/
|
||||||
private createStatePart<PayloadType>(
|
private async createStatePart<PayloadType>(
|
||||||
statePartName: StatePartNameType,
|
statePartName: StatePartNameType,
|
||||||
initialPayloadArg: PayloadType,
|
initialPayloadArg: PayloadType,
|
||||||
initMode?: TInitMode
|
initMode?: TInitMode
|
||||||
): StatePart<StatePartNameType, PayloadType> {
|
): Promise<StatePart<StatePartNameType, PayloadType>> {
|
||||||
const newState = new StatePart<StatePartNameType, PayloadType>(
|
const newState = new StatePart<StatePartNameType, PayloadType>(
|
||||||
statePartName,
|
statePartName,
|
||||||
initMode === 'persistent' ? {
|
initMode === 'persistent' ? {
|
||||||
@ -59,7 +59,11 @@ export class Smartstate<StatePartNameType> {
|
|||||||
storeName: statePartName as any,
|
storeName: statePartName as any,
|
||||||
} : null
|
} : null
|
||||||
);
|
);
|
||||||
newState.setState(initialPayloadArg);
|
const currentState = newState.getState();
|
||||||
|
await newState.setState({
|
||||||
|
...initialPayloadArg,
|
||||||
|
...currentState,
|
||||||
|
});
|
||||||
this.statePartMap[statePartName as any] = newState;
|
this.statePartMap[statePartName as any] = newState;
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user