redux-starter-kit
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -352,2 +352,6 @@ 'use strict'; | ||
/** | ||
* An action creator atttached to a slice. | ||
*/ | ||
function getType$1(slice, actionKey) { | ||
@@ -354,0 +358,0 @@ return slice ? "".concat(slice, "/").concat(actionKey) : actionKey; |
@@ -348,2 +348,6 @@ import { combineReducers, applyMiddleware, createStore, compose } from 'redux'; | ||
/** | ||
* An action creator atttached to a slice. | ||
*/ | ||
function getType$1(slice, actionKey) { | ||
@@ -350,0 +354,0 @@ return slice ? "".concat(slice, "/").concat(actionKey) : actionKey; |
{ | ||
"name": "redux-starter-kit", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "A simple set of tools to make using Redux easier", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/markerikson/redux-starter-kit", |
@@ -1,2 +0,2 @@ | ||
import { Action, AnyAction, ActionCreator, Reducer } from 'redux' | ||
import { Action, AnyAction, Reducer } from 'redux' | ||
import { createAction, PayloadAction } from './createAction' | ||
@@ -6,6 +6,11 @@ import { createReducer, CaseReducersMapObject } from './createReducer' | ||
/** | ||
* An action creator atttached to a slice. | ||
*/ | ||
export type SliceActionCreator<P> = (payload: P) => PayloadAction<P> | ||
export interface Slice< | ||
S = any, | ||
A extends Action = AnyAction, | ||
AT extends string = string | ||
AP extends { [key: string]: any } = { [key: string]: any } | ||
> { | ||
@@ -26,3 +31,3 @@ /** | ||
*/ | ||
actions: { [type in AT]: ActionCreator<A> } | ||
actions: { [type in keyof AP]: SliceActionCreator<AP[type]> } | ||
@@ -73,2 +78,14 @@ /** | ||
type ExtractPayloads< | ||
S, | ||
A extends PayloadAction, | ||
CR extends CaseReducersMapObject<S, A> | ||
> = { | ||
[type in keyof CR]: CR[type] extends (state: S) => any | ||
? void | ||
: (CR[type] extends (state: S, action: PayloadAction<infer P>) => any | ||
? P | ||
: never) | ||
} | ||
function getType(slice: string, actionKey: string): string { | ||
@@ -88,7 +105,7 @@ return slice ? `${slice}/${actionKey}` : actionKey | ||
S = any, | ||
A extends PayloadAction = PayloadAction, | ||
A extends PayloadAction = PayloadAction<any>, | ||
CR extends CaseReducersMapObject<S, A> = CaseReducersMapObject<S, A> | ||
>( | ||
options: CreateSliceOptions<S, A, CR> | ||
): Slice<S, A, Extract<keyof CR, string>> { | ||
): Slice<S, A, ExtractPayloads<S, A, CR>> { | ||
const { slice = '', initialState } = options | ||
@@ -95,0 +112,0 @@ const reducers = options.reducers || {} |
Sorry, the diff of this file is too big to display
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
202470
5285