• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript immer.produce函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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 []
      }
    }
  })
开发者ID:influxdata,项目名称:influxdb,代码行数:32,代码来源:notifications.ts


示例2: produce

 [RESTORE_STEP]: state =>
   produce(state, draft => {
     Object.assign(draft, {
       ...state.pastStep[0],
       pastStep: state.pastStep.slice(1)
     })
   }),
开发者ID:DanSnow,项目名称:react-reversi,代码行数:7,代码来源:reducer.ts


示例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;
    }
});
开发者ID:grebaldi,项目名称:PackageFactory.Guevara,代码行数:7,代码来源:index.ts


示例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
      }
    }
  })
开发者ID:influxdata,项目名称:influxdb,代码行数:28,代码来源:autoRefresh.ts


示例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
      }
    }
  })
开发者ID:influxdata,项目名称:influxdb,代码行数:53,代码来源:index.ts


示例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
      }
    }
  })
开发者ID:influxdata,项目名称:influxdb,代码行数:53,代码来源:index.ts


示例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
      }
    }
  })
开发者ID:influxdata,项目名称:influxdb,代码行数:53,代码来源:index.ts


示例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
      }
    }
  })
开发者ID:influxdata,项目名称:influxdb,代码行数:53,代码来源:index.ts



注:本文中的immer.produce函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript Immutable.List函数代码示例发布时间:2022-05-25
下一篇:
TypeScript immer.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap