Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the ID of an item in a list. #9778

Closed
shadow7412 opened this issue Mar 26, 2019 · 1 comment
Closed

Update the ID of an item in a list. #9778

shadow7412 opened this issue Mar 26, 2019 · 1 comment

Comments

@shadow7412
Copy link

What problem does this feature solve?

The issue is described here: https://stackoverflow.com/questions/55292425/can-you-change-an-items-id-in-vue-js

The problem is when you create an item on the front-end, you want to show that item as soon as practical. Immediately is optimal. But to do that, you need to assign a temporary ID until the backend responds with the actual one.

Currently, by updating an iD, you are signalling to vue that the original object has been removed, and a new one with this other ID has been added. This triggers an in and out animation that isn't desired in my case.

What does the proposed API look like?

I imagine it'd be similar to $set, but with some form of explicit mention of "calm down, I'm not changing which object this is".

You could probably use $set with an extra argument, such as:

$set(item, "ID", 1234, true)

Alternatively, a brand new function could be appropriate.

$setInPlace(item, "ID", 1234)

Or instead of giving an item the ID directly, perhaps a wrapper would be more appropriate:

let newItem = {
    ID: TemporaryID()
}

// ... later ...

item.ID(realID)
@Justineo
Copy link
Member

Then just don’t use your ID as key because it’s how Vue tracks unique item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants