How to use the dexie.setByKeyPath 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
var modsWithoutUndefined = {};
            // As of current Dexie version (1.0.3) hook may be called even if it wouldnt really change.
            // Therefore we may do that kind of optimization here - to not add change entries if
            // there's nothing to change.
            var anythingChanged = false;
            var newObj = Dexie.deepClone(oldObj);
            for (var propPath in mods) {
                var mod = mods[propPath];
                if (typeof mod === 'undefined') {
                    Dexie.delByKeyPath(newObj, propPath);
                    modsWithoutUndefined[propPath] = null; // Null is as close we could come to deleting a property when not allowing undefined.
                    anythingChanged = true;
                } else {
                    var currentValue = Dexie.getByKeyPath(oldObj, propPath);
                    if (mod !== currentValue && JSON.stringify(mod) !== JSON.stringify(currentValue)) {
                        Dexie.setByKeyPath(newObj, propPath, mod);
                        modsWithoutUndefined[propPath] = mod;
                        anythingChanged = true;
                    }
                }
            }
            if (anythingChanged) {
                var change = {
                    source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.
                    table: tableName,
                    key: primKey,
                    type: UPDATE,
                    mods: modsWithoutUndefined,
                    oldObj: oldObj,
                    obj: newObj
                };
                var promise = db._changes.add(change); // Just so we get the correct revision order of the update...
github dfahlander / Dexie.js / addons / Dexie.Observable / dist / dexie-observable.es6.js View on Github external
var modsWithoutUndefined = {};
            // As of current Dexie version (1.0.3) hook may be called even if it wouldnt really change.
            // Therefore we may do that kind of optimization here - to not add change entries if
            // there's nothing to change.
            var anythingChanged = false;
            var newObj = Dexie.deepClone(oldObj);
            for (var propPath in mods) {
                var mod = mods[propPath];
                if (typeof mod === 'undefined') {
                    Dexie.delByKeyPath(newObj, propPath);
                    modsWithoutUndefined[propPath] = null; // Null is as close we could come to deleting a property when not allowing undefined.
                    anythingChanged = true;
                } else {
                    var currentValue = Dexie.getByKeyPath(oldObj, propPath);
                    if (mod !== currentValue && JSON.stringify(mod) !== JSON.stringify(currentValue)) {
                        Dexie.setByKeyPath(newObj, propPath, mod);
                        modsWithoutUndefined[propPath] = mod;
                        anythingChanged = true;
                    }
                }
            }
            if (anythingChanged) {
                var change = {
                    source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.
                    table: tableName,
                    key: primKey,
                    type: UPDATE,
                    mods: modsWithoutUndefined,
                    oldObj: oldObj,
                    obj: newObj
                };
                var promise = trans.tables._changes.add(change); // Just so we get the correct revision order of the update...
github dfahlander / Dexie.js / addons / Dexie.Observable / src / Dexie.Observable.js View on Github external
table.hook('creating').subscribe(function(primKey, obj, trans) {
            /// 
            var rv = undefined;
            if (primKey === undefined && table.schema.primKey.uuid) {
                primKey = rv = Observable.createUUID();
                if (table.schema.primKey.keyPath) {
                    Dexie.setByKeyPath(obj, table.schema.primKey.keyPath, primKey);
                }
            }

            var change = {
                source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.
                table: tableName,
                key: primKey === undefined ? null : primKey,
                type: CREATE,
                obj: obj
            };

            var promise = trans.tables._changes.add(change).then(function(rev) {
                trans._lastWrittenRevision = Math.max(trans._lastWrittenRevision, rev);
                return rev;
            });
github dfahlander / Dexie.js / addons / Dexie.Observable / dist / dexie-observable.es6.js View on Github external
table.hook('creating').subscribe(function (primKey, obj, trans) {
            /// 
            var rv = undefined;
            if (primKey === undefined && table.schema.primKey.uuid) {
                primKey = rv = Observable.createUUID();
                if (table.schema.primKey.keyPath) {
                    Dexie.setByKeyPath(obj, table.schema.primKey.keyPath, primKey);
                }
            }

            var change = {
                source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.
                table: tableName,
                key: primKey === undefined ? null : primKey,
                type: CREATE,
                obj: obj
            };

            var promise = trans.tables._changes.add(change).then(function (rev) {
                trans._lastWrittenRevision = Math.max(trans._lastWrittenRevision, rev);
                return rev;
            });
github dfahlander / Dexie.js / addons / Dexie.Observable / src / Dexie.Observable.js View on Github external
var modsWithoutUndefined = {};
            // As of current Dexie version (1.0.3) hook may be called even if it wouldnt really change.
            // Therefore we may do that kind of optimization here - to not add change entries if
            // there's nothing to change.
            var anythingChanged = false;
            var newObj = Dexie.deepClone(oldObj);
            for (var propPath in mods) {
                var mod = mods[propPath];
                if (typeof mod === 'undefined') {
                    Dexie.delByKeyPath(newObj, propPath);
                    modsWithoutUndefined[propPath] = null; // Null is as close we could come to deleting a property when not allowing undefined.
                    anythingChanged = true;
                } else {
                    var currentValue = Dexie.getByKeyPath(oldObj, propPath);
                    if (mod !== currentValue && JSON.stringify(mod) !== JSON.stringify(currentValue)) {
                        Dexie.setByKeyPath(newObj, propPath, mod);
                        modsWithoutUndefined[propPath] = mod;
                        anythingChanged = true;
                    }
                }
            }
            if (anythingChanged) {
                var change = {
                    source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.
                    table: tableName,
                    key: primKey,
                    type: UPDATE,
                    mods: modsWithoutUndefined,
                    oldObj: oldObj,
                    obj: newObj
                };
                var promise = trans.tables._changes.add(change); // Just so we get the correct revision order of the update...
github LN-Zap / zap-desktop / renderer / store / db.js View on Github external
await tx.settings.toCollection().modify((setting, ref) => {
      const c = configMap.find(c => c.settingsKey === setting.key)
      if (c) {
        try {
          const defaultValue = Dexie.getByKeyPath(config, c.configPath)
          let value = Dexie.getByKeyPath(setting, c.settingsPath)
          // Apply value mapper if there is one.
          if (c.configMutator) {
            value = c.configMutator(value)
          }
          // If the value differes from the default, save it into the config.
          if (value && value !== defaultValue) {
            Dexie.setByKeyPath(newConfig, c.configPath, value)
          }
          // Finally, delete the old setting.
          delete ref.value
        } catch (e) {
          // If there was a problem migrating the old setting just delete the setting altogether.
          delete ref.value
        }
      }
    })
    // Save the migrated config overrides.
github learningequality / studio / contentcuration / contentcuration / frontend / shared / data / mergeChanges.js View on Github external
Object.keys(modifications).forEach(function(keyPath) {
    Dexie.setByKeyPath(obj, keyPath, modifications[keyPath]);
  });
  return obj;
github dfahlander / Dexie.js / addons / Dexie.Syncable / src / connect-protocol.js View on Github external
Object.keys(nodeModificationsOnAck).forEach(function (keyPath) {
                Dexie.setByKeyPath(node, keyPath, nodeModificationsOnAck[keyPath]);
              });
              node.save().catch('DatabaseClosedError', ()=> {
github dfahlander / Dexie.js / addons / Dexie.Syncable / src / Dexie.Syncable.js View on Github external
Object.keys(nodeModificationsOnAck).forEach(function(keyPath) {
                                Dexie.setByKeyPath(node, keyPath, nodeModificationsOnAck[keyPath]);
                            });
                            node.save();