objectbuffer
objectbuffer copied to clipboard
[Feature Idea] Const values
Support saving values as const values, means they will be nested-immutable, and contiguous memory as possible.
Another idea: lock array & object structures, but allow updates that will use same amount of memory.
The involved data structures cloud be more efficient, as they are for read only, so they will be optimize for read and not update.
Take into account: what about circularities, and saving part of the tree into mutable branch of objectbuffer.
A possible api to save values as const:
import { saveAsConst } from '@bnaya/objectbuffer';
const ob = createObjectBuffer();
saveAsConst(() => {
ob.const = {a: 1, b: [1, 2, 3]}
});
ob.const.a === 1; // true
ob.const.a = 2; // THROW!!
Worth noting: https://github.com/tc39/proposal-record-tuple#examples