1.3.2 • Published 3 years ago

ot-json1-immutable v1.3.2

Weekly downloads
519
License
MIT
Repository
github
Last release
3 years ago

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

3 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.2

4 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago