From d5b9f144bc8a0d6ecc2ae38fca02ba8ff0fdba09 Mon Sep 17 00:00:00 2001 From: LFDM <1986gh@gmail.com> Date: Wed, 2 Aug 2017 07:58:30 +0200 Subject: [PATCH 1/3] feat(command) Add it to default invalidatesOn setting --- src/builder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builder.js b/src/builder.js index 6bdfd68..f2dbb4b 100644 --- a/src/builder.js +++ b/src/builder.js @@ -62,7 +62,7 @@ const setEntityConfigDefaults = ec => { return { ttl: 300, invalidates: [], - invalidatesOn: ['CREATE', 'UPDATE', 'DELETE'], + invalidatesOn: ['CREATE', 'UPDATE', 'DELETE', 'COMMAND'], enableDeduplication: true, ...ec }; From 179d773bf6b470dc32277aaebb1e067cd185a9bd Mon Sep 17 00:00:00 2001 From: LFDM <1986gh@gmail.com> Date: Wed, 2 Aug 2017 07:58:41 +0200 Subject: [PATCH 2/3] docs(command) Add documentation --- docs/advanced/Invalidation.md | 2 +- docs/advanced/Plugins.md | 2 +- docs/basics/Configuration.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/advanced/Invalidation.md b/docs/advanced/Invalidation.md index 73cf8bf..458be6d 100644 --- a/docs/advanced/Invalidation.md +++ b/docs/advanced/Invalidation.md @@ -33,7 +33,7 @@ const config = { ttl: 300, api: gameApi, invalidates: ['topList'], - invalidatesOn: ['UPDATE'] // Default: ['CREATE', 'UPDATE', 'DELETE'] + invalidatesOn: ['UPDATE'] // Default: ['CREATE', 'UPDATE', 'DELETE', 'COMMAND'] } }; ``` diff --git a/docs/advanced/Plugins.md b/docs/advanced/Plugins.md index 8e0fca4..cdf9d76 100644 --- a/docs/advanced/Plugins.md +++ b/docs/advanced/Plugins.md @@ -126,7 +126,7 @@ following shape: ```javascript { - operation: 'CREATE' | 'READ' | 'UPDATE' | 'DELETE' | 'NO_OPERATION', + operation: 'CREATE' | 'READ' | 'UPDATE' | 'DELETE' | 'COMMAND' | 'NO_OPERATION', entity: EntityName, apiFn: ApiFunctionName, args: Any[] | null diff --git a/docs/basics/Configuration.md b/docs/basics/Configuration.md index a8e1ae0..2edd96e 100644 --- a/docs/basics/Configuration.md +++ b/docs/basics/Configuration.md @@ -6,7 +6,7 @@ There are a handful optional options to configure Ladda. In a minimal configurat * **ttl**: How long to cache in seconds. Default is `300` seconds. -* **invalidatesOn**: `[Operation]` where `Operation := "CREATE" | "READ" | "UPDATE" | "DELETE" | "NO_OPERATION"`. Default is `["CREATE", "UPDATE", "DELETE"]`. +* **invalidatesOn**: `[Operation]` where `Operation := "CREATE" | "READ" | "UPDATE" | "DELETE" | "COMMAND" | "NO_OPERATION"`. Default is `["CREATE", "UPDATE", "DELETE", "COMMAND"]`. * **invalidates**: `[EntityName]` where EntityName is the key of your EntityConfig. By default an empty list `[]`. @@ -19,7 +19,7 @@ There are a handful optional options to configure Ladda. In a minimal configurat ## Method Configuration -* **operation**: `"CREATE" | "READ" | "UPDATE" | "DELETE" | "NO_OPERATION"`. Default is `"NO_OPERATION"`. +* **operation**: `"CREATE" | "READ" | "UPDATE" | "DELETE" | "COMMAND" | "NO_OPERATION"`. Default is `"NO_OPERATION"`. * **invalidates**: `[ApiFunctionName]` where ApiFunctionName is a name of another function in the same api (see Entity Configuration - api). By default this is the empty list `[]`. From a6a067fc40cf030b0fa13cf65971cc08aead66ef Mon Sep 17 00:00:00 2001 From: LFDM <1986gh@gmail.com> Date: Wed, 2 Aug 2017 08:00:30 +0200 Subject: [PATCH 3/3] docs(operations) Explain difference between UPDATE and COMMAND some more --- docs/basics/Operations.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/basics/Operations.md b/docs/basics/Operations.md index 8c09a55..05777b3 100644 --- a/docs/basics/Operations.md +++ b/docs/basics/Operations.md @@ -6,10 +6,12 @@ Ladda shows its whole potential in a create, read, update & delete application. * **READ**: An API call which returns an EntityValue, or a list of EntityValues (eg. a user or list of users). -* **UPDATE**: Takes the updated EntityValue as the first argument (eg. a user). No assumptions on what is returned by the server are made. +* **UPDATE**: Takes the updated EntityValue as the first argument (eg. a user). No assumptions on what is returned by the server are made. The first argument provided is used to update the cache. * **DELETE**: Takes an ID as the first argument. No assumptions on what is returned by the server are made. +* **COMMAND**: Takes any arguments and expects an updated EntityValue, or a list of them, as return value. This return value is used to update the cache. + * **NO_OPERATION** : When no operation is specified Ladda will not do anything by default. However, you can still use the invalidation logic of Ladda, see EntityConfig. No assumptions on what is returned by the server are made. An example of how a function of operation CREATE might look is: