IdenticObjects
Javascript Object Factory for unique reference shared object creation.
It creates unique objects references for same objects, since objects
share references of unique objects inner equal objects will also share
same references, even if there father are not equal.
All registered objects are read-only and therefor they can not be changed.
install
npm install identicobjects --save
how to use
const IdenticObjects = require("identicobjects");
const objects = new IdenticObjects();
const a = objects.get({
a: {
b: {
c: [{}]
}
}
});
const b = objects.get({
a: {
b: {
c: [{}]
}
},
b: []
});
const c = objects.get(1);
console.log(c);
console.log(a, b, a.a.b.c[0] === b.a.b.c[0]);
console.log(a, b, a === b);
a.d = 1;
console.log(JSON.stringify(a));
Use cases
- Comparing objects created on the fly or coming from different sources,
- Use objects as unique key on a Map, or as a unique Set value.