Open samskiter opened 2 months ago
This works, but the above indexing doesn't:
arrayActions.set(todoStore.todos, index, new Todo({
done: true,
}))
todoStore.todos[index].setDone(true)
should work
Aha - I wonder if it's related to this: https://github.com/xaviergonz/mobx-keystone/issues/173
My todo was created like
export class Todo extends Model({
done: prop<bool>().withSetter(),
}) {
static defaultTodo() {
return new Todo({ done: false })
}
}
export class TodoModel extends Model({
todos: prop<Todo[]>(() => []).withSetter(),
}) {
@modelAction
addNewTodo() {
this.setTodos([...this.todos, Todo.defaultTodo()])
}
But If i change to this, things start working:
export class Todo extends Model({
done: prop<bool>().withSetter(),
})
export class TodoModel extends Model({
todos: prop<Todo[]>(() => []).withSetter(),
}) {
@modelAction
addNewTodo() {
this.setTodos([...this.todos, new Todo({ done: false })])
}
Sounds like you found it :)
Yes, but unsure why a static factory method wouldn't work!
On Mon, 17 Jun 2024, 18:34 Javier Gonzalez, @.***> wrote:
Sounds like you found it :)
— Reply to this email directly, view it on GitHub https://github.com/xaviergonz/mobx-keystone/issues/545#issuecomment-2173961494, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJWOW3EGF6KAM4SOISRURLZH4MYRAVCNFSM6AAAAABJOMQEFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZTHE3DCNBZGQ . You are receiving this because you authored the thread.Message ID: @.***>
It works if you use anything other than babel to transpile the legacy decorators (e.g. typescript compiler) and potentially it might work even with babel if you use the new decorators.
Hrmm, I'm not consciously using Babel - I've never even heard of it. Can you point me at something to read up?
On Mon, 17 Jun 2024, 19:14 Javier Gonzalez, @.***> wrote:
It works if you use anything other than babel to transpile the legacy decorators (e.g. typescript compiler) and potentially it might work even with babel if you use the new decorators.
— Reply to this email directly, view it on GitHub https://github.com/xaviergonz/mobx-keystone/issues/545#issuecomment-2174031977, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJWOW3FSNG6CZUUNGHSVDDZH4RRJAVCNFSM6AAAAABJOMQEFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZUGAZTCOJXG4 . You are receiving this because you authored the thread.Message ID: @.***>
Is mutating an item inside of an array, like this
todoStore.todos[index].setDone(true)
supported?I'm finding that this isn't consistently working, especially after first adding a new Todo to the model