Update DispatchingStore to provide better typing for dispatch function parameters
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import eq from "lodash/eq"
|
||||
import { pluck } from "rxjs/operators"
|
||||
import DispatchingStore, { Dispatchers } from "./DispatchingStore"
|
||||
import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
|
||||
|
||||
export const defaultRESTHistoryState = {
|
||||
state: [] as any[],
|
||||
@@ -15,18 +15,21 @@ export const HISTORY_LIMIT = 50
|
||||
type RESTHistoryType = typeof defaultRESTHistoryState
|
||||
type GraphqlHistoryType = typeof defaultGraphqlHistoryState
|
||||
|
||||
const HistoryDispatcher: Dispatchers<RESTHistoryType | GraphqlHistoryType> = {
|
||||
setEntries(_, { entries }: { entries: any[] }) {
|
||||
const HistoryDispatcher = defineDispatchers({
|
||||
setEntries(
|
||||
_: RESTHistoryType | GraphqlHistoryType,
|
||||
{ entries }: { entries: any[] }
|
||||
) {
|
||||
return {
|
||||
state: entries,
|
||||
}
|
||||
},
|
||||
addEntry(currentVal, { entry }) {
|
||||
addEntry(currentVal: RESTHistoryType | GraphqlHistoryType, { entry }) {
|
||||
return {
|
||||
state: [entry, ...currentVal.state].slice(0, HISTORY_LIMIT),
|
||||
}
|
||||
},
|
||||
deleteEntry(currentVal, { entry }) {
|
||||
deleteEntry(currentVal: RESTHistoryType | GraphqlHistoryType, { entry }) {
|
||||
return {
|
||||
state: currentVal.state.filter((e) => !eq(e, entry)),
|
||||
}
|
||||
@@ -36,7 +39,7 @@ const HistoryDispatcher: Dispatchers<RESTHistoryType | GraphqlHistoryType> = {
|
||||
state: [],
|
||||
}
|
||||
},
|
||||
toggleStar(currentVal, { entry }) {
|
||||
toggleStar(currentVal: RESTHistoryType | GraphqlHistoryType, { entry }) {
|
||||
return {
|
||||
state: currentVal.state.map((e) => {
|
||||
if (eq(e, entry) && e.star !== undefined) {
|
||||
@@ -49,7 +52,7 @@ const HistoryDispatcher: Dispatchers<RESTHistoryType | GraphqlHistoryType> = {
|
||||
}),
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
export const restHistoryStore = new DispatchingStore(
|
||||
defaultRESTHistoryState,
|
||||
|
||||
Reference in New Issue
Block a user