objectbuffer icon indicating copy to clipboard operation
objectbuffer copied to clipboard

[Feature Idea] Const values

Open Bnaya opened this issue 4 years ago • 0 comments

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

Bnaya avatar Jun 20 '20 08:06 Bnaya