From b947416926c72bc9f14bb56c20de5cc15a62f0c8 Mon Sep 17 00:00:00 2001 From: joskarsson Date: Wed, 9 May 2018 14:20:44 +0200 Subject: [PATCH 1/2] Updated README.md with some usage information --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index f62bf7a..0f9e39c 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,27 @@ A [Ladda](https://github.com/ladda-js/ladda) plugin to allow to create observables on all `READ` operation. +## How to use +The observable plugin should work directly with your existing Ladda configuration. However you need to make sure you have the following things configured: +- API-functions need the operation set to `READ` to be observable. +- The other API-functions also need operations set for the observable to be notified of changes. + +An observable can then be created by calling `createObservable` on the API-function to make it observable. You can subscribe to an observable using `subscribe()`. It takes a callback which is called whenever the entity updates. (The callback is called immediately after subscribing, performing an initial `READ` operation if needed.) +```javascript +observable.subscribe(callback); +``` + +`subscribe()` returns a disposable reference that you can use to `unsubscribe()` to the observable. +```javascript +const disposable = observable.subscribe(callback); +... +disposable.unsubscribe(); +``` + +The `subscribe()` method also takes a second callback which is called when an error occurs. +```javascript +observable.subscribe(changeCallback, errorCallback); +``` ## Contribute From 0d27cd630a411518f5f531c34019c04ae5cfbdbe Mon Sep 17 00:00:00 2001 From: joskarsson Date: Wed, 9 May 2018 14:25:16 +0200 Subject: [PATCH 2/2] Updated README.md Updated README to reflect that it's specifically the entity API-functions that need operations --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f9e39c..370f167 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ observables on all `READ` operation. ## How to use The observable plugin should work directly with your existing Ladda configuration. However you need to make sure you have the following things configured: - API-functions need the operation set to `READ` to be observable. -- The other API-functions also need operations set for the observable to be notified of changes. +- The other API-functions for the same Entity also need operations set for the observable to be notified of changes. An observable can then be created by calling `createObservable` on the API-function to make it observable. You can subscribe to an observable using `subscribe()`. It takes a callback which is called whenever the entity updates. (The callback is called immediately after subscribing, performing an initial `READ` operation if needed.) ```javascript