How to use the dexie.extend 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 / addons / Dexie.Observable / src / Dexie.Observable.js View on Github external
} else {
                    request.resolve(msg.message.result);
                }
                delete requestsWaitingForReply[msg.requestId.toString()];
            }
        } else {
            // This is a message or request. Fire the event and add an API for the subscriber to use if reply is requested
            msg.resolve = function(result) {
                db.sendMessage('response', { result: result }, msg.sender, { requestId: msg.id });
            };
            msg.reject = function(error) {
                db.sendMessage('response', { error: error.toString() }, msg.sender, { isFailure: true, requestId: msg.id });
            };
            var message = msg.message;
            delete msg.message;
            Dexie.extend(msg, message);
            db.on.message.fire(msg);
        }
    }
github dfahlander / Dexie.js / addons / Dexie.Observable / src / Dexie.Observable.js View on Github external
} else {
                    request.resolve(msg.message.result);
                }
                delete requestsWaitingForReply[msg.requestId.toString()];
            }
        } else {
            // This is a message or request. Fire the event and add an API for the subscriber to use if reply is requested
            msg.resolve = function(result) {
                db.sendMessage('response', { result: result }, msg.sender, { requestId: msg.id });
            };
            msg.reject = function(error) {
                db.sendMessage('response', { error: error.toString() }, msg.sender, { isFailure: true, requestId: msg.id });
            };
            var message = msg.message;
            delete msg.message;
            Dexie.extend(msg, message);
            db.on.message.fire(msg);
        }
    }
