@airma/core
Advanced tools
Comparing version 15.0.5 to 15.0.6
@@ -76,8 +76,8 @@ // src/libs/tools.ts | ||
const { dispatch, reducer } = connection; | ||
const next = reducer(result); | ||
connection.current = next; | ||
connection.current = reducer(result); | ||
connection.cacheState = result; | ||
if (typeof dispatch !== "function") { | ||
return result; | ||
} | ||
dispatch({ type, state: next.state }); | ||
dispatch({ type, state: result }); | ||
return result; | ||
@@ -94,3 +94,4 @@ }; | ||
dispatch: null, | ||
cacheMethods: {} | ||
cacheMethods: {}, | ||
cacheState: defaultState | ||
}; | ||
@@ -106,5 +107,2 @@ const actualReducer = function actualReducer2(state, action) { | ||
const value = connection.current[p]; | ||
if (p === "state") { | ||
return connection.current[p]; | ||
} | ||
if (typeof value === "function") { | ||
@@ -119,5 +117,6 @@ return rebuildDispatchMethod( | ||
}); | ||
actualReducer.update = function update(updateReducer, s) { | ||
actualReducer.update = function update(updateReducer) { | ||
const { cacheState } = connection; | ||
connection.reducer = updateReducer; | ||
connection.current = updateReducer(s); | ||
connection.current = updateReducer(cacheState); | ||
}; | ||
@@ -124,0 +123,0 @@ actualReducer.connect = function connect(dispatchCall) { |
@@ -15,12 +15,11 @@ export declare type Action = { | ||
export declare interface AirModelInstance<S> { | ||
state: S; | ||
export declare interface AirModelInstance { | ||
[key: string]: unknown; | ||
} | ||
declare type ValidInstance<S,T extends (AirModelInstance<S>)>={ | ||
declare type ValidInstance<S,T extends AirModelInstance>={ | ||
[K in keyof T]:T[K] extends ((...args: unknown[]) => S)?T[K]:T[K] extends ((...args: unknown[]) => unknown)?never:T[K] | ||
}; | ||
export declare type AirReducer<S, T extends AirModelInstance<S>> = ( | ||
export declare type AirReducer<S, T extends AirModelInstance> = ( | ||
state: S | ||
@@ -31,5 +30,5 @@ ) => ValidInstance<S,T>; | ||
export declare interface ReducerPadding<S = any, T extends AirModelInstance<S> = AirModelInstance<S>> { | ||
export declare interface ReducerPadding<S = any, T extends AirModelInstance = AirModelInstance> { | ||
agent: T; | ||
update:(reducer:AirReducer<S, T>,state:S)=>void; | ||
update:(reducer:AirReducer<S, T>)=>void; | ||
connect: (dispatch?: Dispatch) => void; | ||
@@ -39,3 +38,3 @@ disconnect: () => void; | ||
export declare type ActualReducer<S = any, T extends AirModelInstance<S> = any> = Reducer< | ||
export declare type ActualReducer<S = any, T extends AirModelInstance = any> = Reducer< | ||
S, | ||
@@ -46,5 +45,7 @@ Action | ||
export declare function createModel<S, T extends AirModelInstance<S>>( | ||
export type FirstParam<T extends (param:any)=>any>=T extends (param:infer P)=>any?P:never; | ||
export declare function createModel<S, T extends AirModelInstance>( | ||
reducer: AirReducer<S, T>, | ||
defaultState:ReturnType<typeof reducer>['state'] | ||
defaultState:FirstParam<typeof reducer> | ||
): ActualReducer<S, T>; | ||
@@ -51,0 +52,0 @@ |
@@ -7,3 +7,3 @@ { | ||
"name": "@airma/core", | ||
"version": "15.0.5", | ||
"version": "15.0.6", | ||
"description": "This is the core for agent-reducer and airma", | ||
@@ -10,0 +10,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7263
180