-
-
Notifications
You must be signed in to change notification settings - Fork 96
feat: Add schema.Collection #2593
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
Conversation
🦋 Changeset detectedLatest commit: 62d48bb The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -87,7 +89,7 @@ | |||
localCacheKey[pk] = INVALID; | |||
} else { | |||
if (typeof schema.denormalizeOnly === 'function') { | |||
localCacheKey[pk] = schema.denormalizeOnly(entityCopy, unvisit); | |||
localCacheKey[pk] = schema.denormalizeOnly(entityCopy, args, unvisit); |
Check warning
Code scanning / CodeQL
Prototype-polluting assignment
f190842
to
dcda13e
Compare
8bbe78e
to
6c0f8ae
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #2593 +/- ##
==========================================
- Coverage 98.06% 97.98% -0.08%
==========================================
Files 131 135 +4
Lines 2165 2287 +122
Branches 328 357 +29
==========================================
+ Hits 2123 2241 +118
Misses 19 19
- Partials 23 27 +4
☔ View full report in Codecov by Sentry. |
f623b85
to
2146759
Compare
fix: changes to
Will update with insertions in a follow up PR |
Fixes #2566, #1548, #2602, #2553, #2554, #428, #398, #358 .
Motivation
Atomic mutations are one of the core values of Rest Hooks. However, while update was in the first pre-release, and delete quickly added for version 1, create has always been a bit awkward.
Often creating a new element you are on a view where you want to see it added to a list somewhere.
One of the challenges here is that there can be many distinct lists you view. Furthermore, where something is added to a list isn't always the same.
Previously
https://resthooks.io/docs/concepts/atomic-mutations#create
Problems:
TODO
Solution
Collections: Entities but for Arrays and Values instead of classes.
They literally are entities, so they get normalized as such. They just have different lifecycle implementations.
Inspiration: Backbone collections
Usage
This will add to these if they are already in store (but only if they already exist):
Collection
construction
Takes Array or Values as first arg. Second arg is options object.
Options:
Must provide argsKey or nestKey to compute a serializable object to be used in PK table. argsKey takes ...args and nestKey takes (parent,key) as inputs.
createCollectionFilter
is optional and can be used to override the default filter algorithm. This is used by the "adders" as they inherit from the collection.addWith(merge, createCollectionFilter)
This is the general
collection extender
method. All specializations simply call this method. This is also used in the paginator as it has a custom algorithm.merge
overrides theEntity.merge()
algorithm. This is used to determine where new values are placed (end, beginning, somewhere in the middle?)createCollectionFilter
is optional and will override the inherited function from the Collection itself.push/unshift/assign
These all call addWith() with variations on merge to place newly created objects at the beginning or end respectively for Arrays.
assign
is for Values() and simply merges (there is no concept of order in Values)RestEndpoint adder specializations
For a RestEndpoint containing a collection schema, the extenders
push/unshift/assign
can be used as convenience to create an appropriate endpoint. They use the parent schema, but us their respectiveaddWith()
variations. Additionally this sets themethod
to "POST".Pagination
.paginated() now detects whether there is a collection or array. With collections it will use a custom extender. Arrays will work via update.
new .paginated('cursor') - 99% of paginations simply extract one field from the args. Let the user specify that field name rather than writing a whole function.
Normalizr changes
args
are now part of both normalization and denormalization. Of course these will default to an empty array in case users don't need args. However, they will need to be passed on my implementations such as schema.normalize(). This shouldn't be a problem as schema implementations without it wont be expecting it anyway.pk()
now takes a fourth argument - args.next/createResource
searchParams
only applies to getList and create.body
only applies to update,create,partialUpdate