I have:
resolveIdentifier working: changeSelectedItem(uid: string) {
// Working in MST3.0.2
const item = resolveIdentifier(CommentModel, self.items, uid);
console.log("item", item && item.toJSON());
const item2 = self.items.find(i => i.uid === uid);
console.log("item2", item2 && item2.toJSON());
self.selectedItem = item;
}
Regression issue: After upgrading to MST3.2.2 resolveIdentifier returns undefined
https://codesandbox.io/s/294ylryp0
_Not following the above template might result in your issue being closed without further notice_
I took a look into it, it seems your id generator does not pass the test for the TOptionalId refinement
nevermind, it seems to be about the identifier being optional with a function, looking further into it
unit test
```ts
test("#1019", () => {
function randomUuid() {
return "1bbc17fd-2068-4cc9-aff0-82d37c9cdf20"
}
const CommentModel = types.model("CommentModel", {
uid: types.optional(types.identifier, randomUuid)
})
const CommentStore = types
.model("CommentStore", {
items: types.array(CommentModel)
})
.actions(self => {
function test() {
const comment = CommentModel.create({})
expect(comment.uid).toBe(randomUuid())
self.items.push(comment)
const item = resolveIdentifier(CommentModel, self.items, comment.uid)
const item2 = self.items.find(i => i.uid === comment.uid)
expect(item).toBe(item2)
}
return {
test
}
})
CommentStore.create({}).test()
})
````
I had a similar (I think) issue today, a minimal repro is
const Item = types
.model({
id: types.optional(types.identifier, 'dummykey'),
})
console.log(getIdentifier(Item.create())) // undefined, should be 'dummykey'
The PR I just opened should fix both issues
should be fixed in the recently released 3.4.0
Most helpful comment
The PR I just opened should fix both issues