Open thombruce opened 3 months ago
Note: This is not merely a case of adding a default value for the prop on the toast component. That won't be available at the time of the toast being added to the stack.
It needs to be added along with the Toast data at the moment it is being added to the toasts store.
For this, I think a model with default attributes is called for.
Feature request
Working on #85, I added a toast to announce the deletion of a file. I provided no ID so after the timeout, the toast could not be removed from the stack.
The ID is required but... I don't know why we don't just generate one by default.
In the docs we recommend using Lodash
_uniqueId
. Maybe I feared this could end up in collisions I wasn't prepared to handle.Also... the recommended approach is this:
...but
_uniqueId()
accepts a prefix argument. This would be equivalent:I don't think we need to worry about collisions when using
_uniqueId()
, not unless we tried to persist the value and recall it in a different session. It's really a question of... does Lodash track state for the incremental value?The answer... is no, but... well, sort of. It increments a variable - that's all it does. So long as each new ID is generated in the same instance, it will work fine. JS is single threaded, right? We aren't offloading the responsibility for these IDs to a non-renderer process...
If there are collisions, we'll install and make use of nanoID instead, but I think we'll be fine sticking with
_uniqueId()
for now.Code of Conduct