An open-source entry in TopGit's GitHub warehouse: localForage/localForage-observable, 87 stars, TypeScript. Observables for localForage
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Adds observables to localForage, providing a way to get notified whenever:
a method that affects the database is invoked
the value associated with a specific key changes
Requirements
localForage v1.4.0+
zen-observable (used by default) or RxJS 5
Usage
Currently localForage Observables should only be created after localforage.ready(), so that localForage completes the initialization of the requested (or best matching) driver. Moreover, Observables will stop working in case you change the driver in use, after their creation.
Observe for changes with newObservable()
Creates an observable and subscribes to DB changes.
With this method Subscribers get notified with a LocalForageObservableChange object.
This method can be invoked with a LocalForageObservableOptions object as optional argument.
var observable = localforage.newObservable({
key: 'testKey'
});
var subscription = observable.subscribe({
next: function(args) {
console.log('testKey has changed to:', args.newValue);
}
});
Observe specific method calls
var observable = localforage.newObservable({
// setItem: false,
removeItem: true,
clear: true
});
var subscription = observable.subscribe({
next: function(args) {
console.log(args.methodName + ' was called!');
}
});
Get a "live" Observable of a DB Item Value with getItemObservable(key)
Creates an observable for a specific key that returns the current DB value and every new saved value.
With this method Subscribers receive the initial and ongoing DB values for a specific key as it changes.
This method can be invoked with a LocalForageObservableOptions object as extra optional argument.
Deep value change detection is enabled by default. This way our Observable Subscribers get notified only when the value of the associated key actually changes. Obviously, deep equality checking adds some extra overhead, so in case that all you need is to get notified on any attempt to change a value, you can easily disable value checking:
var observable = localforage.newObservable({
key: 'testKey',
changeDetection: false
});
Cross-Tab Observables #5
Cross-tab event emission, observation and value change detection are disabled by default.
In order to enable it, you have to:
call the configObservables() method to start emmiting cross-tab events:
create observables with cross-tab observation enabled:
var observable = localforage.newObservable({
crossTabNotification: true,
changeDetection: false
});
The arguments passed to cross-tab observable callbacks, will also have the crossTabNotification property set.
Cross-tab change detection
Cross-tab observation with change detection is also supported, but with some limitations.
The arguments passed to the callback will have the valueChange property set to true but:
the oldValue will always be null and
the newValue will hold the value retrieved from the local db at the time that the notification arrived.
In that case you can use:
You can actually use any library compatible with the ES Observable spec proposal. For example, in order to make localForage-observable use the Observables of the RxJS, all you have to do is change the provided Observable Factory method:
localforage.newObservable.factory = function (subscribeFn) {
return Rx.Observable.create(subscribeFn);
};
TypeScript
First of all, include localforage with an import statement appropriate for your configuration and import localforage-observable right after it.
Normally, localforage-observable will extend the prototype of locaforage to include newObservable() etc, but unfortunately the typings can't be updated. As a result you should use the exported extendPrototype() method, which returns the provided localforage instance but with inherited typings that also include the extra methods of localforage-observable.
import localForage from "localforage";
// OR based on your configuration:
// import * as localForage from "localforage";
import { extendPrototype } from "localforage-observable";
var localforage = extendPrototype(localForage);
localforage.ready().then(() => {
// TypeScript will find `newObservable()` after the casting that `extendPrototype()` does
var observable = localforage.newObservable();
});
Does localForage/localForage-observable have a project website?
No homepage URL was recorded for localForage/localForage-observable in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
Does localForage/localForage-observable have any tags?
TopGit's last sync did not record any GitHub topics for localForage/localForage-observable. GitHub topics appear in the right sidebar of a repository page; that's the authoritative place to check.
How active is development on localForage/localForage-observable?
The most recent commit recorded on localForage/localForage-observable was 6.3 years ago, based on the GitHub push timestamp. The repository has 3 forks — one of the better signals of community interest.
Is localForage/localForage-observable open source?
TopGit's metadata for localForage/localForage-observable does not record a license. Most public repositories on GitHub ARE open source, but the exact terms vary — verify by opening the LICENSE file directly.
Where do I read more about localForage/localForage-observable?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/localForage/localForage-observable is the definitive source.
Read full README in the tab above.
Want a second opinion on localForage-observable?
Ask an AI that can read this page — one click and you get its take on localForage-observable.