我想在 NGRX 信号存储中重用计算出的信号。
例如:
export const ExampleStore = signalStore(
withState(initialState),
withComputed(store => ({
property1: computed(() => store.example()),
property2: computed(() => store.property1()),
}))
);
store.property1()
在 computed
中不可调用
我知道有两种模式:
使用第二个
withComputed
export const ExampleStore = signalStore(
withState(initialState),
withComputed(store => ({
property1: computed(() => store.example()),
})),
withComputed(store => ({
property2: computed(() => store.property1()),
}))
);
同样
withComputed
export const ExampleStore = signalStore(
withState(initialState),
withComputed(store => {
const property1 = computed(() => store.example());
const property2 = computed(() => property1());
return {property1, property2};
})
);