当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript immer.produce函数代码示例

本文整理汇总了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;未经允许,请勿转载。