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

TypeScript store.Reducer类代码示例

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

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



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

示例1: switch

export const postsByReddit : Reducer<RedditPosts> = (state: {} = {}, action : Action) => {
    switch (action.type) {
        case INVALIDATE_REDDIT:
        case RECEIVE_POSTS:
        case REQUEST_POSTS:
            return Object.assign({}, state, {
                [action.payload.reddit]: posts(state[action.payload.reddit], action)
            });
        default:
            return state;
    }
};
开发者ID:Hongbo-Miao,项目名称:ngrx-examples,代码行数:12,代码来源:reddit.ts


示例2: switch

export const todos : Reducer<Todo[]> = (state : Todo[] = [], action: Action) => {
  switch(action.type) {
      case ADD_TODO:
          return [
              ...state,
              todo(undefined, action)
          ];
      case TOGGLE_TODO:
          return state.map(t => todo(t, action));
      default:
          return state;
  }
};
开发者ID:Hongbo-Miao,项目名称:ngrx-examples,代码行数:13,代码来源:todos.ts


示例3: switch

export const games: Reducer<IGame[]> = (state: IGame[] = [], action: Action) => {
  switch (action.type) {
    case ADD_GAME:
      return [
        ...state,
        game(undefined, action)
      ];
    case TOGGLE_GAME:
      return state.map(t => game(t, action));
    default:
      return state;
  }
};
开发者ID:justdaft,项目名称:cuddly-tribble,代码行数:13,代码来源:games.ts


示例4: switch

export const postsByReddit : Reducer<RedditPosts> = (state: {} = {}, {type, payload} : Action) => {
    switch (type) {
        case LOADING:
            console.log('LOADING');
            return Object.assign({}, state, {
                isFetching: true,
                didInvalidate: false,
            });

        case RECEIVE_POSTS:
            return Object.assign({}, state, {
                isFetching: false,
                [payload.reddit]: posts(state[payload.reddit], {type, payload})
            });
        default:
            return state;
    }
};
开发者ID:andreyZavrazhnov,项目名称:ngrx-examples,代码行数:18,代码来源:reddit.ts


示例5: undoable

export function undoable(reducer: Reducer<any>) {
  // Call the reducer with empty action to populate the initial state
  const initialState: UndoableState = {
    past: [],
    present: reducer(undefined, { type: '__INIT__' }),
    future: []
  };

  // Return a reducer that handles undo and redo
  return function (state = initialState, action: Action) {
    const { past, present, future } = state;
    switch (action.type) {
      case 'UNDO':
        if (past.length <= 1) return state;
        const previous = past[past.length - 1];
        const newPast = past.slice(0, past.length - 1);
        return {
          past: newPast,
          present: previous,
          future: [present, ...future]
        };
      case 'REDO':
        if (future.length < 1) return state;
        const next = future[0];
        const newFuture = future.slice(1);
        return {
          past: [...past, present],
          present: next,
          future: newFuture
        };
      default:
        // Delegate handling the action to the passed reducer
        const newPresent = reducer(present, action);
        if (present === newPresent) {
          return state;
        }
        return {
          past: [...past, present],
          present: newPresent,
          future: []
        };
    }
  };
};
开发者ID:zhaoyiyi,项目名称:tv-todo,代码行数:44,代码来源:undoable.ts


示例6: constructor

  constructor(
    dispatcher: DevtoolsDispatcher,
    actions$: Dispatcher,
    reducers$: Reducer,
    initialState: any,
    options: Options,
    extension: Extension
  ) {
    const liftedInitialState = liftInitialState(initialState, options.monitor);
    const liftReducer = liftReducerWith(initialState, liftedInitialState, options.monitor, {
      maxAge: options.maxAge
    });

    const liftedActions$ = actions$
      .skip(1)
      .merge(extension.actions$)
      .map(liftAction)
      .merge(dispatcher, extension.liftedActions$)
      .observeOn(queue);

    const liftedReducers$ = reducers$
      .map(liftReducer);

    const liftedState = liftedActions$
      .withLatestFrom(liftedReducers$)
      .scan((liftedState, [ action, reducer ]) => {
        const nextState = reducer(liftedState, action);

        extension.notify(action, nextState);

        return nextState;
      }, liftedInitialState)
      .publishReplay(1)
      .refCount();

    const state = liftedState
      .map(unliftState);

    this.dispatcher = dispatcher;
    this.liftedState = liftedState;
    this.state = state;
  }
开发者ID:dballance,项目名称:store-devtools,代码行数:42,代码来源:devtools.ts


示例7: reducer

    return (state: any, action: Action) => {
        let reg = new RegExp(`^\\[${key}\\] (.+)`);

        if(action.type === Store.init) {
            return reducer(state, action);
        } else if(reg.test(action.type)) {
            action = Object.assign({}, action, {
                'type': action.type.replace(reg, '$1')
            });

            return reducer(state, action);
        } else {
            return state;
        }
    };
开发者ID:fellswoop,项目名称:angular-project-template,代码行数:15,代码来源:protected.ts


示例8: function

    return function (state = initialState, action : Action) {
        const { past, present, future } = state;
        switch (action.type) {

            case 'UNDO':
                const previous = past[past.length - 1];
                const newPast = past.slice(0, past.length - 1);
                return {
                    past: newPast,
                    present: previous,
                    future: [ present, ...future ]
                };
            case 'REDO':
                const next = future[0];
                const newFuture = future.slice(1);
                return {
                    past: [ ...past, present ],
                    present: next,
                    future: newFuture
                };
            default:
                // Delegate handling the action to the passed reducer
                const newPresent = reducer(present, action);
                if (present === newPresent) {
                    return state
                }
                return {
                    past: [ ...past, present ],
                    present: newPresent,
                    future: []
                }
        }
    }
开发者ID:Hongbo-Miao,项目名称:ngrx-examples,代码行数:33,代码来源:undoable.ts


示例9: clock

 return state.map((person) => {
     if (payload === person)
         return {
             name: person.name,
             time: clock(payload.time, {type: HOUR, payload: 6})
         };
     
     return person;
 });
开发者ID:kgosse,项目名称:trg-ngrx-store,代码行数:9,代码来源:reducers.ts


示例10: return

    return (state = initial, action: Action) => {
        let next;
        let type = action.type;
        let historyReg = new RegExp('^(\\[HISTORY\\] [A-Z]+).*');
        
        if(key && historyReg.test(type)) {
            let keyReg = new RegExp(` \\[${key}\\]`);
            
            if (!keyReg.test(type)) {
                return state;
            } else {
                type = type.replace(historyReg, '$1');
            }
        }

        switch(type) {
            case History.undo:
                if(past.length) {
                    next = past[past.length - 1];
                    past = past.slice(0, past.length - 1);
                    future = [state, ...future];

                    return next;
                } else {
                    return state;
                }

            case History.redo:
                if(future.length) {
                    next = future[0];
                    past = [...past, state];
                    future = future.slice(1);

                    return next;
                } else {
                    return state;
                }

            case History.reset:
                past = [...past, state];
                future = future.slice(1);
                
                return initial;

            default:
                next = reducer(state, action);

                if (state === next) {
                    return state;
                }

                past = [...past, state];
                future = [];

                return next;
        }
    };
开发者ID:fellswoop,项目名称:angular-project-template,代码行数:57,代码来源:history.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript store.ScannedActionsSubject类代码示例发布时间:2022-05-28
下一篇:
TypeScript store.Dispatcher类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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