ecamp / ecamp/hal-json-vuex

Auto-reload collection after POSTing

Open
#93 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
8
Forks
3
PR merge metrics
No merged PRs in 30d

Description

With POST requests, the semantic implication is often that we POST to a collection, and the response contains a newly created entity that has a new self URI. In this case, the collection in the store will not contain the new entity after the response has arrived.

We could consider adding a configurable option or flag to the `post` / `$post` functions that allows to automatically reload the collection after the POST request has completed. This seems like a usual pattern that hal-json-vuex users would have to do manually otherwise, and it would be similar to the behaviour of `delete`, where we reload any collection and entity that "know" the deleted entity.

We should probably only reload the collection if it was loaded in the store already.

Thoughts on this? I'd imagine to use it like this:
```js
// will automatically reload /books after the POST was successful
this.api.get().books().$post({ name: 'Moby Dick' })

// disable auto-reloading the collection
this.api.get().books().$post({ name: 'Winnetou' }, { reload: false })

this.api.purgeAll()
// will not reload the whole /books collection when we don't already know it
// (at the point in time after the POST request has finished)
this.api.post(await this.api.get().$href('books'), { name: 'Harry Potter' })
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the post/$post entry points and compare their behavior with delete, focusing on how the Vuex store tracks loaded collections. Define the reload option shown in the examples, reload an already-known collection after a successful POST, and leave unknown collections untouched; verify the behavior through the project's existing tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.