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


TypeScript NgRedux.mapDispatchToTarget方法代码示例

本文整理汇总了TypeScript中ng2-redux.NgRedux.mapDispatchToTarget方法的典型用法代码示例。如果您正苦于以下问题:TypeScript NgRedux.mapDispatchToTarget方法的具体用法?TypeScript NgRedux.mapDispatchToTarget怎么用?TypeScript NgRedux.mapDispatchToTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ng2-redux.NgRedux的用法示例。


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

示例1: constructor

  constructor(
    private ngRedux: NgRedux<IAppState>,
    applicationRef: ApplicationRef,
    private sessionActions: SessionActions) {

    const session$: Observable<Map<string, any>>
      = ngRedux.select<Map<string, any>>('session');

    this.hasError$ = session$.map(s => !!s.get('hasError'));
    this.isLoading$ = session$.map(s => !!s.get('isLoading'));
    this.loggedIn$ = session$.map(s => !!s.get('token'));
    this.loggedOut$ = this.loggedIn$.map(loggedIn => !loggedIn);

    this.userName$ = session$.map(s => {
        return [
          s.getIn(['user', 'firstName'], ''),
          s.getIn(['user', 'lastName'], '')
         ].join(' ');
      });

    ngRedux.mapDispatchToTarget((dispatch) => {
      return {
        login: (credentials) => dispatch(
          this.sessionActions.loginUser(credentials)),
        logout: () => dispatch(
          this.sessionActions.logoutUser())
      };
    })(this);

    this.unsubscribe = ngRedux.subscribe(() => {
      applicationRef.tick();
    });
  }
开发者ID:lokeshjain2008,项目名称:angular2-redux-starter,代码行数:33,代码来源:sample-app.ts

示例2: ngOnInit

 ngOnInit() {
   this.counter$ = this.ngRedux
     .select(n => n.counter.get('count'));
     
   this.ngRedux.mapDispatchToTarget(CounterActions)(this);
   
 }
开发者ID:e-schultz,项目名称:angular2-redux-example,代码行数:7,代码来源:counter-page.ts

示例3: ngOnInit

 ngOnInit() {
   
   this.selector = this.ngRedux
     .select(state => state.session, is)
     .subscribe(n => { 
       this.session = n;
       this.isLoggedIn = n.get('token', false);
     });
 
   this.ngRedux.mapDispatchToTarget(this.mapDispatchToThis)(this);
   
 }
开发者ID:e-schultz,项目名称:angular2-redux-example,代码行数:12,代码来源:sample-app.ts

示例4: constructor

  constructor(
    ngRedux: NgRedux<AppState>,
    applicationRef: ApplicationRef) {

    this.ngRedux = ngRedux;

    ngRedux.mapDispatchToTarget((dispatch) => {
      return {
        setTitle: (title) => dispatch(setTitle(title))
      };
    })(this);

    this.unsubscribe = ngRedux.subscribe(() => {
      applicationRef.tick();
    });
  }
开发者ID:levinmr,项目名称:angular2-webpack-redux,代码行数:16,代码来源:home-page.component.ts

示例5: constructor

  constructor(
    ngRedux: NgRedux<IAppState>,
    applicationRef: ApplicationRef
  ) {
    this.sampleData$ = ngRedux.select(n => n.sampleReducer.get('sampleData'));

    ngRedux.mapDispatchToTarget((dispatch) => {
      return {
        foo: () => dispatch({
          type: 'App/FOO',
          payload: 'FOO'
        })
      }
    })(this);

    this.unsubscribe = ngRedux.subscribe(() => {
      applicationRef.tick();
    });
  }
开发者ID:rtbm,项目名称:ng2-webpack-boilerplate,代码行数:19,代码来源:my-app.ts

示例6: constructor

  constructor(
    ngRedux: NgRedux<AppState>,
    applicationRef: ApplicationRef) {

    const app$ = ngRedux.select<Map<string, any>>('app');

    this.ngRedux = ngRedux;
    this.title$ = app$.map(s => s.get('title'));

    ngRedux.mapDispatchToTarget((dispatch) => {
      return {
        changeRoute: (path) => dispatch(changeRoute(path))
      };
    })(this);

    this.unsubscribe = ngRedux.subscribe(() => {
      applicationRef.tick();
    });

  }
开发者ID:levinmr,项目名称:angular2-webpack-redux,代码行数:20,代码来源:app.component.ts

示例7: constructor

  constructor(
    ngRedux: NgRedux<AppState>,
    applicationRef: ApplicationRef) {

    const user$ = ngRedux.select<Map<string, any>>('user');

    this.ngRedux = ngRedux;
    this.users$ = user$.map(s => s.get('users'));
    this.getAllPending$ = user$.map(s => s.get('getAllPending'));
    this.getAllError$ = user$.map(s => s.get('getAllError'));

    ngRedux.mapDispatchToTarget((dispatch) => {
      return {
        getUsers: (id) => dispatch(getUsers(id))
      };
    })(this);

      this.unsubscribe = ngRedux.subscribe(() => {
      applicationRef.tick();
    });
  }
开发者ID:levinmr,项目名称:angular2-webpack-redux,代码行数:21,代码来源:users-page.component.ts

示例8: ngOnInit

  ngOnInit() {
    
    let filterTodos = (val: boolean) => (item: Todo) => item.completed === val;

    this.hideCompleted$ = this.ngRedux.select(state => {
      
      return !state.filter.showCompleted;
    });

    this.todos$ = this.ngRedux
      .select(n => n.todos);

    this.completedTodos$ = this.todos$
      .map(todos => todos.filter(filterTodos(true)));

    this.incompleteTodos$ = this.todos$
      .map(todos => todos.filter(filterTodos(false)));

    this.total$ = this.todos$.pluck('length');
    this.completed$ = this.completedTodos$.pluck('length');

    this.filteredTodos$ = this.todos$
      .combineLatest(this.hideCompleted$, (todos, filter) => {
        return todos.filter(n => filterTodos(false)(n) || filter === false);
      });

    this.ngRedux.mapDispatchToTarget({
      completeTodo,
      editTodo,
      deleteTodo,
      filterCompleted,
      completeAll,
      clearCompleted,
      addTodo
    })(this);

  }
开发者ID:e-schultz,项目名称:angular2-redux-example,代码行数:37,代码来源:todo-page.ts


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