我在测试应用程序中注意到奇怪的行为,每当我用新数组覆盖存储时,似乎旧状态仍在内存中(只有最近的条应该是蓝色的)
出于测试目的,我每5秒调度10次加载操作。
ngOnInit() {
setInterval(() => {
for (let i = 0; i < 10; i++) {
this.store.dispatch(CharacterActions.getCharacters());
}
}, 5000);
}
我的店就是这个样子
export interface CharacterState {
characters: Character[];
}
export const initialState: CharacterState = {
characters: [],
};
export const characterReducer = createReducer(
initialState,
on(CharacterActions.getCharactersSuccess, (state, { characters }) => ({
...state,
characters: [...characters],
}))
);
和性格类
import { Weapon } from "./weapon";
export class Character {
name: string;
surname: string;
private weapons: Weapon[];
constructor(name: string, surname: string, weapons?: Weapon[]) {
this.weapons = weapons ?? [];
this.name = name;
this.surname = surname;
}
public getWeapons(): Weapon[] {
return this.weapons;
}
public addWeapon(weapon: Weapon): void {
this.weapons.push(weapon);
}
public upgradeWeapon(name: string, value: number) {
this.weapons.find(x => x.name === name.toLowerCase())?.upgrade(value);
}
}
1条答案
按热度按时间ajsxfq5m1#
好吧,我认为它的工作版本
@ngrx/store@14.2.0
的每一个更高的它不是。