Composition
You can compose multiple stores together using class inheritance. This is quite simple:
1
@State({
2
name: 'zoo',
3
defaults: {
4
type: null
5
}
6
})
7
@Injectable()
8
class ZooState {
9
@Action(Eat)
10
eat(ctx: StateContext) {
11
ctx.setState({ type: 'eat' });
12
}
13
}
14
15
@State({
16
name: 'stlzoo'
17
})
18
@Injectable()
19
class StLouisZooState extends ZooState {
20
@Action(Drink)
21
drink(ctx: StateContext) {
22
ctx.setState({ type: 'drink' });
23
}
24
}
Copied!
Now when StLouisZooState is invoked, it will share the actions of the ZooState. Also all state options are inherited.
Last modified 1yr ago
Copy link