Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
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

Expand Down