Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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()

About

Add support for Immutable.js structures to ot-json1

Resources

Packages

No packages published