NGXS维护状态图而不是数组
我正在考虑使用NGXS来维持服务器的股票当前价格。我可能在应用程序中有很多符号,因此我宁愿使用哈希键而不是数组将其索引。
我想要的看起来像这样的东西。
export interface SymbolCurrentPriceModel {
updateTime: number;
symbol: string;
currentPrice: number;
}
const SYMBOL_CURRENT_PRICES_TOKEN = new StateToken<Map<string, SymbolCurrentPriceModel>>('symbolCurrentPrices');
我可以这样做,但是当其中一个符号更改值时,我不想在操作上派遣整个地图。相反,如果可能的话,我想每个符号。
在选择器方面,我正在想象这样的东西来访问这些值,
@Selector([SYMBOL_CURRENT_PRICES_TOKEN])
static getCurrentPrice(state: Map<string, SymbolCurrentPriceModel>) {
return (symbol: string) => {
return state[symbol];
};
}
我似乎无法在文档中找到一个支持此用例 https://www.ngxs.io/concepts/state/state
除此之外,我希望我的选择器如果不在商店。这是NGSX处理的用例吗?
I'm looking into using NGXS for maintaining the current prices of tickers coming from the server. I might have a lot of symbols in the application so I'd rather be able to index into them using a hash key instead of an array.
what I would like would look like something like this.
export interface SymbolCurrentPriceModel {
updateTime: number;
symbol: string;
currentPrice: number;
}
const SYMBOL_CURRENT_PRICES_TOKEN = new StateToken<Map<string, SymbolCurrentPriceModel>>('symbolCurrentPrices');
I can do it like this, however I don't want to dispatch the whole map on an action when one of the symbols changes values. Instead I would like to per symbol if that's possible.
On the selector side, I'm imagining something like this to access these values
@Selector([SYMBOL_CURRENT_PRICES_TOKEN])
static getCurrentPrice(state: Map<string, SymbolCurrentPriceModel>) {
return (symbol: string) => {
return state[symbol];
};
}
I can't seem to be able to find an example in the docs that would support this use case https://www.ngxs.io/concepts/state
In addition to this, I would like my selector to fetch the value if it isn't in the store. Is that a use case handled by NGSX?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论