zoukankan      html  css  js  c++  java
  • [Anuglar & NgRx] StoreRouterConnectingModule

    Always treat Router as the source of truth

    When we use Ngrx, we can see that we will use a "StoreRouterConnectingModule" from the example app.

    What it does, is that, it connects router state to store, 

    It will set up the router in such a way that right after the URL gets parsed and the future router state gets created, the router will dispatch a RouterAction

    Check the post.

    Code example:

    class TalksEffects {
      @Effect() navigateToTalks = this.actions.ofType(ROUTER_NAVIGATION).
        map(firstSegment).
        filter(s => s.routeConfig.path === "talks").
        switchMap((r: ActivatedRouteSnapshot) => {
          const filters = createFilters(r.params);
          return this.backend.findTalks(filters)
    .map(resp => ({type: 'TALKS_UPDATED', payload: {...resp, filters}})); }).catch(e => { console.log('Network error', e); return of(); }); }

    We can listen for "ROUTER_NAVATION" event, filter though the path, get the activated route snapshot, then snyc Router URL with BE.

  • 相关阅读:
    图书排列
    L1-059 敲笨钟 (20 分)
    区间移位
    取球博弈
    poj 2456 Aggressive cows
    对局匹配
    发现环
    数字划分
    哥德巴赫分解
    把数组排成最小的数
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7757683.html
Copyright © 2011-2022 走看看