本文整理汇总了TypeScript中immer.produce函数的典型用法代码示例。如果您正苦于以下问题:TypeScript produce函数的具体用法?TypeScript produce怎么用?TypeScript produce使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了produce函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: produce
export const notificationsReducer = (
state = initialState,
action: Action
): Notification[] =>
produce(state, draftState => {
switch (action.type) {
case 'PUBLISH_NOTIFICATION': {
const {notification} = action.payload
const publishedNotification = {
...notification,
id: uuid.v4(),
}
const matchIndex = state.findIndex(
n => n.type && notification.type && n.type === notification.type
)
const isUnique = matchIndex === -1
if (isUnique) {
draftState.unshift(publishedNotification)
}
return
}
case 'DISMISS_NOTIFICATION': {
const {id} = action.payload
return draftState.filter(n => n.id !== id)
}
case 'DISMISS_ALL_NOTIFICATIONS': {
return []
}
}
})
示例2: produce
[RESTORE_STEP]: state =>
produce(state, draft => {
Object.assign(draft, {
...state.pastStep[0],
pastStep: state.pastStep.slice(1)
})
}),
示例3: produce
export const reducer = (state: State = defaultState, action: InitAction) => produce(state, draft => {
switch (action.type) {
case system.INIT:
draft.interfaceLanguage = action.payload.user.preferences.interfaceLanguage;
break;
}
});
示例4: initialState
export const autoRefreshReducer = (state = initialState(), action: Action) =>
produce(state, draftState => {
switch (action.type) {
case 'SET_AUTO_REFRESH_INTERVAL': {
const {dashboardID, milliseconds} = action.payload
if (!draftState[dashboardID]) {
draftState[dashboardID] = AUTOREFRESH_DEFAULT
}
draftState[dashboardID].interval = milliseconds
return
}
case 'SET_AUTO_REFRESH_STATUS': {
const {dashboardID, status} = action.payload
if (!draftState[dashboardID]) {
draftState[dashboardID] = AUTOREFRESH_DEFAULT
}
draftState[dashboardID].status = status
return
}
}
})
示例5: initialState
export const bucketsReducer = (
state: BucketsState = initialState(),
action: Action
): BucketsState =>
produce(state, draftState => {
switch (action.type) {
case 'SET_BUCKETS': {
const {status, list} = action.payload
draftState.status = status
if (list) {
draftState.list = list
}
return
}
case 'ADD_BUCKET': {
const {bucket} = action.payload
draftState.list.push(bucket)
return
}
case 'EDIT_BUCKET': {
const {bucket} = action.payload
const {list} = draftState
draftState.list = list.map(l => {
if (l.id === bucket.id) {
return bucket
}
return l
})
return
}
case 'REMOVE_BUCKET': {
const {id} = action.payload
const {list} = draftState
const deleted = list.filter(l => {
return l.id !== id
})
draftState.list = deleted
return
}
}
})
示例6: initialState
export const labelsReducer = (
state: LabelsState = initialState(),
action: Action
): LabelsState =>
produce(state, draftState => {
switch (action.type) {
case 'SET_LABELS': {
const {status, list} = action.payload
draftState.status = status
if (list) {
draftState.list = list
}
return
}
case 'ADD_LABEL': {
const {label} = action.payload
draftState.list.push(label)
return
}
case 'EDIT_LABEL': {
const {label} = action.payload
const {list} = draftState
draftState.list = list.map(l => {
if (l.id === label.id) {
return label
}
return l
})
return
}
case 'REMOVE_LABEL': {
const {id} = action.payload
const {list} = draftState
const deleted = list.filter(l => {
return l.id !== id
})
draftState.list = deleted
return
}
}
})
示例7: initialState
export const authorizationsReducer = (
state: AuthorizationsState = initialState(),
action: Action
): AuthorizationsState =>
produce(state, draftState => {
switch (action.type) {
case 'SET_AUTHS': {
const {status, list} = action.payload
draftState.status = status
if (list) {
draftState.list = list
}
return
}
case 'ADD_AUTH': {
const {authorization} = action.payload
draftState.list.push(authorization)
return
}
case 'EDIT_AUTH': {
const {authorization} = action.payload
const {list} = draftState
draftState.list = list.map(l => {
if (l.id === authorization.id) {
return authorization
}
return l
})
return
}
case 'REMOVE_AUTH': {
const {id} = action.payload
const {list} = draftState
const deleted = list.filter(l => {
return l.id !== id
})
draftState.list = deleted
return
}
}
})
示例8: initialState
export const scrapersReducer = (
state: ScrapersState = initialState(),
action: Action
): ScrapersState =>
produce(state, draftState => {
switch (action.type) {
case 'SET_SCRAPERS': {
const {status, list} = action.payload
draftState.status = status
if (list) {
draftState.list = list
}
return
}
case 'ADD_SCRAPER': {
const {scraper} = action.payload
draftState.list.push(scraper)
return
}
case 'EDIT_SCRAPER': {
const {scraper} = action.payload
const {list} = draftState
draftState.list = list.map(l => {
if (l.id === scraper.id) {
return scraper
}
return l
})
return
}
case 'REMOVE_SCRAPER': {
const {id} = action.payload
const {list} = draftState
const deleted = list.filter(l => {
return l.id !== id
})
draftState.list = deleted
return
}
}
})