Skip to content

Save your object links equal server and client states

Notifications You must be signed in to change notification settings

belozer/objects-packer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

travis

Objects Packer

Save your object links equal server and client states

Short example

// 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

Named stores

// 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

IMPORTANT!

You can give as many times as you take for same store. This is feature for cleaning store in runtime for stop memory leaks.

Example

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

About

Save your object links equal server and client states

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published