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


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

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