How to use the fast-json-patch.applyPatch function in fast-json-patch

To help you get started, we’ve selected a few fast-json-patch 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 axway-amplify-streams / axway-amplify-streams-js / stockmarket-angular2 / src / app / app.component.ts View on Github external
.onPatch((patch) => {
        // update the data with the provided patch// update the data with the provided patch
        console.log('--------------- on patch ---------------');
        //  console.log('patch: %o', patch);
        console.log('patch:');

        applyPatch(this.result, patch);

        console.log('result patched:');
        console.log('--------------- end on patch ---------------');

      }, this)
      .onError((error: StreamDataError) => {
github vega / vega-embed / src / embed.ts View on Github external
if (!div) {
    throw Error('${el} does not exist');
  }

  div.classList.add('vega-embed');
  if (actions) {
    div.classList.add('has-actions');
  }
  div.innerHTML = ''; // clear container

  const patch = opts.patch;
  if (patch) {
    if (patch instanceof Function) {
      vgSpec = patch(vgSpec);
    } else {
      vgSpec = applyPatch(vgSpec, patch, true, false).newDocument;
    }
  }

  // Set locale. Note that this is a global setting.
  if (opts.formatLocale) {
    vega.formatLocale(opts.formatLocale);
  }

  if (opts.timeFormatLocale) {
    vega.timeFormatLocale(opts.timeFormatLocale);
  }

  // Do not apply the config to Vega when we have already applied it to Vega-Lite.
  // This call may throw an Error if parsing fails.
  const runtime = vega.parse(vgSpec, mode === 'vega-lite' ? {} : config);
github formio / formio / src / middleware / submissionApplyPatch.js View on Github external
router.resourcejs[req.route.path]['get'](childReq, childRes, function(err) {
    if (err) {
      return res.status(400).send(err);
    }

    const submission = _.get(childRes, 'resource.item', false);
    // No submission exists.
    if (!submission) {
      return res.sendStatus(404);
    }

    const patch = req.body;

    try {
      req.body = jsonPatch.applyPatch(submission, patch, true).newDocument;

      return next();
    }
    catch (err) {
      res.status(400).send(err);
    }
  });
};
github neuroanatomy / BrainBox / controller / atlasmakerServer / atlasmakerServer.js View on Github external
.then(function (ret) {
                        delete ret._id;
                        // apply patch
                        jsonpatch.applyPatch( ret, data.patch );
                        // sanitise
                        ret = JSON.parse(DOMPurify.sanitize(JSON.stringify(ret))); // sanitize works on strings, not objects
                        // mark previous as backup
                        db.get('mri').update({ source: json.source }, { $set: { backup: true }}, { multi: true })
                            .then(function () {
                                // insert new
                                db.get('mri').insert(ret);
                            });
                    });
            } else {
github FabricLabs / fabric / types / collection.js View on Github external
_patchTarget (path, patches) {
    let link = `${path}`;
    let result = null;

    try {
      result = monitor.applyPatch(this.state, patches.map((op) => {
        op.path = `${link}${op.path}`;
        return op;
      })).newDocument;
    } catch (E) {
      console.log('Could not patch target:', E, path, patches);
    }

    this.commit();

    return result;
  }
github FabricLabs / fabric / types / state.js View on Github external
async _applyChanges (ops) {
    try {
      monitor.applyPatch(this['@data'], ops);

      await this.commit();
    } catch (E) {
      this.error('Error applying changes:', E);
    }

    return this;
  }
github FabricLabs / fabric / types / datastore.js View on Github external
_apply (delta) {
    let datastore = this;
    let document = monitor.applyPatch(datastore['@data'], delta);

    datastore._sign();
    document.commit();

    this.log('[DATASTORE]', '_apply', 'document:', document);
    this.log('[DATASTORE]', '_apply', 'datastore:', datastore);

    return datastore['@data'];
  }
github sigoden / htte / packages / htte / src / load-config.js View on Github external
configFile = path.resolve(configFile);

  let baseDir = getBaseDir(configFile);
  let config = loadYaml(configFile);
  config.baseDir = baseDir;
  config.configFile = configFile;
  if (!validator.config(config)) {
    throw new ValidateError('config', validator.config.errors);
  }
  if (patch) {
    let patchFile = getPatchFile(configFile, patch);
    let patchOps = loadYaml(path.resolve(baseDir, patchFile));
    if (!validator.patch(patchOps)) {
      throw new ValidateError('patch', validator.patch.errors);
    }
    applyPatch(config, patchOps, false, true);
  }
  return config;
};
github formio / formio.js / src / utils / formUtils.js View on Github external
findComponent(form.components, change.key, null, function(component, path) {
          found = true;
          try {
            set(form.components, path, applyPatch(component, change.patches).newDocument);
          }
          catch (err) {
            failed.push(change);
          }
        });
        break;