@equinor/fusion-observable
Advanced tools
Comparing version 8.3.0 to 8.3.1
@@ -19,3 +19,6 @@ export function createAction(type, prepareAction) { | ||
export const matchActionSuffix = (suffix) => new RegExp(`${actionSuffixDivider}${suffix}$`); | ||
export const actionBaseType = (action) => action.type.replace(matchActionSuffix('\\w+$'), ''); | ||
export const actionBaseType = (action) => { | ||
const type = typeof action === 'string' ? action : action.type; | ||
return type.replace(matchActionSuffix('\\w+$'), ''); | ||
}; | ||
export function getType(actionCreator) { | ||
@@ -22,0 +25,0 @@ return `${actionCreator}`; |
@@ -16,6 +16,9 @@ import { actionSuffixDivider, createAction, matchActionSuffix, } from './create-action'; | ||
} | ||
export const isRequestAction = (action) => !!action.type.match(/::request$/); | ||
export const isSuccessAction = (action) => !!action.type.match(matchActionSuffix('success')); | ||
export const isFailureAction = (action) => !!action.type.match(matchActionSuffix('failure')); | ||
export function isActionWithSuffix(action, suffix) { | ||
return !!action.type.match(matchActionSuffix(suffix)); | ||
} | ||
export const isRequestAction = (action) => isActionWithSuffix(action, 'request'); | ||
export const isSuccessAction = (action) => isActionWithSuffix(action, 'success'); | ||
export const isFailureAction = (action) => isActionWithSuffix(action, 'failure'); | ||
export const isCompleteAction = (action) => isSuccessAction(action) || isFailureAction(action); | ||
//# sourceMappingURL=create-async-action.js.map |
@@ -1,2 +0,2 @@ | ||
export const version = '8.3.0'; | ||
export const version = '8.3.1'; | ||
//# sourceMappingURL=version.js.map |
@@ -45,5 +45,5 @@ import { Action, PayloadAction } from './types/actions'; | ||
export declare const matchActionSuffix: (suffix: string) => RegExp; | ||
export declare const actionBaseType: (action: Action) => string; | ||
export declare const actionBaseType: (action: Action | string) => string; | ||
export declare function getType<T extends string>(actionCreator: PayloadActionCreator<any, T>): T; | ||
type IfPrepareActionMethodProvided<PA extends PrepareAction<any> | void, True, False> = PA extends (...args: any[]) => any ? True : False; | ||
export {}; |
import { PayloadActionCreator } from './create-action'; | ||
import type { PrepareAction } from './create-action'; | ||
import type { AnyAction } from './types'; | ||
import type { Action, ActionWithSuffix, AnyAction } from './types'; | ||
export declare function createAsyncAction<PA extends PrepareAction<any>, PA_Success extends PrepareAction<any>, T extends string>(type: T, request: PA, success: PA_Success): PayloadActionCreator<ReturnType<PA>['payload'], `${T}::request`, PA> & { | ||
@@ -11,5 +11,6 @@ success: PayloadActionCreator<ReturnType<PA_Success>['payload'], `${T}::success`, PA_Success>; | ||
}; | ||
export declare const isRequestAction: <A extends AnyAction>(action: A) => action is A; | ||
export declare const isSuccessAction: <A extends AnyAction>(action: A) => action is A; | ||
export declare const isFailureAction: <A extends AnyAction>(action: A) => action is A; | ||
export declare const isCompleteAction: <A extends AnyAction>(action: A) => action is A; | ||
export declare function isActionWithSuffix<A extends Action, Suffix extends string>(action: A, suffix: Suffix): action is ActionWithSuffix<A, Suffix>; | ||
export declare const isRequestAction: <A extends AnyAction>(action: A) => action is ActionWithSuffix<A, "request">; | ||
export declare const isSuccessAction: <A extends AnyAction>(action: A) => action is ActionWithSuffix<A, "success">; | ||
export declare const isFailureAction: <A extends AnyAction>(action: A) => action is ActionWithSuffix<A, "failure">; | ||
export declare const isCompleteAction: <A extends AnyAction>(action: A) => action is ActionWithSuffix<A, "failure" | "success">; |
import type { Draft } from 'immer'; | ||
import type { NoInfer, TypeGuard } from './types/ts-helpers'; | ||
import type { Action, AnyAction } from './types/actions'; | ||
import type { Action, ActionType, AnyAction } from './types/actions'; | ||
import type { ReducerWithInitialState } from './types/reducers'; | ||
@@ -19,14 +19,15 @@ type NotFunction<T = unknown> = T extends Function ? never : T; | ||
}; | ||
export declare function createReducer<S extends NotFunction, A extends Action = AnyAction>(initialState: S | (() => S), builderCallback: (builder: ActionReducerMapBuilder<S>) => void): ReducerWithInitialState<S, A>; | ||
export interface ActionReducerMapBuilder<State> { | ||
addCase<ActionCreator extends TypedActionCreator<string>>(actionCreator: ActionCreator, reducer: CaseReducer<State, ReturnType<ActionCreator>>): ActionReducerMapBuilder<State>; | ||
addCase<Type extends string, A extends Action<Type>>(type: Type, reducer: CaseReducer<State, A>): ActionReducerMapBuilder<State>; | ||
addMatcher<A>(matcher: TypeGuard<A> | ((action: AnyAction) => boolean), reducer: CaseReducer<State, A extends AnyAction ? A : A & AnyAction>): Omit<ActionReducerMapBuilder<State>, 'addCase'>; | ||
export declare function createReducer<S extends NotFunction, A extends Action = AnyAction>(initialState: S | (() => S), builderCallback: (builder: ActionReducerMapBuilder<S, A>) => void): ReducerWithInitialState<S, A>; | ||
export interface ActionReducerMapBuilder<State, Actions extends AnyAction = AnyAction> { | ||
addCase<ActionCreator extends TypedActionCreator<ActionType<Actions>>>(actionCreator: ActionCreator, reducer: CaseReducer<State, ReturnType<ActionCreator>>): ActionReducerMapBuilder<State, Actions>; | ||
addCase<Type extends Actions['type'], A extends Action<Type>>(type: Type, reducer: CaseReducer<State, A>): ActionReducerMapBuilder<State, Actions>; | ||
addMatcher<TAction extends Actions = Actions>(matcher: (action: Actions) => action is TAction, reducer: CaseReducer<State, TAction extends AnyAction ? TAction : TAction & AnyAction>): Omit<ActionReducerMapBuilder<State, Actions>, 'addCase'>; | ||
addMatcher<TAction extends Actions = Actions>(matcher: (action: Actions) => boolean, reducer: CaseReducer<State, TAction extends AnyAction ? TAction : TAction & AnyAction>): Omit<ActionReducerMapBuilder<State, Actions>, 'addCase'>; | ||
addDefaultCase(reducer: CaseReducer<State, AnyAction>): void; | ||
} | ||
export declare function executeReducerBuilderCallback<TState>(builderCallback: (builder: ActionReducerMapBuilder<TState>) => void): [ | ||
export declare function executeReducerBuilderCallback<TState, TAction extends AnyAction>(builderCallback: (builder: ActionReducerMapBuilder<TState, TAction>) => void): [ | ||
CaseReducers<TState, any>, | ||
ActionMatcherDescriptionCollection<TState>, | ||
CaseReducer<TState, AnyAction> | undefined | ||
CaseReducer<TState, TAction> | undefined | ||
]; | ||
export {}; |
@@ -34,2 +34,3 @@ export type TypeConstant = string; | ||
export type ExtractAction<TAction extends Action, TType extends TypeConstant = ActionType<TAction>> = Extract<TAction, Action<TType>>; | ||
export type ActionWithSuffix<TAction extends Action, Suffix extends string> = TAction extends Action ? TAction['type'] extends `${infer AName}::${infer ASuffix}` ? ASuffix extends Suffix ? TAction : never : never : never; | ||
export type ActionDefinitions = Record<string, ActionCreator>; |
@@ -1,1 +0,1 @@ | ||
export declare const version = "8.3.0"; | ||
export declare const version = "8.3.1"; |
{ | ||
"name": "@equinor/fusion-observable", | ||
"version": "8.3.0", | ||
"version": "8.3.1", | ||
"description": "WIP", | ||
@@ -62,3 +62,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@testing-library/react": "^14.2.0", | ||
"@testing-library/react": "^15.0.7", | ||
"@types/node": "^20.11.14", | ||
@@ -70,3 +70,3 @@ "@types/react": "^18.2.50", | ||
"typescript": "^5.4.2", | ||
"vitest": "^1.2.2" | ||
"vitest": "^1.6.0" | ||
}, | ||
@@ -73,0 +73,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
152437
770