@glimmer/reference
Advanced tools
+1
-371
@@ -1,372 +0,2 @@ | ||
| import { getProp, setProp, toIterator, getPath } from '@glimmer/global-context'; | ||
| import { expect, isDict, EMPTY_ARRAY, isObject } from '@glimmer/util'; | ||
| import { CONSTANT_TAG, validateTag, track, valueForTag, consumeTag, INITIAL, createTag, dirtyTag } from '@glimmer/validator'; | ||
| const REFERENCE = Symbol('REFERENCE'); | ||
| const CONSTANT = 0; | ||
| const COMPUTE = 1; | ||
| const UNBOUND = 2; | ||
| const INVOKABLE = 3; | ||
| ////////// | ||
| class ReferenceImpl { | ||
| [REFERENCE]; | ||
| tag = null; | ||
| lastRevision = INITIAL; | ||
| lastValue; | ||
| children = null; | ||
| compute = null; | ||
| update = null; | ||
| debugLabel; | ||
| constructor(type) { | ||
| this[REFERENCE] = type; | ||
| } | ||
| } | ||
| function createPrimitiveRef(value) { | ||
| const ref = new ReferenceImpl(UNBOUND); | ||
| ref.tag = CONSTANT_TAG; | ||
| ref.lastValue = value; | ||
| { | ||
| ref.debugLabel = String(value); | ||
| } | ||
| return ref; | ||
| } | ||
| const UNDEFINED_REFERENCE = createPrimitiveRef(undefined); | ||
| const NULL_REFERENCE = createPrimitiveRef(null); | ||
| const TRUE_REFERENCE = createPrimitiveRef(true); | ||
| const FALSE_REFERENCE = createPrimitiveRef(false); | ||
| function createConstRef(value, debugLabel) { | ||
| const ref = new ReferenceImpl(CONSTANT); | ||
| ref.lastValue = value; | ||
| ref.tag = CONSTANT_TAG; | ||
| { | ||
| ref.debugLabel = debugLabel; | ||
| } | ||
| return ref; | ||
| } | ||
| function createUnboundRef(value, debugLabel) { | ||
| const ref = new ReferenceImpl(UNBOUND); | ||
| ref.lastValue = value; | ||
| ref.tag = CONSTANT_TAG; | ||
| { | ||
| ref.debugLabel = debugLabel; | ||
| } | ||
| return ref; | ||
| } | ||
| function createComputeRef(compute) { | ||
| let update = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
| let debugLabel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'unknown'; | ||
| const ref = new ReferenceImpl(COMPUTE); | ||
| ref.compute = compute; | ||
| ref.update = update; | ||
| { | ||
| ref.debugLabel = `(result of a \`${debugLabel}\` helper)`; | ||
| } | ||
| return ref; | ||
| } | ||
| function createReadOnlyRef(ref) { | ||
| if (!isUpdatableRef(ref)) return ref; | ||
| return createComputeRef(() => valueForRef(ref), null, ref.debugLabel); | ||
| } | ||
| function isInvokableRef(ref) { | ||
| return ref[REFERENCE] === INVOKABLE; | ||
| } | ||
| function createInvokableRef(inner) { | ||
| const ref = createComputeRef(() => valueForRef(inner), value => updateRef(inner, value)); | ||
| ref.debugLabel = inner.debugLabel; | ||
| ref[REFERENCE] = INVOKABLE; | ||
| return ref; | ||
| } | ||
| function isConstRef(_ref) { | ||
| const ref = _ref; | ||
| return ref.tag === CONSTANT_TAG; | ||
| } | ||
| function isUpdatableRef(_ref) { | ||
| const ref = _ref; | ||
| return ref.update !== null; | ||
| } | ||
| function valueForRef(_ref) { | ||
| const ref = _ref; | ||
| let { | ||
| tag | ||
| } = ref; | ||
| if (tag === CONSTANT_TAG) { | ||
| return ref.lastValue; | ||
| } | ||
| const { | ||
| lastRevision | ||
| } = ref; | ||
| let lastValue; | ||
| if (tag === null || !validateTag(tag, lastRevision)) { | ||
| const { | ||
| compute | ||
| } = ref; | ||
| const newTag = track(() => { | ||
| lastValue = ref.lastValue = compute(); | ||
| }, ref.debugLabel); | ||
| tag = ref.tag = newTag; | ||
| ref.lastRevision = valueForTag(newTag); | ||
| } else { | ||
| lastValue = ref.lastValue; | ||
| } | ||
| consumeTag(tag); | ||
| return lastValue; | ||
| } | ||
| function updateRef(_ref, value) { | ||
| const ref = _ref; | ||
| const update = expect(ref.update, 'called update on a non-updatable reference'); | ||
| update(value); | ||
| } | ||
| function childRefFor(_parentRef, path) { | ||
| const parentRef = _parentRef; | ||
| const type = parentRef[REFERENCE]; | ||
| let children = parentRef.children; | ||
| let child; | ||
| if (children === null) { | ||
| children = parentRef.children = new Map(); | ||
| } else { | ||
| child = children.get(path); | ||
| if (child !== undefined) { | ||
| return child; | ||
| } | ||
| } | ||
| if (type === UNBOUND) { | ||
| const parent = valueForRef(parentRef); | ||
| if (isDict(parent)) { | ||
| child = createUnboundRef(parent[path], `${parentRef.debugLabel}.${path}`); | ||
| } else { | ||
| child = UNDEFINED_REFERENCE; | ||
| } | ||
| } else { | ||
| child = createComputeRef(() => { | ||
| const parent = valueForRef(parentRef); | ||
| if (isDict(parent)) { | ||
| return getProp(parent, path); | ||
| } | ||
| }, val => { | ||
| const parent = valueForRef(parentRef); | ||
| if (isDict(parent)) { | ||
| return setProp(parent, path, val); | ||
| } | ||
| }); | ||
| { | ||
| child.debugLabel = `${parentRef.debugLabel}.${path}`; | ||
| } | ||
| } | ||
| children.set(path, child); | ||
| return child; | ||
| } | ||
| function childRefFromParts(root, parts) { | ||
| let reference = root; | ||
| for (const part of parts) { | ||
| reference = childRefFor(reference, part); | ||
| } | ||
| return reference; | ||
| } | ||
| let createDebugAliasRef; | ||
| { | ||
| createDebugAliasRef = (debugLabel, inner) => { | ||
| const update = isUpdatableRef(inner) ? value => updateRef(inner, value) : null; | ||
| const ref = createComputeRef(() => valueForRef(inner), update); | ||
| ref[REFERENCE] = inner[REFERENCE]; | ||
| ref.debugLabel = debugLabel; | ||
| return ref; | ||
| }; | ||
| } | ||
| const NULL_IDENTITY = {}; | ||
| const KEY = (_, index) => index; | ||
| const INDEX = (_, index) => String(index); | ||
| const IDENTITY = item => { | ||
| if (item === null) { | ||
| // Returning null as an identity will cause failures since the iterator | ||
| // can't tell that it's actually supposed to be null | ||
| return NULL_IDENTITY; | ||
| } | ||
| return item; | ||
| }; | ||
| function keyForPath(path) { | ||
| if (path[0] === '@') { | ||
| throw new Error(`invalid keypath: '${path}', valid keys: @index, @identity, or a path`); | ||
| } | ||
| return uniqueKeyFor(item => getPath(item, path)); | ||
| } | ||
| function makeKeyFor(key) { | ||
| switch (key) { | ||
| case '@key': | ||
| return uniqueKeyFor(KEY); | ||
| case '@index': | ||
| return uniqueKeyFor(INDEX); | ||
| case '@identity': | ||
| return uniqueKeyFor(IDENTITY); | ||
| default: | ||
| return keyForPath(key); | ||
| } | ||
| } | ||
| class WeakMapWithPrimitives { | ||
| _weakMap; | ||
| _primitiveMap; | ||
| get weakMap() { | ||
| if (this._weakMap === undefined) { | ||
| this._weakMap = new WeakMap(); | ||
| } | ||
| return this._weakMap; | ||
| } | ||
| get primitiveMap() { | ||
| if (this._primitiveMap === undefined) { | ||
| this._primitiveMap = new Map(); | ||
| } | ||
| return this._primitiveMap; | ||
| } | ||
| set(key, value) { | ||
| if (isObject(key)) { | ||
| this.weakMap.set(key, value); | ||
| } else { | ||
| this.primitiveMap.set(key, value); | ||
| } | ||
| } | ||
| get(key) { | ||
| if (isObject(key)) { | ||
| return this.weakMap.get(key); | ||
| } else { | ||
| return this.primitiveMap.get(key); | ||
| } | ||
| } | ||
| } | ||
| const IDENTITIES = new WeakMapWithPrimitives(); | ||
| function identityForNthOccurence(value, count) { | ||
| let identities = IDENTITIES.get(value); | ||
| if (identities === undefined) { | ||
| identities = []; | ||
| IDENTITIES.set(value, identities); | ||
| } | ||
| let identity = identities[count]; | ||
| if (identity === undefined) { | ||
| identity = { | ||
| value, | ||
| count | ||
| }; | ||
| identities[count] = identity; | ||
| } | ||
| return identity; | ||
| } | ||
| /** | ||
| * When iterating over a list, it's possible that an item with the same unique | ||
| * key could be encountered twice: | ||
| * | ||
| * ```js | ||
| * let arr = ['same', 'different', 'same', 'same']; | ||
| * ``` | ||
| * | ||
| * In general, we want to treat these items as _unique within the list_. To do | ||
| * this, we track the occurences of every item as we iterate the list, and when | ||
| * an item occurs more than once, we generate a new unique key just for that | ||
| * item, and that occurence within the list. The next time we iterate the list, | ||
| * and encounter an item for the nth time, we can get the _same_ key, and let | ||
| * Glimmer know that it should reuse the DOM for the previous nth occurence. | ||
| */ | ||
| function uniqueKeyFor(keyFor) { | ||
| let seen = new WeakMapWithPrimitives(); | ||
| return (value, memo) => { | ||
| let key = keyFor(value, memo); | ||
| let count = seen.get(key) || 0; | ||
| seen.set(key, count + 1); | ||
| if (count === 0) { | ||
| return key; | ||
| } | ||
| return identityForNthOccurence(key, count); | ||
| }; | ||
| } | ||
| function createIteratorRef(listRef, key) { | ||
| return createComputeRef(() => { | ||
| let iterable = valueForRef(listRef); | ||
| let keyFor = makeKeyFor(key); | ||
| if (Array.isArray(iterable)) { | ||
| return new ArrayIterator(iterable, keyFor); | ||
| } | ||
| let maybeIterator = toIterator(iterable); | ||
| if (maybeIterator === null) { | ||
| return new ArrayIterator(EMPTY_ARRAY, () => null); | ||
| } | ||
| return new IteratorWrapper(maybeIterator, keyFor); | ||
| }); | ||
| } | ||
| function createIteratorItemRef(_value) { | ||
| let value = _value; | ||
| let tag = createTag(); | ||
| return createComputeRef(() => { | ||
| consumeTag(tag); | ||
| return value; | ||
| }, newValue => { | ||
| if (value !== newValue) { | ||
| value = newValue; | ||
| dirtyTag(tag); | ||
| } | ||
| }); | ||
| } | ||
| class IteratorWrapper { | ||
| constructor(inner, keyFor) { | ||
| this.inner = inner; | ||
| this.keyFor = keyFor; | ||
| } | ||
| isEmpty() { | ||
| return this.inner.isEmpty(); | ||
| } | ||
| next() { | ||
| let nextValue = this.inner.next(); | ||
| if (nextValue !== null) { | ||
| nextValue.key = this.keyFor(nextValue.value, nextValue.memo); | ||
| } | ||
| return nextValue; | ||
| } | ||
| } | ||
| class ArrayIterator { | ||
| current; | ||
| pos = 0; | ||
| constructor(iterator, keyFor) { | ||
| this.iterator = iterator; | ||
| this.keyFor = keyFor; | ||
| if (iterator.length === 0) { | ||
| this.current = { | ||
| kind: 'empty' | ||
| }; | ||
| } else { | ||
| this.current = { | ||
| kind: 'first', | ||
| value: iterator[this.pos] | ||
| }; | ||
| } | ||
| } | ||
| isEmpty() { | ||
| return this.current.kind === 'empty'; | ||
| } | ||
| next() { | ||
| let value; | ||
| let current = this.current; | ||
| if (current.kind === 'first') { | ||
| this.current = { | ||
| kind: 'progress' | ||
| }; | ||
| value = current.value; | ||
| } else if (this.pos >= this.iterator.length - 1) { | ||
| return null; | ||
| } else { | ||
| value = this.iterator[++this.pos]; | ||
| } | ||
| let { | ||
| keyFor | ||
| } = this; | ||
| let key = keyFor(value, this.pos); | ||
| let memo = this.pos; | ||
| return { | ||
| key, | ||
| value, | ||
| memo | ||
| }; | ||
| } | ||
| } | ||
| export { FALSE_REFERENCE, NULL_REFERENCE, REFERENCE, TRUE_REFERENCE, UNDEFINED_REFERENCE, childRefFor, childRefFromParts, createComputeRef, createConstRef, createDebugAliasRef, createInvokableRef, createIteratorItemRef, createIteratorRef, createPrimitiveRef, createReadOnlyRef, createUnboundRef, isConstRef, isInvokableRef, isUpdatableRef, updateRef, valueForRef }; | ||
| import{getProp as t,setProp as e,toIterator as n,getPath as r}from"@glimmer/global-context";import{expect as i,isDict as u,EMPTY_ARRAY as l,isObject as s}from"@glimmer/util";import{CONSTANT_TAG as a,validateTag as o,track as c,valueForTag as p,consumeTag as d,INITIAL as h,createTag as f,dirtyTag as g}from"@glimmer/validator";const m=Symbol("REFERENCE"),b=1,v=2;class k{[m];tag=null;lastRevision=h;lastValue;children=null;compute=null;update=null;debugLabel;constructor(t){this[m]=t}}function w(t){const e=new k(v);return e.tag=a,e.lastValue=t,e.debugLabel=String(t),e}const y=w(void 0),M=w(null),L=w(!0),E=w(!1);function _(t,e){const n=new k(0);return n.lastValue=t,n.tag=a,n.debugLabel=e,n}function x(t,e){const n=new k(v);return n.lastValue=t,n.tag=a,n.debugLabel=e,n}function V(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"unknown";const r=new k(b);return r.compute=t,r.update=e,r.debugLabel=`(result of a \`${n}\` helper)`,r}function $(t){return A(t)?V((()=>C(t)),null,t.debugLabel):t}function F(t){return 3===t[m]}function R(t){const e=V((()=>C(t)),(e=>N(t,e)));return e.debugLabel=t.debugLabel,e[m]=3,e}function S(t){return t.tag===a}function A(t){return null!==t.update}function C(t){const e=t;let{tag:n}=e;if(n===a)return e.lastValue;const{lastRevision:r}=e;let i;if(null!==n&&o(n,r))i=e.lastValue;else{const{compute:t}=e,r=c((()=>{i=e.lastValue=t()}),e.debugLabel);n=e.tag=r,e.lastRevision=p(r)}return d(n),i}function N(t,e){i(t.update,"called update on a non-updatable reference")(e)}function W(n,r){const i=n,l=i[m];let s,a=i.children;if(null===a)a=i.children=new Map;else if(s=a.get(r),void 0!==s)return s;if(l===v){const t=C(i);s=u(t)?x(t[r],`${i.debugLabel}.${r}`):y}else s=V((()=>{const e=C(i);if(u(e))return t(e,r)}),(t=>{const n=C(i);if(u(n))return e(n,r,t)})),s.debugLabel=`${i.debugLabel}.${r}`;return a.set(r,s),s}function j(t,e){let n=t;for(const t of e)n=W(n,t);return n}let q;q=(t,e)=>{const n=V((()=>C(e)),A(e)?t=>N(e,t):null);return n[m]=e[m],n.debugLabel=t,n};const z={},B=(t,e)=>e,D=(t,e)=>String(e),G=t=>null===t?z:t;function H(t){switch(t){case"@key":return K(B);case"@index":return K(D);case"@identity":return K(G);default:return function(t){if("@"===t[0])throw new Error(`invalid keypath: '${t}', valid keys: @index, @identity, or a path`);return K((e=>r(e,t)))}(t)}}class I{_weakMap;_primitiveMap;get weakMap(){return void 0===this._weakMap&&(this._weakMap=new WeakMap),this._weakMap}get primitiveMap(){return void 0===this._primitiveMap&&(this._primitiveMap=new Map),this._primitiveMap}set(t,e){s(t)?this.weakMap.set(t,e):this.primitiveMap.set(t,e)}get(t){return s(t)?this.weakMap.get(t):this.primitiveMap.get(t)}}const J=new I;function K(t){let e=new I;return(n,r)=>{let i=t(n,r),u=e.get(i)||0;return e.set(i,u+1),0===u?i:function(t,e){let n=J.get(t);void 0===n&&(n=[],J.set(t,n));let r=n[e];return void 0===r&&(r={value:t,count:e},n[e]=r),r}(i,u)}}function O(t,e){return V((()=>{let r=C(t),i=H(e);if(Array.isArray(r))return new T(r,i);let u=n(r);return null===u?new T(l,(()=>null)):new Q(u,i)}))}function P(t){let e=t,n=f();return V((()=>(d(n),e)),(t=>{e!==t&&(e=t,g(n))}))}class Q{constructor(t,e){this.inner=t,this.keyFor=e}isEmpty(){return this.inner.isEmpty()}next(){let t=this.inner.next();return null!==t&&(t.key=this.keyFor(t.value,t.memo)),t}}class T{current;pos=0;constructor(t,e){this.iterator=t,this.keyFor=e,0===t.length?this.current={kind:"empty"}:this.current={kind:"first",value:t[this.pos]}}isEmpty(){return"empty"===this.current.kind}next(){let t,e=this.current;if("first"===e.kind)this.current={kind:"progress"},t=e.value;else{if(this.pos>=this.iterator.length-1)return null;t=this.iterator[++this.pos]}let{keyFor:n}=this;return{key:n(t,this.pos),value:t,memo:this.pos}}}export{E as FALSE_REFERENCE,M as NULL_REFERENCE,m as REFERENCE,L as TRUE_REFERENCE,y as UNDEFINED_REFERENCE,W as childRefFor,j as childRefFromParts,V as createComputeRef,_ as createConstRef,q as createDebugAliasRef,R as createInvokableRef,P as createIteratorItemRef,O as createIteratorRef,w as createPrimitiveRef,$ as createReadOnlyRef,x as createUnboundRef,S as isConstRef,F as isInvokableRef,A as isUpdatableRef,N as updateRef,C as valueForRef}; | ||
| //# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sources":["../../lib/reference.ts","../../lib/iterable.ts"],"sourcesContent":["import { getProp, setProp } from '@glimmer/global-context';\nimport type {\n ComputeReference,\n ConstantReference,\n InvokableReference,\n Nullable,\n Reference,\n ReferenceSymbol,\n ReferenceType,\n UnboundReference,\n} from \"@glimmer/interfaces\";\nimport { expect, isDict } from '@glimmer/util';\nimport {\n CONSTANT_TAG,\n consumeTag,\n INITIAL,\n type Revision,\n type Tag,\n track,\n validateTag,\n valueForTag,\n} from '@glimmer/validator';\n\nexport const REFERENCE: ReferenceSymbol = Symbol('REFERENCE') as ReferenceSymbol;\n\nconst CONSTANT: ConstantReference = 0;\nconst COMPUTE: ComputeReference = 1;\nconst UNBOUND: UnboundReference = 2;\nconst INVOKABLE: InvokableReference = 3;\n\nexport type { Reference as default };\nexport type { Reference };\n\n//////////\n\nexport interface ReferenceEnvironment {\n getProp(obj: unknown, path: string): unknown;\n setProp(obj: unknown, path: string, value: unknown): unknown;\n}\n\nclass ReferenceImpl<T = unknown> implements Reference<T> {\n [REFERENCE]: ReferenceType;\n public tag: Nullable<Tag> = null;\n public lastRevision: Revision = INITIAL;\n public lastValue?: T;\n\n public children: Nullable<Map<string | Reference, Reference>> = null;\n\n public compute: Nullable<() => T> = null;\n public update: Nullable<(val: T) => void> = null;\n\n public debugLabel?: string;\n\n constructor(type: ReferenceType) {\n this[REFERENCE] = type;\n }\n}\n\nexport function createPrimitiveRef(value: unknown): Reference {\n const ref = new ReferenceImpl(UNBOUND);\n\n ref.tag = CONSTANT_TAG;\n ref.lastValue = value;\n\n if (import.meta.env.DEV) {\n ref.debugLabel = String(value);\n }\n\n return ref;\n}\n\nexport const UNDEFINED_REFERENCE = createPrimitiveRef(undefined);\nexport const NULL_REFERENCE = createPrimitiveRef(null);\nexport const TRUE_REFERENCE = createPrimitiveRef(true);\nexport const FALSE_REFERENCE = createPrimitiveRef(false);\n\nexport function createConstRef(value: unknown, debugLabel: false | string): Reference {\n const ref = new ReferenceImpl(CONSTANT);\n\n ref.lastValue = value;\n ref.tag = CONSTANT_TAG;\n\n if (import.meta.env.DEV) {\n ref.debugLabel = debugLabel as string;\n }\n\n return ref;\n}\n\nexport function createUnboundRef(value: unknown, debugLabel: false | string): Reference {\n const ref = new ReferenceImpl(UNBOUND);\n\n ref.lastValue = value;\n ref.tag = CONSTANT_TAG;\n\n if (import.meta.env.DEV) {\n ref.debugLabel = debugLabel as string;\n }\n\n return ref;\n}\n\nexport function createComputeRef<T = unknown>(\n compute: () => T,\n update: Nullable<(value: T) => void> = null,\n debugLabel: false | string = 'unknown'\n): Reference<T> {\n const ref = new ReferenceImpl<T>(COMPUTE);\n\n ref.compute = compute;\n ref.update = update;\n\n if (import.meta.env.DEV) {\n ref.debugLabel = `(result of a \\`${debugLabel}\\` helper)`;\n }\n\n return ref;\n}\n\nexport function createReadOnlyRef(ref: Reference): Reference {\n if (!isUpdatableRef(ref)) return ref;\n\n return createComputeRef(() => valueForRef(ref), null, ref.debugLabel);\n}\n\nexport function isInvokableRef(ref: Reference) {\n return ref[REFERENCE] === INVOKABLE;\n}\n\nexport function createInvokableRef(inner: Reference): Reference {\n const ref = createComputeRef(\n () => valueForRef(inner),\n (value) => updateRef(inner, value)\n );\n ref.debugLabel = inner.debugLabel;\n ref[REFERENCE] = INVOKABLE;\n\n return ref;\n}\n\nexport function isConstRef(_ref: Reference) {\n const ref = _ref as ReferenceImpl;\n\n return ref.tag === CONSTANT_TAG;\n}\n\nexport function isUpdatableRef(_ref: Reference) {\n const ref = _ref as ReferenceImpl;\n\n return ref.update !== null;\n}\n\nexport function valueForRef<T>(_ref: Reference<T>): T {\n const ref = _ref as ReferenceImpl<T>;\n\n let { tag } = ref;\n\n if (tag === CONSTANT_TAG) {\n return ref.lastValue as T;\n }\n\n const { lastRevision } = ref;\n let lastValue;\n\n if (tag === null || !validateTag(tag, lastRevision)) {\n const { compute } = ref;\n\n const newTag = track(() => {\n lastValue = ref.lastValue = compute!();\n }, import.meta.env.DEV && ref.debugLabel);\n\n tag = ref.tag = newTag;\n\n ref.lastRevision = valueForTag(newTag);\n } else {\n lastValue = ref.lastValue;\n }\n\n consumeTag(tag);\n\n return lastValue as T;\n}\n\nexport function updateRef(_ref: Reference, value: unknown) {\n const ref = _ref as ReferenceImpl;\n\n const update = expect(ref.update, 'called update on a non-updatable reference');\n\n update(value);\n}\n\nexport function childRefFor(_parentRef: Reference, path: string): Reference {\n const parentRef = _parentRef as ReferenceImpl;\n\n const type = parentRef[REFERENCE];\n\n let children = parentRef.children;\n let child: Reference;\n\n if (children === null) {\n children = parentRef.children = new Map();\n } else {\n child = children.get(path)!;\n\n if (child !== undefined) {\n return child;\n }\n }\n\n if (type === UNBOUND) {\n const parent = valueForRef(parentRef);\n\n if (isDict(parent)) {\n child = createUnboundRef(\n (parent as Record<string, unknown>)[path],\n import.meta.env.DEV && `${parentRef.debugLabel}.${path}`\n );\n } else {\n child = UNDEFINED_REFERENCE;\n }\n } else {\n child = createComputeRef(\n () => {\n const parent = valueForRef(parentRef);\n\n if (isDict(parent)) {\n return getProp(parent, path);\n }\n },\n (val) => {\n const parent = valueForRef(parentRef);\n\n if (isDict(parent)) {\n return setProp(parent, path, val);\n }\n }\n );\n\n if (import.meta.env.DEV) {\n child.debugLabel = `${parentRef.debugLabel}.${path}`;\n }\n }\n\n children.set(path, child);\n\n return child;\n}\n\nexport function childRefFromParts(root: Reference, parts: string[]): Reference {\n let reference = root;\n\n for (const part of parts) {\n reference = childRefFor(reference, part);\n }\n\n return reference;\n}\n\nexport let createDebugAliasRef: undefined | ((debugLabel: string, inner: Reference) => Reference);\n\nif (import.meta.env.DEV) {\n createDebugAliasRef = (debugLabel: string, inner: Reference) => {\n const update = isUpdatableRef(inner) ? (value: unknown) => updateRef(inner, value) : null;\n const ref = createComputeRef(() => valueForRef(inner), update);\n\n ref[REFERENCE] = inner[REFERENCE];\n\n ref.debugLabel = debugLabel;\n\n return ref;\n };\n}\n","import { getPath, toIterator } from '@glimmer/global-context';\nimport type { Dict, Nullable } from \"@glimmer/interfaces\";\nimport { EMPTY_ARRAY, isObject } from '@glimmer/util';\nimport { consumeTag, createTag, dirtyTag } from '@glimmer/validator';\n\nimport {\n createComputeRef,\n type Reference,\n type ReferenceEnvironment,\n valueForRef,\n} from './reference';\n\nexport interface IterationItem<T, U> {\n key: unknown;\n value: T;\n memo: U;\n}\n\nexport interface AbstractIterator<T, U, V extends IterationItem<T, U>> {\n isEmpty(): boolean;\n next(): Nullable<V>;\n}\n\nexport type OpaqueIterationItem = IterationItem<unknown, unknown>;\nexport type OpaqueIterator = AbstractIterator<unknown, unknown, OpaqueIterationItem>;\n\nexport interface IteratorDelegate {\n isEmpty(): boolean;\n next(): { value: unknown; memo: unknown } | null;\n}\n\nexport interface IteratorReferenceEnvironment extends ReferenceEnvironment {\n getPath(obj: unknown, path: string): unknown;\n toIterator(obj: unknown): Nullable<IteratorDelegate>;\n}\n\ntype KeyFor = (item: unknown, index: unknown) => unknown;\n\nconst NULL_IDENTITY = {};\n\nconst KEY: KeyFor = (_, index) => index;\nconst INDEX: KeyFor = (_, index) => String(index);\nconst IDENTITY: KeyFor = (item) => {\n if (item === null) {\n // Returning null as an identity will cause failures since the iterator\n // can't tell that it's actually supposed to be null\n return NULL_IDENTITY;\n }\n\n return item;\n};\n\nfunction keyForPath(path: string): KeyFor {\n if (import.meta.env.DEV && path[0] === '@') {\n throw new Error(`invalid keypath: '${path}', valid keys: @index, @identity, or a path`);\n }\n return uniqueKeyFor((item) => getPath(item as object, path));\n}\n\nfunction makeKeyFor(key: string) {\n switch (key) {\n case '@key':\n return uniqueKeyFor(KEY);\n case '@index':\n return uniqueKeyFor(INDEX);\n case '@identity':\n return uniqueKeyFor(IDENTITY);\n default:\n return keyForPath(key);\n }\n}\n\nclass WeakMapWithPrimitives<T> {\n private _weakMap?: WeakMap<object, T>;\n private _primitiveMap?: Map<unknown, T>;\n\n private get weakMap() {\n if (this._weakMap === undefined) {\n this._weakMap = new WeakMap();\n }\n\n return this._weakMap;\n }\n\n private get primitiveMap() {\n if (this._primitiveMap === undefined) {\n this._primitiveMap = new Map();\n }\n\n return this._primitiveMap;\n }\n\n set(key: unknown, value: T) {\n if (isObject(key)) {\n this.weakMap.set(key, value);\n } else {\n this.primitiveMap.set(key, value);\n }\n }\n\n get(key: unknown): T | undefined {\n if (isObject(key)) {\n return this.weakMap.get(key);\n } else {\n return this.primitiveMap.get(key);\n }\n }\n}\n\nconst IDENTITIES = new WeakMapWithPrimitives<object[]>();\n\nfunction identityForNthOccurence(value: any, count: number) {\n let identities = IDENTITIES.get(value);\n\n if (identities === undefined) {\n identities = [];\n IDENTITIES.set(value, identities);\n }\n\n let identity = identities[count];\n\n if (identity === undefined) {\n identity = { value, count };\n identities[count] = identity;\n }\n\n return identity;\n}\n\n/**\n * When iterating over a list, it's possible that an item with the same unique\n * key could be encountered twice:\n *\n * ```js\n * let arr = ['same', 'different', 'same', 'same'];\n * ```\n *\n * In general, we want to treat these items as _unique within the list_. To do\n * this, we track the occurences of every item as we iterate the list, and when\n * an item occurs more than once, we generate a new unique key just for that\n * item, and that occurence within the list. The next time we iterate the list,\n * and encounter an item for the nth time, we can get the _same_ key, and let\n * Glimmer know that it should reuse the DOM for the previous nth occurence.\n */\nfunction uniqueKeyFor(keyFor: KeyFor) {\n let seen = new WeakMapWithPrimitives<number>();\n\n return (value: unknown, memo: unknown) => {\n let key = keyFor(value, memo);\n let count = seen.get(key) || 0;\n\n seen.set(key, count + 1);\n\n if (count === 0) {\n return key;\n }\n\n return identityForNthOccurence(key, count);\n };\n}\n\nexport function createIteratorRef(listRef: Reference, key: string) {\n return createComputeRef(() => {\n let iterable = valueForRef(listRef) as { [Symbol.iterator]: any } | null | false;\n\n let keyFor = makeKeyFor(key);\n\n if (Array.isArray(iterable)) {\n return new ArrayIterator(iterable, keyFor);\n }\n\n let maybeIterator = toIterator(iterable);\n\n if (maybeIterator === null) {\n return new ArrayIterator(EMPTY_ARRAY, () => null);\n }\n\n return new IteratorWrapper(maybeIterator, keyFor);\n });\n}\n\nexport function createIteratorItemRef(_value: unknown) {\n let value = _value;\n let tag = createTag();\n\n return createComputeRef(\n () => {\n consumeTag(tag);\n return value;\n },\n (newValue) => {\n if (value !== newValue) {\n value = newValue;\n dirtyTag(tag);\n }\n }\n );\n}\n\nclass IteratorWrapper implements OpaqueIterator {\n constructor(private inner: IteratorDelegate, private keyFor: KeyFor) {}\n\n isEmpty() {\n return this.inner.isEmpty();\n }\n\n next() {\n let nextValue = this.inner.next() as OpaqueIterationItem;\n\n if (nextValue !== null) {\n nextValue.key = this.keyFor(nextValue.value, nextValue.memo);\n }\n\n return nextValue;\n }\n}\n\nclass ArrayIterator implements OpaqueIterator {\n private current: { kind: 'empty' } | { kind: 'first'; value: unknown } | { kind: 'progress' };\n private pos = 0;\n\n constructor(private iterator: unknown[] | readonly unknown[], private keyFor: KeyFor) {\n if (iterator.length === 0) {\n this.current = { kind: 'empty' };\n } else {\n this.current = { kind: 'first', value: iterator[this.pos] };\n }\n }\n\n isEmpty(): boolean {\n return this.current.kind === 'empty';\n }\n\n next(): Nullable<IterationItem<unknown, number>> {\n let value: unknown;\n\n let current = this.current;\n if (current.kind === 'first') {\n this.current = { kind: 'progress' };\n value = current.value;\n } else if (this.pos >= this.iterator.length - 1) {\n return null;\n } else {\n value = this.iterator[++this.pos];\n }\n\n let { keyFor } = this;\n\n let key = keyFor(value as Dict, this.pos);\n let memo = this.pos;\n\n return { key, value, memo };\n }\n}\n"],"names":["REFERENCE","Symbol","CONSTANT","COMPUTE","UNBOUND","INVOKABLE","ReferenceImpl","tag","lastRevision","INITIAL","lastValue","children","compute","update","debugLabel","constructor","type","createPrimitiveRef","value","ref","CONSTANT_TAG","String","UNDEFINED_REFERENCE","undefined","NULL_REFERENCE","TRUE_REFERENCE","FALSE_REFERENCE","createConstRef","createUnboundRef","createComputeRef","arguments","length","createReadOnlyRef","isUpdatableRef","valueForRef","isInvokableRef","createInvokableRef","inner","updateRef","isConstRef","_ref","validateTag","newTag","track","valueForTag","consumeTag","expect","childRefFor","_parentRef","path","parentRef","child","Map","get","parent","isDict","getProp","val","setProp","set","childRefFromParts","root","parts","reference","part","createDebugAliasRef","NULL_IDENTITY","KEY","_","index","INDEX","IDENTITY","item","keyForPath","Error","uniqueKeyFor","getPath","makeKeyFor","key","WeakMapWithPrimitives","_weakMap","_primitiveMap","weakMap","WeakMap","primitiveMap","isObject","IDENTITIES","identityForNthOccurence","count","identities","identity","keyFor","seen","memo","createIteratorRef","listRef","iterable","Array","isArray","ArrayIterator","maybeIterator","toIterator","EMPTY_ARRAY","IteratorWrapper","createIteratorItemRef","_value","createTag","newValue","dirtyTag","isEmpty","next","nextValue","current","pos","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,CAACD,GAAG,CAAC,CAAA;AACnC,KAAA;IAEA,IAAI;AAAEtB,MAAAA,MAAAA;AAAO,KAAC,GAAG,IAAI,CAAA;IAErB,IAAIb,GAAG,GAAGa,MAAM,CAACzE,KAAK,EAAU,IAAI,CAAC+F,GAAG,CAAC,CAAA;AACzC,IAAA,IAAIpB,IAAI,GAAG,IAAI,CAACoB,GAAG,CAAA;IAEnB,OAAO;MAAEnC,GAAG;MAAE5D,KAAK;AAAE2E,MAAAA,IAAAA;KAAM,CAAA;AAC7B,GAAA;AACF;;;;"} | ||
| {"version":3,"file":"index.js","sources":["../../lib/reference.ts","../../lib/iterable.ts"],"sourcesContent":["import { getProp, setProp } from '@glimmer/global-context';\nimport type {\n ComputeReference,\n ConstantReference,\n InvokableReference,\n Nullable,\n Reference,\n ReferenceSymbol,\n ReferenceType,\n UnboundReference,\n} from \"@glimmer/interfaces\";\nimport { expect, isDict } from '@glimmer/util';\nimport {\n CONSTANT_TAG,\n consumeTag,\n INITIAL,\n type Revision,\n type Tag,\n track,\n validateTag,\n valueForTag,\n} from '@glimmer/validator';\n\nexport const REFERENCE: ReferenceSymbol = Symbol('REFERENCE') as ReferenceSymbol;\n\nconst CONSTANT: ConstantReference = 0;\nconst COMPUTE: ComputeReference = 1;\nconst UNBOUND: UnboundReference = 2;\nconst INVOKABLE: InvokableReference = 3;\n\nexport type { Reference as default };\nexport type { Reference };\n\n//////////\n\nexport interface ReferenceEnvironment {\n getProp(obj: unknown, path: string): unknown;\n setProp(obj: unknown, path: string, value: unknown): unknown;\n}\n\nclass ReferenceImpl<T = unknown> implements Reference<T> {\n [REFERENCE]: ReferenceType;\n public tag: Nullable<Tag> = null;\n public lastRevision: Revision = INITIAL;\n public lastValue?: T;\n\n public children: Nullable<Map<string | Reference, Reference>> = null;\n\n public compute: Nullable<() => T> = null;\n public update: Nullable<(val: T) => void> = null;\n\n public debugLabel?: string;\n\n constructor(type: ReferenceType) {\n this[REFERENCE] = type;\n }\n}\n\nexport function createPrimitiveRef(value: unknown): Reference {\n const ref = new ReferenceImpl(UNBOUND);\n\n ref.tag = CONSTANT_TAG;\n ref.lastValue = value;\n\n if (import.meta.env.DEV) {\n ref.debugLabel = String(value);\n }\n\n return ref;\n}\n\nexport const UNDEFINED_REFERENCE = createPrimitiveRef(undefined);\nexport const NULL_REFERENCE = createPrimitiveRef(null);\nexport const TRUE_REFERENCE = createPrimitiveRef(true);\nexport const FALSE_REFERENCE = createPrimitiveRef(false);\n\nexport function createConstRef(value: unknown, debugLabel: false | string): Reference {\n const ref = new ReferenceImpl(CONSTANT);\n\n ref.lastValue = value;\n ref.tag = CONSTANT_TAG;\n\n if (import.meta.env.DEV) {\n ref.debugLabel = debugLabel as string;\n }\n\n return ref;\n}\n\nexport function createUnboundRef(value: unknown, debugLabel: false | string): Reference {\n const ref = new ReferenceImpl(UNBOUND);\n\n ref.lastValue = value;\n ref.tag = CONSTANT_TAG;\n\n if (import.meta.env.DEV) {\n ref.debugLabel = debugLabel as string;\n }\n\n return ref;\n}\n\nexport function createComputeRef<T = unknown>(\n compute: () => T,\n update: Nullable<(value: T) => void> = null,\n debugLabel: false | string = 'unknown'\n): Reference<T> {\n const ref = new ReferenceImpl<T>(COMPUTE);\n\n ref.compute = compute;\n ref.update = update;\n\n if (import.meta.env.DEV) {\n ref.debugLabel = `(result of a \\`${debugLabel}\\` helper)`;\n }\n\n return ref;\n}\n\nexport function createReadOnlyRef(ref: Reference): Reference {\n if (!isUpdatableRef(ref)) return ref;\n\n return createComputeRef(() => valueForRef(ref), null, ref.debugLabel);\n}\n\nexport function isInvokableRef(ref: Reference) {\n return ref[REFERENCE] === INVOKABLE;\n}\n\nexport function createInvokableRef(inner: Reference): Reference {\n const ref = createComputeRef(\n () => valueForRef(inner),\n (value) => updateRef(inner, value)\n );\n ref.debugLabel = inner.debugLabel;\n ref[REFERENCE] = INVOKABLE;\n\n return ref;\n}\n\nexport function isConstRef(_ref: Reference) {\n const ref = _ref as ReferenceImpl;\n\n return ref.tag === CONSTANT_TAG;\n}\n\nexport function isUpdatableRef(_ref: Reference) {\n const ref = _ref as ReferenceImpl;\n\n return ref.update !== null;\n}\n\nexport function valueForRef<T>(_ref: Reference<T>): T {\n const ref = _ref as ReferenceImpl<T>;\n\n let { tag } = ref;\n\n if (tag === CONSTANT_TAG) {\n return ref.lastValue as T;\n }\n\n const { lastRevision } = ref;\n let lastValue;\n\n if (tag === null || !validateTag(tag, lastRevision)) {\n const { compute } = ref;\n\n const newTag = track(() => {\n lastValue = ref.lastValue = compute!();\n }, import.meta.env.DEV && ref.debugLabel);\n\n tag = ref.tag = newTag;\n\n ref.lastRevision = valueForTag(newTag);\n } else {\n lastValue = ref.lastValue;\n }\n\n consumeTag(tag);\n\n return lastValue as T;\n}\n\nexport function updateRef(_ref: Reference, value: unknown) {\n const ref = _ref as ReferenceImpl;\n\n const update = expect(ref.update, 'called update on a non-updatable reference');\n\n update(value);\n}\n\nexport function childRefFor(_parentRef: Reference, path: string): Reference {\n const parentRef = _parentRef as ReferenceImpl;\n\n const type = parentRef[REFERENCE];\n\n let children = parentRef.children;\n let child: Reference;\n\n if (children === null) {\n children = parentRef.children = new Map();\n } else {\n child = children.get(path)!;\n\n if (child !== undefined) {\n return child;\n }\n }\n\n if (type === UNBOUND) {\n const parent = valueForRef(parentRef);\n\n if (isDict(parent)) {\n child = createUnboundRef(\n (parent as Record<string, unknown>)[path],\n import.meta.env.DEV && `${parentRef.debugLabel}.${path}`\n );\n } else {\n child = UNDEFINED_REFERENCE;\n }\n } else {\n child = createComputeRef(\n () => {\n const parent = valueForRef(parentRef);\n\n if (isDict(parent)) {\n return getProp(parent, path);\n }\n },\n (val) => {\n const parent = valueForRef(parentRef);\n\n if (isDict(parent)) {\n return setProp(parent, path, val);\n }\n }\n );\n\n if (import.meta.env.DEV) {\n child.debugLabel = `${parentRef.debugLabel}.${path}`;\n }\n }\n\n children.set(path, child);\n\n return child;\n}\n\nexport function childRefFromParts(root: Reference, parts: string[]): Reference {\n let reference = root;\n\n for (const part of parts) {\n reference = childRefFor(reference, part);\n }\n\n return reference;\n}\n\nexport let createDebugAliasRef: undefined | ((debugLabel: string, inner: Reference) => Reference);\n\nif (import.meta.env.DEV) {\n createDebugAliasRef = (debugLabel: string, inner: Reference) => {\n const update = isUpdatableRef(inner) ? (value: unknown) => updateRef(inner, value) : null;\n const ref = createComputeRef(() => valueForRef(inner), update);\n\n ref[REFERENCE] = inner[REFERENCE];\n\n ref.debugLabel = debugLabel;\n\n return ref;\n };\n}\n","import { getPath, toIterator } from '@glimmer/global-context';\nimport type { Dict, Nullable } from \"@glimmer/interfaces\";\nimport { EMPTY_ARRAY, isObject } from '@glimmer/util';\nimport { consumeTag, createTag, dirtyTag } from '@glimmer/validator';\n\nimport {\n createComputeRef,\n type Reference,\n type ReferenceEnvironment,\n valueForRef,\n} from './reference';\n\nexport interface IterationItem<T, U> {\n key: unknown;\n value: T;\n memo: U;\n}\n\nexport interface AbstractIterator<T, U, V extends IterationItem<T, U>> {\n isEmpty(): boolean;\n next(): Nullable<V>;\n}\n\nexport type OpaqueIterationItem = IterationItem<unknown, unknown>;\nexport type OpaqueIterator = AbstractIterator<unknown, unknown, OpaqueIterationItem>;\n\nexport interface IteratorDelegate {\n isEmpty(): boolean;\n next(): { value: unknown; memo: unknown } | null;\n}\n\nexport interface IteratorReferenceEnvironment extends ReferenceEnvironment {\n getPath(obj: unknown, path: string): unknown;\n toIterator(obj: unknown): Nullable<IteratorDelegate>;\n}\n\ntype KeyFor = (item: unknown, index: unknown) => unknown;\n\nconst NULL_IDENTITY = {};\n\nconst KEY: KeyFor = (_, index) => index;\nconst INDEX: KeyFor = (_, index) => String(index);\nconst IDENTITY: KeyFor = (item) => {\n if (item === null) {\n // Returning null as an identity will cause failures since the iterator\n // can't tell that it's actually supposed to be null\n return NULL_IDENTITY;\n }\n\n return item;\n};\n\nfunction keyForPath(path: string): KeyFor {\n if (import.meta.env.DEV && path[0] === '@') {\n throw new Error(`invalid keypath: '${path}', valid keys: @index, @identity, or a path`);\n }\n return uniqueKeyFor((item) => getPath(item as object, path));\n}\n\nfunction makeKeyFor(key: string) {\n switch (key) {\n case '@key':\n return uniqueKeyFor(KEY);\n case '@index':\n return uniqueKeyFor(INDEX);\n case '@identity':\n return uniqueKeyFor(IDENTITY);\n default:\n return keyForPath(key);\n }\n}\n\nclass WeakMapWithPrimitives<T> {\n private _weakMap?: WeakMap<object, T>;\n private _primitiveMap?: Map<unknown, T>;\n\n private get weakMap() {\n if (this._weakMap === undefined) {\n this._weakMap = new WeakMap();\n }\n\n return this._weakMap;\n }\n\n private get primitiveMap() {\n if (this._primitiveMap === undefined) {\n this._primitiveMap = new Map();\n }\n\n return this._primitiveMap;\n }\n\n set(key: unknown, value: T) {\n if (isObject(key)) {\n this.weakMap.set(key, value);\n } else {\n this.primitiveMap.set(key, value);\n }\n }\n\n get(key: unknown): T | undefined {\n if (isObject(key)) {\n return this.weakMap.get(key);\n } else {\n return this.primitiveMap.get(key);\n }\n }\n}\n\nconst IDENTITIES = new WeakMapWithPrimitives<object[]>();\n\nfunction identityForNthOccurence(value: any, count: number) {\n let identities = IDENTITIES.get(value);\n\n if (identities === undefined) {\n identities = [];\n IDENTITIES.set(value, identities);\n }\n\n let identity = identities[count];\n\n if (identity === undefined) {\n identity = { value, count };\n identities[count] = identity;\n }\n\n return identity;\n}\n\n/**\n * When iterating over a list, it's possible that an item with the same unique\n * key could be encountered twice:\n *\n * ```js\n * let arr = ['same', 'different', 'same', 'same'];\n * ```\n *\n * In general, we want to treat these items as _unique within the list_. To do\n * this, we track the occurences of every item as we iterate the list, and when\n * an item occurs more than once, we generate a new unique key just for that\n * item, and that occurence within the list. The next time we iterate the list,\n * and encounter an item for the nth time, we can get the _same_ key, and let\n * Glimmer know that it should reuse the DOM for the previous nth occurence.\n */\nfunction uniqueKeyFor(keyFor: KeyFor) {\n let seen = new WeakMapWithPrimitives<number>();\n\n return (value: unknown, memo: unknown) => {\n let key = keyFor(value, memo);\n let count = seen.get(key) || 0;\n\n seen.set(key, count + 1);\n\n if (count === 0) {\n return key;\n }\n\n return identityForNthOccurence(key, count);\n };\n}\n\nexport function createIteratorRef(listRef: Reference, key: string) {\n return createComputeRef(() => {\n let iterable = valueForRef(listRef) as { [Symbol.iterator]: any } | null | false;\n\n let keyFor = makeKeyFor(key);\n\n if (Array.isArray(iterable)) {\n return new ArrayIterator(iterable, keyFor);\n }\n\n let maybeIterator = toIterator(iterable);\n\n if (maybeIterator === null) {\n return new ArrayIterator(EMPTY_ARRAY, () => null);\n }\n\n return new IteratorWrapper(maybeIterator, keyFor);\n });\n}\n\nexport function createIteratorItemRef(_value: unknown) {\n let value = _value;\n let tag = createTag();\n\n return createComputeRef(\n () => {\n consumeTag(tag);\n return value;\n },\n (newValue) => {\n if (value !== newValue) {\n value = newValue;\n dirtyTag(tag);\n }\n }\n );\n}\n\nclass IteratorWrapper implements OpaqueIterator {\n constructor(private inner: IteratorDelegate, private keyFor: KeyFor) {}\n\n isEmpty() {\n return this.inner.isEmpty();\n }\n\n next() {\n let nextValue = this.inner.next() as OpaqueIterationItem;\n\n if (nextValue !== null) {\n nextValue.key = this.keyFor(nextValue.value, nextValue.memo);\n }\n\n return nextValue;\n }\n}\n\nclass ArrayIterator implements OpaqueIterator {\n private current: { kind: 'empty' } | { kind: 'first'; value: unknown } | { kind: 'progress' };\n private pos = 0;\n\n constructor(private iterator: unknown[] | readonly unknown[], private keyFor: KeyFor) {\n if (iterator.length === 0) {\n this.current = { kind: 'empty' };\n } else {\n this.current = { kind: 'first', value: iterator[this.pos] };\n }\n }\n\n isEmpty(): boolean {\n return this.current.kind === 'empty';\n }\n\n next(): Nullable<IterationItem<unknown, number>> {\n let value: unknown;\n\n let current = this.current;\n if (current.kind === 'first') {\n this.current = { kind: 'progress' };\n value = current.value;\n } else if (this.pos >= this.iterator.length - 1) {\n return null;\n } else {\n value = this.iterator[++this.pos];\n }\n\n let { keyFor } = this;\n\n let key = keyFor(value as Dict, this.pos);\n let memo = this.pos;\n\n return { key, value, memo };\n }\n}\n"],"names":["REFERENCE","Symbol","COMPUTE","UNBOUND","ReferenceImpl","tag","lastRevision","INITIAL","lastValue","children","compute","update","debugLabel","constructor","type","this","createPrimitiveRef","value","ref","CONSTANT_TAG","String","UNDEFINED_REFERENCE","undefined","NULL_REFERENCE","TRUE_REFERENCE","FALSE_REFERENCE","createConstRef","createUnboundRef","createComputeRef","arguments","length","createReadOnlyRef","isUpdatableRef","valueForRef","isInvokableRef","createInvokableRef","inner","updateRef","isConstRef","_ref","validateTag","newTag","track","valueForTag","consumeTag","expect","childRefFor","_parentRef","path","parentRef","child","Map","get","parent","isDict","getProp","val","setProp","set","childRefFromParts","root","parts","reference","part","createDebugAliasRef","NULL_IDENTITY","KEY","_","index","INDEX","IDENTITY","item","makeKeyFor","key","uniqueKeyFor","Error","getPath","keyForPath","WeakMapWithPrimitives","_weakMap","_primitiveMap","weakMap","WeakMap","primitiveMap","isObject","IDENTITIES","keyFor","seen","memo","count","identities","identity","identityForNthOccurence","createIteratorRef","listRef","iterable","Array","isArray","ArrayIterator","maybeIterator","toIterator","EMPTY_ARRAY","IteratorWrapper","createIteratorItemRef","_value","createTag","newValue","dirtyTag","isEmpty","next","nextValue","current","pos","iterator","kind"],"mappings":"6UAuBaA,EAA6BC,OAAO,aAG3CC,EAA4B,EAC5BC,EAA4B,EAalC,MAAMC,EACJJ,CAACA,GACMK,IAAqB,KACrBC,aAAyBC,EACzBC,UAEAC,SAAyD,KAEzDC,QAA6B,KAC7BC,OAAqC,KAErCC,WAEPC,WAAAA,CAAYC,GACVC,KAAKf,GAAac,CACpB,EAGK,SAASE,EAAmBC,GACjC,MAAMC,EAAM,IAAId,EAAcD,GAS9B,OAPAe,EAAIb,IAAMc,EACVD,EAAIV,UAAYS,EAGdC,EAAIN,WAAaQ,OAAOH,GAGnBC,CACT,OAEaG,EAAsBL,OAAmBM,GACzCC,EAAiBP,EAAmB,MACpCQ,EAAiBR,GAAmB,GACpCS,EAAkBT,GA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ApB2B,EAASnF,OACXf,KAAKgG,QAAU,CAAEG,KAAM,SAEvBnG,KAAKgG,QAAU,CAAEG,KAAM,QAASjG,MAAOgG,EAASlG,KAAKiG,KAEzD,CAEAJ,OAAAA,GACE,MAA6B,UAAtB7F,KAAKgG,QAAQG,IACtB,CAEAL,IAAAA,GACE,IAAI5F,EAEA8F,EAAUhG,KAAKgG,QACnB,GAAqB,UAAjBA,EAAQG,KACVnG,KAAKgG,QAAU,CAAEG,KAAM,YACvBjG,EAAQ8F,EAAQ9F,UACX,IAAIF,KAAKiG,KAAOjG,KAAKkG,SAASnF,OAAS,EAC5C,OAAO,KAEPb,EAAQF,KAAKkG,WAAWlG,KAAKiG,IAC/B,CAEA,IAAI1B,OAAEA,GAAWvE,KAKjB,MAAO,CAAE0D,IAHCa,EAAOrE,EAAeF,KAAKiG,KAGvB/F,QAAOuE,KAFVzE,KAAKiG,IAGlB"} |
+6
-6
| { | ||
| "name": "@glimmer/reference", | ||
| "type": "module", | ||
| "version": "0.85.5", | ||
| "version": "0.85.6", | ||
| "description": "Objects used to track values and their dirtiness in Glimmer", | ||
@@ -17,6 +17,6 @@ "license": "MIT", | ||
| "@glimmer/env": "^0.1.7", | ||
| "@glimmer/global-context": "^0.85.5", | ||
| "@glimmer/interfaces": "^0.85.5", | ||
| "@glimmer/util": "^0.85.5", | ||
| "@glimmer/validator": "^0.85.5" | ||
| "@glimmer/global-context": "^0.85.6", | ||
| "@glimmer/interfaces": "^0.85.6", | ||
| "@glimmer/util": "^0.85.6", | ||
| "@glimmer/validator": "^0.85.6" | ||
| }, | ||
@@ -27,3 +27,3 @@ "devDependencies": { | ||
| "publint": "^0.2.5", | ||
| "@glimmer/local-debug-flags": "^0.85.5", | ||
| "@glimmer/local-debug-flags": "^0.85.6", | ||
| "@glimmer-workspace/build-support": "^1.0.0" | ||
@@ -30,0 +30,0 @@ }, |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
1
-50%44380
-21.59%545
-39.11%3
50%Updated
Updated
Updated