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

TypeScript typesafe-actions.createReducer函数代码示例

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

本文整理汇总了TypeScript中typesafe-actions.createReducer函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createReducer函数的具体用法?TypeScript createReducer怎么用?TypeScript createReducer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了createReducer函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: simulateBookmark

export const bookmarkReducer = createReducer<BookmarkState, ActionType<typeof bookmarkCreators>>(
  INITIAL_STATE,
  {
    [getType(bookmarkCreators.copyBookmark)]: (
      state: BookmarkState,
      {payload}: ReturnType<typeof bookmarkCreators.copyBookmark>
    ) => {
      return {
        ...state,
        clipboard: {
          id: payload.id,
          isRemoveAfterPaste: false
        }
      }
    },
    [getType(bookmarkCreators.cutBookmark)]: (
      state: BookmarkState,
      {payload}: ReturnType<typeof bookmarkCreators.cutBookmark>
    ) => {
      return {
        ...state,
        clipboard: {
          id: payload.id,
          isRemoveAfterPaste: true
        }
      }
    },
    [getType(bookmarkCreators.getSearchResult)]: (
      state: BookmarkState,
      {payload}: ReturnType<typeof bookmarkCreators.getSearchResult>
    ) => {
      return {
        ...state,
        searchKeyword: payload.searchKeyword
      }
    },
    [getType(bookmarkCreators.removeBookmarkTree)]: (
      state: BookmarkState,
      {payload}: ReturnType<typeof bookmarkCreators.removeBookmarkTree>
    ) => {
      const removeFromIndex = state.trees.findIndex(R.pathEq(['parent', 'id'], payload.id))
      if (removeFromIndex < 0) return state

      return {
        ...state,
        trees: state.trees.slice(0, removeFromIndex)
      }
    },
    [getType(bookmarkCreators.removeDragIndicator)]: removeDragIndicator,
    [getType(bookmarkCreators.removeNextBookmarkTrees)]: (
      state: BookmarkState,
      {payload}: ReturnType<typeof bookmarkCreators.removeNextBookmarkTrees>
    ) => {
      const removeAfterIndex = state.trees.findIndex(
        R.pathEq(['parent', 'id'], payload.removeAfterId)
      )
      if (removeAfterIndex < 0) return state

      return {
        ...state,
        trees: state.trees.slice(0, removeAfterIndex + 1)
      }
    },
    [getType(bookmarkCreators.resetClipboard)]: (state: BookmarkState) => {
      return {
        ...state,
        clipboard: INITIAL_STATE.clipboard
      }
    },
    [getType(bookmarkCreators.setBookmarkTrees)]: (
      state: BookmarkState,
      {payload}: ReturnType<typeof bookmarkCreators.setBookmarkTrees>
    ) => {
      return {
        ...state,
        trees: payload.bookmarkTrees
      }
    },
    [getType(bookmarkCreators.setDragIndicator)]: (
      state: BookmarkState,
      {payload}: ReturnType<typeof bookmarkCreators.setDragIndicator>
    ) => {
      const parentIndex = state.trees.findIndex((tree) => tree.parent.id === payload.parentId)
      if (parentIndex === -1) return state

      return R.over(
        R.lensPath(['trees', parentIndex, 'children']),
        R.insert(payload.index, simulateBookmark({type: CST.BOOKMARK_TYPES.DRAG_INDICATOR})),
        removeDragIndicator(state)
      )
    }
  }
)
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:93,代码来源:reducer.ts


示例2:

import {ActionType, createReducer} from 'typesafe-actions'

import {NAV_MODULE} from '../../constants'
import * as navigationCreators from './actions'

interface NavigationState {
  selectedNavModule: NAV_MODULE
}
const INITIAL_STATE: NavigationState = {
  selectedNavModule: NAV_MODULE.GENERAL
}

export const navigationReducer = createReducer<
NavigationState,
ActionType<typeof navigationCreators>
>(INITIAL_STATE).handleAction(navigationCreators.switchNavModule, (state, {payload}) => {
  return {
    ...state,
    selectedNavModule: payload.navModule
  }
})
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:21,代码来源:reducer.ts


示例3: createAction

  activeWindowIdQueue: ReadonlyArray<string>
}

export const windowsInitialState: WindowsState = {
  activeWindowIdQueue: []
}

export const windowsCreators = {
  setActiveWindowId: createAction('SET_ACTIVE_WINDOW_ID', (action) => (windowId: string) =>
    action(windowId)),
  unsetActiveWindowId: createAction('UNSET_ACTIVE_WINDOW_ID', (action) => (windowId: string) =>
    action(windowId))
}

