import { State, Action, StateContext } from '@ngxs/store';
export class FeedAnimals {
static readonly type = '[Zoo] FeedAnimals';
}
export interface ZooStateModel {
feed: boolean;
}
@State<ZooStateModel>({
name: 'zoo',
defaults: {
feed: false
}
})
export class ZooState {
@Action(FeedAnimals)
feedAnimals(ctx: StateContext<ZooStateModel>) {
const state = ctx.getState();
ctx.setState({
...state,
feed: !state.feed
});
}
}
Я изучаю ngxs из gitbook, вышеприведенный блок скопирован оттуда. В этом примере ...state
назначено объекту. зачем нам это? поэтому у нас есть только один фид свойств объекта и уже назначено feed: !state.feed