Optionalname: string
The name it is resolved under, in the container and in the snapshot. Defaults to the class name.
The lifetime.
A class decorator.
@FeatureStore('competition')
export class CompetitionStore extends StateStore<CompetitionState> {
private readonly client: CompetitionClient
constructor ({ competitionClient }: { competitionClient: CompetitionClient }) {
super({ list: [], selected: undefined })
this.client = competitionClient
}
async load (): Promise<void> {
this.setState({ list: await this.client.list() })
}
}
Declare a class as a feature's store.
A feature owns its client, its service and its state, and this is how the state half is declared: a class extending
StateStore, holding the actions that move it. Two statements in one, the way every declaration decorator works here:store.<name>, hydrated from the snapshot, and given the per-request lifetime, exactly like a store declared as data.The imperative counterpart is
defineStore(CompetitionStore, { name: 'competition' }), and the two declare the same thing: neither paradigm can do something the other cannot.