export const windowsReducer = createReducer<WindowsState, ActionType<typeof windowsCreators>>(
  windowsInitialState
)
  .handleAction(windowsCreators.setActiveWindowId, (state, {payload: windowId}) => {
    const activeWindowIdQueue = [
      ...state.activeWindowIdQueue.filter((x) => x !== windowId),
      windowId
    ]
    return {
      activeWindowId: activeWindowIdQueue[activeWindowIdQueue.length - 1],
      activeWindowIdQueue
    }
  })
  .handleAction(windowsCreators.unsetActiveWindowId, (state, {payload: windowId}) => {
    const activeWindowIdQueue = state.activeWindowIdQueue.filter((x) => x !== windowId)
    return {
      activeWindowId: activeWindowIdQueue[activeWindowIdQueue.length - 1],
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:31,代码来源:windows.ts


示例4:

  positionLeft: 0,
  positionTop: 0,
  targetId: undefined
}

export const menuReducer = createReducer<MenuState, ActionType<typeof menuCreators>>(
  INITIAL_STATE,
  {
    [getType(menuCreators.closeMenu)]: () => INITIAL_STATE,
    [getType(menuCreators.openMenu)]: (
      state: MenuState,
      {payload}: ReturnType<typeof menuCreators.openMenu>
    ) => {
      return {
        ...state,
        ...payload.coordinates,
        targetId: payload.targetId
      }
    },
    [getType(menuCreators.setMenuPattern)]: (
      state: MenuState,
      {payload}: ReturnType<typeof menuCreators.setMenuPattern>
    ) => {
      return {
        ...state,
        menuPattern: payload.menuPattern
      }
    }
  }
)
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:30,代码来源:reducer.ts


示例5: createAction

export const keyBindingsPerWindowCreators = {
  addEventListener: createAction(
    'ADD_EVENT_LISTENER',
    (action) => ({priority = 0, ...meta}: KeyBindingMeta, callback: KeyBindingEventCallback) =>
      action({...meta, priority, callback})
  ),
  removeEventListener: createAction(
    'REMOVE_EVENT_LISTENER',
    (action) => ({priority = 0, ...meta}: KeyBindingMeta, callback: KeyBindingEventCallback) =>
      action({...meta, priority, callback})
  )
}

export const keyBindingsPerWindowReducer = createReducer<
KeyBindingsPerWindowState,
ActionType<typeof keyBindingsPerWindowCreators>
>(keyBindingsPerWindowInitialState)
  .handleAction(keyBindingsPerWindowCreators.addEventListener, (state, {payload}) => {
    const {callback, key, priority, windowId} = payload

    const keyBindings = state.get(windowId) || []
    const updatedKeyBindings = [...keyBindings, {callback, key, priority}].sort(
      (a, b) => a.priority - b.priority
    )

    return new Map(state).set(windowId, updatedKeyBindings)
  })
  .handleAction(keyBindingsPerWindowCreators.removeEventListener, (state, {payload}) => {
    const {callback, key, priority, windowId} = payload

    const keyBindings = state.get(windowId)
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:31,代码来源:keyBindingsPerWindow.ts


示例6: deleteFromMap

export const listsReducer = createReducer<ListsState, ActionType<typeof listsCreators>>(
  listsInitialState,
  {
    [getType(listsCreators.removeList)]: (
      state: ListsState,
      {payload}: ReturnType<typeof listsCreators.removeList>
    ) => {
      const {listIndex} = payload

      return {
        ...state,
        highlightedIndices: deleteFromMap(state.highlightedIndices, listIndex),
        itemCounts: deleteFromMap(state.itemCounts, listIndex)
      }
    },
    [getType(listsCreators.resetLists)]: () => listsInitialState,
    [getType(listsCreators.setHighlightedIndex)]: (
      state: ListsState,
      {payload}: ReturnType<typeof listsCreators.setHighlightedIndex>
    ) => {
      const {listIndex, itemIndex} = payload

      return {
        ...state,
        highlightedIndices: new Map(state.highlightedIndices).set(listIndex, itemIndex)
      }
    },
    [getType(listsCreators.setItemCount)]: (
      state: ListsState,
      {payload}: ReturnType<typeof listsCreators.setItemCount>
    ) => {
      const {listIndex, itemCount} = payload

      return {...state, itemCounts: new Map(state.itemCounts).set(listIndex, itemCount)}
    },
    [getType(listsCreators.unsetHighlightedIndex)]: (
      state: ListsState,
      {payload}: ReturnType<typeof listsCreators.unsetHighlightedIndex>
    ) => {
      const {listIndex, itemIndex} = payload

      if (state.highlightedIndices.get(listIndex) !== itemIndex) {
        return state
      }

      return {
        ...state,
        highlightedIndices: deleteFromMap(state.highlightedIndices, listIndex)
      }
    }
  }
)
开发者ID:foray1010,项目名称:Popup-my-Bookmarks,代码行数:52,代码来源:lists.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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