Replies: 1 comment
-
Unfortunately, the MST
(Note my code doesn't account for possible duplicate keys in the map). But, since MST is already good at reference resolution, I tend to reach for this approach before building intermediate "reference maps". In the particular example, I might model it a little differently: import { types } from "mobx-state-tree"
const Thing = types.model({
id: types.identifier,
description: types.string
})
const Opinion = types.model({
id: types.identifierNumber,
comment: types.string,
thing: types.reference(Thing)
})
const Person = types.model({
name: types.identifier,
opinions: types.map(Opinion)
})
const Store = types.model({
things: types.map(Thing),
people: types.map(Person)
})
const store = Store.create({
things: {
vanilla: { id: "vanilla", description: "vanilla" },
chocolate: { id: "chocolate", description: "chocolate" }
},
people: {
john: {
name: "john",
opinions: {
1: { id: 1, comment: "I don't like vanilla", thing: "vanilla" }
}
}
}
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I constantly come up against the requirement to have a map that has reference keys rather than string keys. Is there some way to achieve that in MST? See below for the kind of thing I'm looking for:
Thanks for any help.
P.S. - I've hacked together some stuff that approximates what I need like the thing below, but it's pretty hacky and would require some more work to make it reliable, so I was wondering if there was a more establisher approach (seems like it would be a common requirement)
Beta Was this translation helpful? Give feedback.
All reactions