like this:
attrs: {
_id: {
default: uuidv4(),
}
},
but it not work
like this:
attrs: {
_id: {
default: uuidv4(),
}
},
but it not work
No, default attribute values are just values, they don’t get recomputed for every node. See this thread for similar discussion.
It’s not an elegant solution
Now I use other ways to solve the problem, without using ID.
Any reason for making default values as values only?
What if we allow specifying a generator like function which would compute the default whenever the node is created? Example,
attrs: {
_id: {
default: () => uuidv4(),
}
},
I know this is not there in the current version. But any thoughts around support for something like this in future?
The library had something like that at one point, but making node creation non-pure caused all kinds of awkwardness, often did the wrong thing, and still didn’t help with splitting nodes, so it was removed.