Nested Model Question
See original GitHub issueThis is a question not an issue, but I would be glad to get your comments.
If we have to model a one-to-many relation, where both models have specific actions, let’s say:
const childModel = {
id: "",
parent: "",
items: {},
addItem: action( (state, payload) => {
state.items[payload.id} = payload;
),
removeItem: action( (state, id) => {
delete state.items[id};
)
};
const parentModel = {
id: "",
children: {},
addChild: action( (state, payload) => {
state.children[payload.id] = {...childModel, ...payload, parent:state.id}; // :)
})
};
This doesn’t work as it is. I am using something like this:
const parentModel = {
id: "",
children: {},
addChild: action( (state, payload) => {
state.children[payload.id] = createStore( {...childModel, ...payload, parent:state.id} );
})
};
That allows me to write things like:
parent.children[id].addItem({id: 1, name: "pees"})
which is nice!
However the state tree has to be computed:
Object.values(parent.children).map(child => child.getState())
which feels wrong 😕
If anyone has a similar issue solved more elegantly I would love to see it!
Thank you!
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Newest 'nested-models' Questions - Cross Validated
Is it safe to enter the consulate/embassy of the country I escaped from as a refugee? Why don't courts punish time-wasting tactics? What...
Read more >F-tests and Nested Models - Rose-Hulman
Nested Models : A core concept in statistics is comparing nested models. ... The fundamental question with respect to this model is whether...
Read more >Nested Model, ANOVA and Factors - Statistics How To
What is a Nested Model? Very simply, “nested” means that one model is a subset of another. For example, take a model for...
Read more >Model Selection Tests For Nested And Non-nested ...
The nature of the model selection test depends on whether the two models A and B are nested versus non-nested. If model B...
Read more >198 questions with answers in NESTED | Science topic
Im struggling to find what statistical test to use, and how to set up the data. Do I do individual tests for each...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hmmmm, you certainly have me thinking. I will continue to do so and if I think of anything interesting I’ll feed back to you here. 🙏
Hey @ctrlplusb,
Here is a sample showing the difference between nested models added at “design time” and those added at “run-time” :
https://codesandbox.io/s/easy-peasy-nested-1d1rw