Save your object links equal server and client states
// Server
const dataA = {};
const dataB = { a: dataA, b : dataA };
const packer = new Packer();
packer.take(dataB);
const json = JSON.stringify(packer.pack);
// Browser
const packer = new Packer(JSON.parse(json));
const data = packer.get(0);
data.a === data.b; // true
// Server
const dataA = {};
const dataB = { a: dataA, b : dataA };
const packer = new Packer();
packer.take(dataB, 'myStore1');
packer.take(dataA, 'myStore2');
const json = JSON.stringify(packer.pack);
// Browser
const packer = new Packer(JSON.parse(json));
const myStore1 = packer.give('myStore1');
myStore1.a === myStore1.b; // true
const myStore2 = packer.give('myStore2'); // Deep equal dataA
You can give
as many times as you take
for same store.
This is feature for cleaning store in runtime for stop memory leaks.
const data = {};
packer.take(data); // returns pos 0
packer.take(data); // returns pos 0
packer.give(0); // returns data
packer.give(0); // returns data
packer.give(0); // returns null