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

Direct Store Mutation #6

Open
pmattmann opened this issue Nov 14, 2020 · 1 comment
Open

Direct Store Mutation #6

pmattmann opened this issue Nov 14, 2020 · 1 comment

Comments

@pmattmann
Copy link
Member

Mutate Store without any server-request.
Allows optimistic updates on clientside

@usu
Copy link
Member

usu commented Apr 18, 2021

Maybe at least for $post we could let hal-json-vuex handle this automatically.

Use case:

let materialItems = this.api.get().materialItems({ contentNodeId: this.contentNode.id })
let newItemData = { article: "Tent" }

materialItems.$postEager(newItemData)

// at this point, materialItems already contains the new item with a temporary uri (simple hash)
// including a flag, e.g. item._meta.isPersisted = false (or similary)

materialItems.items[materialItems.length-1]._meta.self // --> 5ffd3cb97f651a73502429df51c439cd
materialItems.items[materialItems.length-1]._meta.isPersisted // --> false
materialItems.items[materialItems.length-1]._meta.isSaving // --> true
materialItems.items[materialItems.length-1].article // --> Tent

If the network request comes back successfully, the item is updated with the correct uri (of course only in the list above). Otherwise, the temporary entity is removed from the store.

Alternative: temporary key is only used internally and not exposed via _meta.self?

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