import { Writable, computed, pattern } from "commonfabric"; const KEY = "k"; const ANY_KEY: string = "k"; // FIXTURE: computed-element-access-dynamic-key // Verifies: an element access whose key can name any member reads the whole static prefix above the key, so the receiver keeps that prefix // catalog.get().offers[key.get()].space, offers[ANY_KEY], offers[String(KEY)], and offers[k] in a map callback each keep catalog in the lift's input // items.get()[idx.get()] directly on the `.get()` result keeps items the same way // a typed capture read through offers[ANY_KEY] keeps offers whole and drops its unread meta // Context: Every lift has at least two captures, so a dropped read would shrink one out export default pattern(() => { const catalog = new Writable>({ offers: {} }); const n = new Writable(0); const key = new Writable("k"); const items = new Writable([]); const idx = new Writable(0); const keys = new Writable(["k"]); const typed = new Writable<{ offers: Record; meta: { x: number }; }>({ offers: {}, meta: { x: 1 } }); const captureKey = computed(() => n.get() === 1 && catalog.get().offers[key.get()].space === "room" ); const stringTypedKey = computed(() => n.get() === 1 && catalog.get().offers[ANY_KEY].space === "room" ); const callKey = computed(() => n.get() === 1 && catalog.get().offers[String(KEY)].space === "room" ); const callbackParameterKey = computed(() => keys.get().map((k) => n.get() === 1 && catalog.get().offers[k].space) ); const indexOnGetResult = computed(() => n.get() + items.get()[idx.get()]!); const typedAnyKey = computed(() => n.get() === 1 && typed.get().offers[ANY_KEY]?.space === "room" ); return { captureKey, stringTypedKey, callKey, callbackParameterKey, indexOnGetResult, typedAnyKey, }; });