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

Add patch functionality to lists #691

Merged
merged 9 commits into from
Jan 15, 2021
Merged

Add patch functionality to lists #691

merged 9 commits into from
Jan 15, 2021

Conversation

jpope19
Copy link
Contributor

@jpope19 jpope19 commented Dec 10, 2020

No description provided.

async function addToList(uri, data) {
// do a db call for the list
const list = await db.get(uri),
added = list.concat(data);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to make sure the item being added to the list isn't already there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supposedly we want to allow dupes... which makes add / delete a little difficult. decided to allow dupes to be added, and deletion will remove all duplicates.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah Chris lists aren't sets as far as clay is concerned i.e. they don't have semantics for duplicates, so dupes should be allowed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will this work with components like tags which has a count?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is count used anywhere ? afaik it's only tracked, and I don't think it's tracked very well. At least I remember it being inaccurate.

If we care about count then a generic clay list isn't a good structure for this since there's no good way to update it while taking into account concurrent modifications. A new structure with an identifier would be necessary.

* @param {Array<Object>} data
* @returns {Promise}
*/
function patchList(uri, data) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be the first time I've seen PATCH implemented correctly haha

}

if (list.length === startLength) {
throw new Error('Nothing was removed from the list.');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I feel throwing an error in this case will prove more trouble than it's worth. Like if two editors end up removing the same item from the list that should work just fine rather than cause a 500.

not a strong opinion though

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would tend to agree here. If the goal is to have it removed, it was already achieved.

@jpope19 jpope19 changed the title [WIP] add patch functionality to lists Add patch functionality to lists Dec 14, 2020
@mrollinsiv
Copy link

Is there a PR or matching ticket to update Kiln to utilize PATCH instead of doing a PUT of the entire list?

@jpope19
Copy link
Contributor Author

jpope19 commented Jan 4, 2021

Is there a PR or matching ticket to update Kiln to utilize PATCH instead of doing a PUT of the entire list?

clay/clay-kiln#1511

@jpope19 jpope19 merged commit cd67636 into master Jan 15, 2021
@jpope19 jpope19 deleted the modify-lists branch January 15, 2021 15:54
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

Successfully merging this pull request may close these issues.

5 participants