From 10eeeff38fc2f479488cfef10b9d4c56d0d7f32f Mon Sep 17 00:00:00 2001 From: Matthieu Fesselier <matthieu.fesselier@gmail.com> Date: Tue, 12 May 2020 09:27:45 +0200 Subject: [PATCH] add store documentation --- source/import_documentation/Store-doc.rst | 114 ++++++++++++++++++++++ source/index.rst | 1 + 2 files changed, 115 insertions(+) create mode 100644 source/import_documentation/Store-doc.rst diff --git a/source/import_documentation/Store-doc.rst b/source/import_documentation/Store-doc.rst new file mode 100644 index 0000000..0a9e6a8 --- /dev/null +++ b/source/import_documentation/Store-doc.rst @@ -0,0 +1,114 @@ +Store documentation +==================== + +The store is responsible for the communication between the framework and the servers. You may need to use some of its functions. +To use the store in your application, make sure to import it from the root of sib-core (ie: `import { store } from 'https://unpkg.com/@startinblox/core';`). + + +API Reference +------------- + + +`getData` (`async`) +^^^^^^^^^^^^^^^^^^^ + +Fetch and cache the data for a resource + +**parameters** +- `id: string`: uri of the resource +- `context: object` (optional): used to expand the `id` and to access the resource predicates from a compact form + +**returns** +- `resource: Proxy` + + +`get` +^^^^^ + +Synchronously returns a resource from the cache. + +**parameters** +- `id: string`: uri of the resource + +**returns** +- `resource: Proxy`: or `null` if the resource is not in cache + + +`post` (`async`) +^^^^^^^^^^^^^^^^ + +Send a POST request to create a resource in a container. When the request succeed, the resource is cleared from the cache, and the components showing it are notified. + +**parameters** +- `resource: object`: values of the resource to create +- `id: string`: uri of the container + +**returns** +- `resourceId: string`: id of the created resource + + +`put` (`async`) +^^^^^^^^^^^^^^^ + +Send a PUT request to edit a resource. When the request succeed, the resource is cleared from the cache, and the components showing it are notified. + +**parameters** +- `resource: object`: new values of the resource to edit +- `id: string`: uri of the resource + +**returns** +- `resourceId: string`: id of the edited resource + + +`patch` (`async`) +^^^^^^^^^^^^^^^^^ + +Send a PATCH request to edit a resource. When the request succeed, the resource is cleared from the cache, and the components showing it are notified. + +**parameters** +- `resource: object`: new values of the resource to edit +- `id: string`: uri of the resource + +**returns** +- `resourceId: string`: id of the edited resource + + +`delete` (`async`) +^^^^^^^^^^^^^^^^^^ + +Send a DELETE request to delete a resource. When the request succeed, the resource is cleared from the cache, and the components showing it are notified. + +**parameters** +- `id: string`: uri of the resource to delete +- `context: object` (optional): used to expand the id if needed + +**returns** +- `resourceId: string`: id of the deleted resource + + +`subscribeTo` +^^^^^^^^^^^^^ + +Make a resource listen another one. When a change is detected on a resource, all the resources which are listening are removed from the cache, and the component showing them are notified to re-render their content. + +**parameters** +- `resourceToUpdate`: resource which needs to be updated when another one change +- `resourceToListen`: resource on which listen for changes + + +`clearCache` +^^^^^^^^^^^^ + +Manually remove a resource from the cache + +**parameters** +- `id`: uri of the resource to remove from the cache + + +Store reactivity +---------------- + +The store is reactive. It means that any change you make on a resource in your app will be reflected in the interface automatically. +However, there are some limitations: +- If you make some changes on a resource which is in a virtual container, other virtual containers including this resource may not be updated. (ie: POST on circles/1/members does not update users/admin/circles/) +- If a resource a multi nested field is displayed in a component, it may not be updated. (ie: in a `sib-display`, I display `nestedResource.user.name` from `resource`, changing `user` will not update the display) \ No newline at end of file diff --git a/source/index.rst b/source/index.rst index 85491e1..974b712 100644 --- a/source/index.rst +++ b/source/index.rst @@ -61,6 +61,7 @@ Welcome to Startinblox's documentation! :caption: Javascript Api: import_documentation/Helpers-functions + import_documentation/Store-doc -- GitLab