Skip to content

Commit

Permalink
feat: fix and export TS action types
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Nov 9, 2023
1 parent ed1126d commit 11bea7d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 15 deletions.
54 changes: 47 additions & 7 deletions src/actions.d.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,67 @@
import { AnyAction } from 'redux'
import type { Feature, FeatureState, FeatureAction } from './index'
import type { Feature, FeatureState } from './index'
export declare const ACTION_TYPE_PREFIX = '@@redux-features/'
export declare const ADD_FEATURE: '@@redux-features/ADD_FEATURE'
export declare const REPLACE_FEATURE: '@@redux-features/REPLACE_FEATURE'
export declare const LOAD_FEATURE: '@@redux-features/LOAD_FEATURE'
export declare const INSTALL_FEATURE: '@@redux-features/INSTALL_FEATURE'
export declare const SET_FEATURE_STATE: '@@redux-features/SET_FEATURE_STATE'
export declare const LOAD_INITIAL_FEATURES: '@@redux-features/LOAD_INITIAL_FEATURES'

export type AddFeatureAction<S = any, A extends AnyAction = AnyAction> = {
type: typeof ADD_FEATURE
payload: Feature<S, A>
meta: { id: string }
}
export declare function addFeature<S = any, A extends AnyAction = AnyAction>(
id: string,
feature: Feature<S, A>
): FeatureAction
): AddFeatureAction<S, A>

export type ReplaceFeatureAction<S = any, A extends AnyAction = AnyAction> = {
type: typeof REPLACE_FEATURE
feature: Feature<S, A>
meta: { id: string }
}
export declare function replaceFeature<
S = any,
A extends AnyAction = AnyAction
>(id: string, feature: Feature<S, A>): FeatureAction
export declare function loadFeature(id: string): FeatureAction
>(id: string, feature: Feature<S, A>): ReplaceFeatureAction

export type LoadFeatureAction = {
type: typeof LOAD_FEATURE
meta: { id: string }
}
export declare function loadFeature(id: string): LoadFeatureAction

export type InstallFeatureAction<S = any, A extends AnyAction = AnyAction> = {
type: typeof INSTALL_FEATURE
feature: Feature<S, A>
meta: { id: string }
}
export declare function installFeature<
S = any,
A extends AnyAction = AnyAction
>(id: string, feature: Feature<S, A>): FeatureAction
>(id: string, feature: Feature<S, A>): InstallFeatureAction<S, A>

export type SetFeatureStateAction = {
type: typeof SET_FEATURE_STATE
payload: FeatureState
}
export declare function setFeatureState(
id: string,
payload: FeatureState
): FeatureAction
export declare function loadInitialFeatures(): FeatureAction
): SetFeatureStateAction

export type LoadInitialFeaturesAction = {
type: typeof LOAD_INITIAL_FEATURES
}
export declare function loadInitialFeatures(): LoadInitialFeaturesAction

export type FeatureAction<S = any, A extends AnyAction = AnyAction> =
| AddFeatureAction<S, A>
| ReplaceFeatureAction<S, A>
| LoadFeatureAction
| InstallFeatureAction<S, A>
| SetFeatureStateAction
| LoadInitialFeaturesAction
22 changes: 14 additions & 8 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import {
replaceFeature,
setFeatureState,
loadInitialFeatures,
AddFeatureAction,
LoadFeatureAction,
InstallFeatureAction,
ReplaceFeatureAction,
SetFeatureStateAction,
LoadInitialFeaturesAction,
FeatureAction,
} from './actions'
export {
featuresReducer,
Expand All @@ -39,6 +46,13 @@ export {
replaceFeature,
setFeatureState,
loadInitialFeatures,
AddFeatureAction,
LoadFeatureAction,
InstallFeatureAction,
ReplaceFeatureAction,
SetFeatureStateAction,
LoadInitialFeaturesAction,
FeatureAction,
}
import type {
MiddlewareAPI,
Expand Down Expand Up @@ -80,11 +94,3 @@ export type Features<
A extends AnyAction = AnyAction,
D extends Dispatch = Dispatch<A>
> = Record<string, Feature<S, A, D>>

export type FeatureAction = {
type: string
payload?: any
meta?: {
id: string
}
}

0 comments on commit 11bea7d

Please sign in to comment.