首页 > 其他 > 详细

[NGXS] Selector - 2 Joining Selectors, compose

时间:2020-01-16 19:41:51      阅读:72      评论:0      收藏:0      [点我收藏+]

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.

[NGXS] Selector - 2 Joining Selectors, compose

原文:https://www.cnblogs.com/Answer1215/p/12202708.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!