How to use the dexie.Observable function in dexie

To help you get started, we’ve selected a few dexie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dfahlander / Dexie.js / test / tests-open.js View on Github external
ok(true, "Could create a dummy database");
        db2 = new Dexie("TestDB");
        return db2.open();
    }).then(function () {
        ok(true, "Dummy Database did exist.");
        db2.close();
    }).catch(function (err) {
        ok(false, "Error: " + err.stack || err);
    }).finally(function () {
        db.delete().then(function () {
            if (db2) return db2.delete();
        }).finally(start);
    });
});

asyncTest("open database without specifying version or schema", Dexie.Observable ? 1 : 10, function () {
    if (Dexie.Observable) {
        ok(true, "Dexie.Observable currently not compatible with this mode");
        return start();
    }
    var db = new Dexie("TestDB");
    var db2 = null;
    db.open().then(function () {
        ok(false, "Should not be able to open a non-existing database when not specifying any version schema");
    }).catch(function (err) {
        ok(true, "Got error when trying to open non-existing DB: " + err);
        // Create a non-empty database that we later on will open in other instance (see next then()-clause)...
        db = new Dexie("TestDB");
        db.version(1).stores({ friends: "++id,name", pets: "++,name,kind" });
        return db.open();
    }).then(function () {
        ok(true, "Could create TestDB with specified version schema.");
github dfahlander / Dexie.js / addons / Dexie.Syncable / src / Dexie.Syncable.js View on Github external
*/

import Dexie from "dexie";
// Depend on 'dexie-observable'
// To support both ES6,AMD,CJS and UMD (plain script), we just import it and then access it as "Dexie.Observable".
// That way, our plugin works in all UMD cases.
// If target platform would only be module based (ES6/AMD/CJS), we could have done 'import Observable from "dexie-observable"'.
import "dexie-observable";

import initSyncableConnect from './syncable-connect';
import initConnectFn from './connect-fn';
import {Statuses, StatusTexts} from './statuses';

var override = Dexie.override,
    Promise = Dexie.Promise,
    Observable = Dexie.Observable;

export default function Syncable (db) {
    /// 

    var activePeers = [];

    const connectFn = initConnectFn(db, activePeers);
    const syncableConnect = initSyncableConnect(db, connectFn);

    db.on('message', function(msg) {
        // Message from other local node arrives...
        Dexie.vip(function() {
            if (msg.type === 'connect') {
                // We are master node and another non-master node wants us to do the connect.
                db.syncable.connect(msg.message.protocolName, msg.message.url, msg.message.options).then(msg.resolve, msg.reject);
            } else if (msg.type === 'disconnect') {
github dfahlander / Dexie.js / addons / Dexie.Observable / src / Dexie.Observable.js View on Github external
Observable._onBeforeUnload = function() {
    Observable.on.beforeunload.fire();
};

Observable.localStorageImpl = global.localStorage;

//
// Map window events to static events in Dexie.Observable:
//
if (global.addEventListener) {
    global.addEventListener("storage", Observable._onStorage);
    global.addEventListener("beforeunload", Observable._onBeforeUnload);
}
// Register addon:
Dexie.Observable = Observable;
Dexie.addons.push(Observable);
github dfahlander / Dexie.js / addons / Dexie.Syncable / src / Dexie.Syncable.js View on Github external
* Disclaimber: This addon is in alpha status meaning that
 * its API and behavior may change.
 *
 */

import Dexie from "dexie";
// Depend on 'dexie-observable'
// To support both ES6,AMD,CJS and UMD (plain script), we just import it and then access it as "Dexie.Observable".
// That way, our plugin works in all UMD cases.
// If target platform would only be module based (ES6/AMD/CJS), we could have done 'import Observable from "dexie-observable"'.
import "dexie-observable"; 

var override = Dexie.override,
    Promise = Dexie.Promise,
    setByKeyPath = Dexie.setByKeyPath,
    Observable = Dexie.Observable;

export default function Syncable (db) {
    /// 

    var activePeers = [];

    // Change Types
    var CREATE = 1,
        UPDATE = 2,
        DELETE = 3;

    // Statuses
    var Statuses = Syncable.Statuses;

    var MAX_CHANGES_PER_CHUNK = 1000;
github dfahlander / Dexie.js / addons / Dexie.Observable / src / Dexie.Observable.js View on Github external
Observable._onBeforeUnload = function() {
    Observable.on.beforeunload.fire();
};

Observable.localStorageImpl = global.localStorage;

//
// Map window events to static events in Dexie.Observable:
//
if (global.addEventListener) {
    global.addEventListener("storage", Observable._onStorage);
    global.addEventListener("beforeunload", Observable._onBeforeUnload);
}
// Register addon:
Dexie.Observable = Observable;
Dexie.addons.push(Observable);
github dfahlander / Dexie.js / addons / Dexie.Observable / dist / dexie-observable.es6.js View on Github external
Observable._onBeforeUnload = function () {
    Observable.on.beforeunload.fire();
};

Observable.localStorageImpl = global.localStorage;

//
// Map window events to static events in Dexie.Observable:
//
if (global.addEventListener) {
    global.addEventListener("storage", Observable._onStorage);
    global.addEventListener("beforeunload", Observable._onBeforeUnload);
}
// Register addon:
Dexie.Observable = Observable;
Dexie.addons.push(Observable);

export default Observable;
//# sourceMappingURL=dexie-observable.es6.js.map