zoukankan      html  css  js  c++  java
  • [NGXS] Selector

    When defining a selector, you can also pass other selectors into the signature of the Selector decorator to join other selectors with this state selector.

    @State<PreferencesStateModel>({ ... })
    export class PreferencesState { ... }
    
    @State<string[]>({ ... })
    export class ZooState {
    
     @Selector([ZooState, PreferencesState])
     static firstLocalPanda(state: string[], preferencesState: PreferencesStateModel) {
       return state.find(
         s => s.indexOf('panda') > -1 && s.indexOf(preferencesState.location)
       );
     }
    
     @Selector([ZooState.firstLocalPanda])
     static happyLocalPanda(panda: string) {
       return 'happy ' + panda;
     }
    
    }

    Now the happyLocalPanda will only recalculate when the output value of the firstLocalPanda selector changes.

    We recommend that you move your projects to this behavior in order to optimize your selectors and to prepare for the change to the defaults coming in NGXS v4. See the Selector Options section above for the recommended settings.

  • 相关阅读:
    设计模式 设计原则 何为设计
    面向对象 多态
    两个简易的对拍程序
    各类有用的神奇网站
    乘法逆元
    树链剖分
    Markdown的用法
    vimrc 的配置
    luogu【P1144】最短路计数
    【娱乐】收录各种神奇知乎问答
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12202708.html
Copyright © 2011-2022 走看看