当前位置:网站首页>Design details related to sap e-commerce cloud Spartacus UI store
Design details related to sap e-commerce cloud Spartacus UI store
2022-07-21 15:08:00 【Wang Zixi】
Store
state.ts
Defines and Site Context Business related State Data model .
The routine of defining data model is :
export const SITE_CONTEXT_FEATURE = 'siteContext';
export interface StateWithSiteContext {
[SITE_CONTEXT_FEATURE]: SiteContextState;
}
This is the top floor State Model .
SiteContextState It contains three sub State:
export interface SiteContextState {
languages: LanguagesState;
currencies: CurrenciesState;
baseSite: BaseSiteState;
}
With CurrenciesState For example , It's not just about Entities list , It also includes the current Active State of Currency:
export interface CurrenciesState {
entities: CurrencyEntities;
activeCurrency: string;
}
Redefine Entities list :
export interface CurrencyEntities {
[isocode: string]: Currency;
}
That's all Site Context Required by the field State data structure .
Be careful SITE_CONTEXT_FEATURE Where to use , In addition to the definitions in this document feature state outside , It is also used in the following two files :
scene 1: Used to create feature selector:
scene 2: Use StoreModule.forFeature register store:
When using createSelector and createFeatureSelector Function time ,@ngrx/store It keeps track of the latest parameters that call the selector function . Because selectors are pure functions , So when the parameters match, the last result can be returned , Without having to call the selector function again . This provides a performance advantage , Especially for selectors that perform expensive calculations . This practice is called memoization
.
createFeatureSelector Is to return to the top (Top Level
) Of Feature State
A convenient way . It is the characteristic slice of the state (Feature Slice
) Returns a typed (typed
) Selector function of .
Be careful createFeatureSelector There are two ways to write the call of .
How to write it 1
The figure below 2 Must be 1 A slice of , also 3 The type of must be the same as 2 The same type of :
2 The location of is actually result The location of :
How to write it 2
import {
createSelector, createFeatureSelector } from '@ngrx/store';
export const featureKey = 'feature';
export interface FeatureState {
counter: number;
}
export interface AppState {
feature: FeatureState;
}
export const selectFeature = createFeatureSelector<AppState, FeatureState>(featureKey);
export const selectFeatureCount = createSelector(
selectFeature,
(state: FeatureState) => state.counter
);
I did a test , stay SAP E-commerce cloud Spartacus UI In the project , The two expressions are completely equivalent :
Can be successfully compiled :
边栏推荐
- It is said that only the great God knows the function of this capacitor
- 虚拟机双网卡配置
- Web3再怎么牛 也不能逃出这几个老巨头的五指山
- Deep copy function
- 请问一下大佬,flink 如何做到 mysql 数据库与elastic search的数据实时同步
- 金仓数据库KingbaseES数据库管理员指南--15.1. 管理视图
- TDSQL PG版节省30%磁盘空间的同时如何保障数据安全?|DB·洞见
- 金仓数据库KingbaseES数据库管理员指南--17数据库调度概念
- networkX 可视化图 visibility graph 如何根据时间序列得到图
- 性能提升30倍丨基于 DolphinDB 的 mytt 指标库实现
猜你喜欢
Mysql的主键UUID、自增ID、雪花算法到底该怎么选择?(荣耀典藏版)
leetcode:42. Connect rainwater
Win64 driver kernel programming -31 Enumerating and deleting image callbacks
Web3流量聚合平台Starfish OS,给玩家元宇宙新范式体验
Yunna | dynamic environment monitoring system inspection, general introduction to the functions of the dynamic environment monitoring system
TCP sliding window explanation (very practical)
Win64 driver kernel programming -31 Enumerating and deleting image callbacks
When the microstrip line is pulled open for 7h, you feel very stable?
Supermarket order management system based on SSM framework +mysql [source code + document +ppt]
Detailed explanation of TCP communication process (with case code)
随机推荐
Detailed explanation of TCP communication concurrent server (with case code)
leetcode:689. 三个无重叠子数组的最大和
Header files referencing different packages in the same workspace
[public class preview]: cloud video conference system privatization practice
巧用RoaringBitMap处理海量数据内存diff问题
【LeetCode】29、 两数相除
[untitled]
同一工作空间下引用不同包的头文件
魑魅魍魎
[C language] file related operations
【C 练习】将字符串中的空格转换为「%20」
Audience analysis and uninstall analysis have been comprehensively upgraded, and HMS core analysis service version 6.6.0 has been updated
虚拟机双网卡配置
Yunna | dynamic environment monitoring system inspection, general introduction to the functions of the dynamic environment monitoring system
7.19 simulation summary
Rust language - tuple
虚拟机内核参数永久生效配置
Yunna Xianning communication machine room dynamic loop monitoring system, telecom dynamic loop monitoring system
【二叉树】分裂二叉树的最大乘积
Win64 driver kernel programming -31 Enumerating and deleting image callbacks