github dfahlander / Dexie.js / addons / Dexie.Observable / src / intercomm.js View on Github external
db.observable.sendMessage = function (type, message, destinationNode, options) {
    /// Type of message
    /// Message to send
    /// ID of destination node
    /// {wantReply: Boolean, isFailure: Boolean, requestId: Number}. If wantReply, the returned promise will complete with the reply from remote. Otherwise it will complete when message has been successfully sent.
    options = options || {};
    if (!mySyncNode.node)
      return options.wantReply ?
          Promise.reject(new Dexie.DatabaseClosedError()) :
          Promise.resolve(); // If caller doesn't want a reply, it won't catch errors either.

    var msg = {message: message, destinationNode: destinationNode, sender: mySyncNode.node.id, type: type};
    Dexie.extend(msg, options); // wantReply: wantReply, success: !isFailure, requestId: ...
    return Dexie.ignoreTransaction(()=> {
      var tables = ["_intercomm"];
      if (options.wantReply) tables.push("_syncNodes"); // If caller wants a reply, include "_syncNodes" in transaction to check that there's a receiver there. Otherwise, new master will get it.
      var promise = db.transaction('rw', tables, () => {
        if (options.wantReply) {
          // Check that there is a receiver there to take the request.
          return db._syncNodes.where('id').equals(destinationNode).count(receiverAlive => {
            if (receiverAlive)
              return db._intercomm.add(msg);
            else // If we couldn't find a node -> send to master
              return db._syncNodes.where('isMaster').above(0).first(function (masterNode) {
                msg.destinationNode = masterNode.id;
                return db._intercomm.add(msg)
              });
          });
        } else {
github dfahlander / Dexie.js / addons / Dexie.Observable / src / Dexie.Observable.js View on Github external
db.sendMessage = function(type, message, destinationNode, options) {
        /// Type of message
        /// Message to send
        /// ID of destination node
        /// {wantReply: Boolean, isFailure: Boolean, requestId: Number}. If wantReply, the returned promise will complete with the reply from remote. Otherwise it will complete when message has been successfully sent.
        if (!mySyncNode) return Promise.reject("Database closed");
        options = options || {};
        var msg = { message: message, destinationNode: destinationNode, sender: mySyncNode.id, type: type };
        Dexie.extend(msg, options); // wantReply: wantReply, success: !isFailure, requestId: ...
        var tables = ["_intercomm"];
        if (options.wantReply) tables.push("_syncNodes"); // If caller wants a reply, include "_syncNodes" in transaction to check that there's a reciever there. Otherwise, new master will get it.
        return db.transaction('rw?', tables, function() {
            if (options.wantReply) {
                // Check that there is a reciever there to take the request.
                return db._syncNodes.where('id').equals(destinationNode).count(function(recieverAlive) {
                    if (recieverAlive)
                        return addMessage(msg);
                    else
                        return db._syncNodes.where('isMaster').above(0).first(function(masterNode) {
                            msg.destinationNode = masterNode.id;
                            return addMessage(msg);
                        });
                });
            } else {
                addMessage(msg); // No need to return Promise. Caller dont need a reply.
github dfahlander / Dexie.js / addons / Dexie.Observable / dist / dexie-observable.es6.js View on Github external
} else {
                    request.resolve(msg.message.result);
                }
                delete requestsWaitingForReply[msg.requestId.toString()];
            }
        } else {
            // This is a message or request. Fire the event and add an API for the subscriber to use if reply is requested
            msg.resolve = function (result) {
                db.sendMessage('response', { result: result }, msg.sender, { requestId: msg.id });
            };
            msg.reject = function (error) {
                db.sendMessage('response', { error: error.toString() }, msg.sender, { isFailure: true, requestId: msg.id });
            };
            var message = msg.message;
            delete msg.message;
            Dexie.extend(msg, message);
            db.on.message.fire(msg);
        }
    }
github dfahlander / Dexie.js / addons / Dexie.Observable / dist / dexie-observable.es6.js View on Github external
db.sendMessage = function (type, message, destinationNode, options) {
        /// Type of message
        /// Message to send
        /// ID of destination node
        /// {wantReply: Boolean, isFailure: Boolean, requestId: Number}. If wantReply, the returned promise will complete with the reply from remote. Otherwise it will complete when message has been successfully sent.
        if (!mySyncNode) return Promise.reject("Database closed");
        options = options || {};
        var msg = { message: message, destinationNode: destinationNode, sender: mySyncNode.id, type: type };
        Dexie.extend(msg, options); // wantReply: wantReply, success: !isFailure, requestId: ...
        var tables = ["_intercomm"];
        if (options.wantReply) tables.push("_syncNodes"); // If caller wants a reply, include "_syncNodes" in transaction to check that there's a reciever there. Otherwise, new master will get it.
        return db.transaction('rw?', tables, function () {
            if (options.wantReply) {
                // Check that there is a reciever there to take the request.
                return db._syncNodes.where('id').equals(destinationNode).count(function (recieverAlive) {
                    if (recieverAlive) return addMessage(msg);else return db._syncNodes.where('isMaster').above(0).first(function (masterNode) {
                        msg.destinationNode = masterNode.id;
                        return addMessage(msg);
                    });
                });
            } else {
                addMessage(msg); // No need to return Promise. Caller dont need a reply.
            }

            function addMessage(msg) {
github dfahlander / Dexie.js / addons / Dexie.Observable / src / Dexie.Observable.js View on Github external
db.sendMessage = function(type, message, destinationNode, options) {
        /// Type of message
        /// Message to send
        /// ID of destination node
        /// {wantReply: Boolean, isFailure: Boolean, requestId: Number}. If wantReply, the returned promise will complete with the reply from remote. Otherwise it will complete when message has been successfully sent.
        if (!mySyncNode) return Promise.reject("Database closed");
        options = options || {};
        var msg = { message: message, destinationNode: destinationNode, sender: mySyncNode.id, type: type };
        Dexie.extend(msg, options); // wantReply: wantReply, success: !isFailure, requestId: ...
        var tables = ["_intercomm"];
        if (options.wantReply) tables.push("_syncNodes"); // If caller wants a reply, include "_syncNodes" in transaction to check that there's a reciever there. Otherwise, new master will get it.
        return db.transaction('rw?', tables, function() {
            if (options.wantReply) {
                // Check that there is a reciever there to take the request.
                return db._syncNodes.where('id').equals(destinationNode).count(function(recieverAlive) {
                    if (recieverAlive)
                        return addMessage(msg);
                    else
                        return db._syncNodes.where('isMaster').above(0).first(function(masterNode) {
                            msg.destinationNode = masterNode.id;
                            return addMessage(msg);
                        });
                });
            } else {
                addMessage(msg); // No need to return Promise. Caller dont need a reply.
github dfahlander / Dexie.js / addons / Dexie.Syncable / src / Dexie.Syncable.js View on Github external
function PersistedContext(nodeID, otherProps) {
                        this.nodeID = nodeID;
                        if (otherProps) Dexie.extend(this, otherProps);
                    }