From 09bd998495ff0d59c4ee3ae0238f6b5fcc719091 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Sun, 29 Sep 2024 21:41:37 -0400 Subject: [PATCH] Prepare to implement tracked storage, RFC#669 --- .../@glimmer/tracking/primitives/storage.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 packages/@glimmer/tracking/primitives/storage.ts diff --git a/packages/@glimmer/tracking/primitives/storage.ts b/packages/@glimmer/tracking/primitives/storage.ts new file mode 100644 index 00000000000..13f0d3e2b66 --- /dev/null +++ b/packages/@glimmer/tracking/primitives/storage.ts @@ -0,0 +1,32 @@ +/** + * https://rfcs.emberjs.com/id/0669-tracked-storage-primitive + * + * See, in particular: + * https://rfcs.emberjs.com/id/0669-tracked-storage-primitive#re-implementing-tracked-with-storage + * + * This was an earlier iteration of "Cells" from starbeam. + * + * Ultimately, these functions could (and maybe should) + * be re-exports from Glimmer and/or Starbeam + */ + +export function createStorage( + initialValue?: T, + isEqual?: (oldValue: T, newValue: T) => boolean +): Storage { + throw new Error('Not Implemented'); +} + +/** + * This function receives a tracked storage instance, and returns the value it contains, consuming it so that it entangles with any currently active autotracking contexts. + */ +export function getValue(storage: Storage): T { + throw new Error('Not Implemented'); +} + +/** + * This function receives a tracked storage instance and a value, and sets the value of the tracked storage to the passed value if it is not equal to the previous value. If the value is set, it will dirty the storage, causing any tracked computations which consumed the stored value to recompute. If the value was not changed, then it does not set the value or dirty it. + */ +export function setValue(storage: Storage, value: T): void { + throw new Error('Not Implemented'); +}