Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

ot-json1-immutable

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ot-json1-immutable

Add Immutable.js support to ot-json1

latest
Source
npmnpm
Version
1.3.2
Version published
Maintainers
1
Created
Source

JSON1 + Immutable.js

This module add supports for Immutable.js structures to ot-json1.

Install

yarn add ot-json1-immutable ot-json1 immutable

Usage

Just import json from ot-json1-immutable and use it exactly like specified by ot-json1 documentation. Use applyImmutable to actually apply operations to any immutable structure.

import json1 from 'ot-json1-immutable';
import { Map } from 'immutable';

const op = json1.moveOp(['a'], ['b']);

let doc = new Map({ a: 1 });
doc = json1.type.applyImmutable(doc, op);
// doc => new Map({ b: 1 })

applyImmutable function also take a reviver, used by Immutable's fromJS:

function reviver(key, value) => {
  if (!isKeyed(value)) {
    return value.toList();
  }
  switch (value.get('object')) {
    case 'block':
      return Block.create(value.toJS());
    default:
      return value.toMap();
  }
}

const op = json1.insertOp(['a'], { object: 'block' });
let doc = new Map({});

doc = json1.type.applyImmutable(doc, op, reviver);

// doc.get('a') => new Block()

FAQs

Package last updated on 16 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts