NGXS
Github
Slack
Questions
Search…
Latest Release
Introduction
Getting Started
Concepts
Advanced
Action Handlers
Actions Life Cycle
Cancellation
Composition
Error Handling
Ivy Migration Guide
Lazy Loading
Life-cycle
Mapped Sub States
Meta Reducers
Optimizing Selectors
Options
Shared State
State Token
State Operators
Sub States
Recipes
Plugins
NGXS Labs
Community
Changelog
Powered By
GitBook
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.
Previous
Cancellation
Next
Error Handling
Last modified
2yr ago
Copy link