@glimmer/reference
Advanced tools
Comparing version 0.92.3 to 0.93.0
@@ -5,7 +5,7 @@ import { DEBUG } from "@glimmer/env"; | ||
import { expect, isDict, EMPTY_ARRAY, isObject } from "@glimmer/util"; | ||
import { isDict, EMPTY_ARRAY, isIndexable } from "@glimmer/util"; | ||
import { CONSTANT_TAG, validateTag, track, valueForTag, consumeTag, INITIAL, createTag, dirtyTag } from "@glimmer/validator"; | ||
const REFERENCE = Symbol("REFERENCE"), COMPUTE = 1, UNBOUND = 2; | ||
const REFERENCE = Symbol("REFERENCE"); | ||
@@ -28,3 +28,3 @@ ////////// | ||
function createPrimitiveRef(value) { | ||
const ref = new ReferenceImpl(UNBOUND); | ||
const ref = new ReferenceImpl(2); | ||
return ref.tag = CONSTANT_TAG, ref.lastValue = value, DEBUG && (ref.debugLabel = String(value)), | ||
@@ -43,3 +43,3 @@ ref; | ||
function createUnboundRef(value, debugLabel) { | ||
const ref = new ReferenceImpl(UNBOUND); | ||
const ref = new ReferenceImpl(2); | ||
return ref.lastValue = value, ref.tag = CONSTANT_TAG, DEBUG && (ref.debugLabel = debugLabel), | ||
@@ -50,3 +50,3 @@ ref; | ||
function createComputeRef(compute, update = null, debugLabel = "unknown") { | ||
const ref = new ReferenceImpl(COMPUTE); | ||
const ref = new ReferenceImpl(1); | ||
return ref.compute = compute, ref.update = update, DEBUG && (ref.debugLabel = `(result of a \`${debugLabel}\` helper)`), | ||
@@ -93,3 +93,3 @@ ref; | ||
function updateRef(_ref, value) { | ||
expect(_ref.update, "called update on a non-updatable reference")(value); | ||
(0, _ref.update)(value); | ||
} | ||
@@ -102,3 +102,3 @@ | ||
void 0 !== child) return child; | ||
if (type === UNBOUND) { | ||
if (2 === type) { | ||
const parent = valueForRef(parentRef); | ||
@@ -141,6 +141,6 @@ child = isDict(parent) ? createUnboundRef(parent[path], DEBUG && `${parentRef.debugLabel}.${path}`) : UNDEFINED_REFERENCE; | ||
set(key, value) { | ||
isObject(key) ? this.weakMap.set(key, value) : this.primitiveMap.set(key, value); | ||
isIndexable(key) ? this.weakMap.set(key, value) : this.primitiveMap.set(key, value); | ||
} | ||
get(key) { | ||
return isObject(key) ? this.weakMap.get(key) : this.primitiveMap.get(key); | ||
return isIndexable(key) ? this.weakMap.get(key) : this.primitiveMap.get(key); | ||
} | ||
@@ -151,2 +151,3 @@ } | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
/** | ||
@@ -185,2 +186,3 @@ * When iterating over a list, it's possible that an item with the same unique | ||
return createComputeRef((() => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let iterable = valueForRef(listRef), keyFor = function(key) { | ||
@@ -187,0 +189,0 @@ switch (key) { |
@@ -1,2 +0,2 @@ | ||
import{setProp as t,getProp as e,toIterator as n,getPath as r}from"@glimmer/global-context";import{expect as i,isDict as u,EMPTY_ARRAY as s,isObject as l}from"@glimmer/util";import{CONSTANT_TAG as o,validateTag as a,track as c,valueForTag as p,consumeTag as f,INITIAL as h,createTag as m,dirtyTag as d}from"@glimmer/validator";const g=Symbol("REFERENCE"),v=1,k=2;class w{[g];tag=null;lastRevision=h;lastValue;children=null;compute=null;update=null;debugLabel;constructor(t){this[g]=t}}function M(t){const e=new w(k);return e.tag=o,e.lastValue=t,e}const y=M(void 0),b=M(null),_=M(!0),E=M(!1);function V(t,e){const n=new w(0);return n.lastValue=t,n.tag=o,n}function x(t,e){const n=new w(k);return n.lastValue=t,n.tag=o,n}function F(t,e=null,n="unknown"){const r=new w(v);return r.compute=t,r.update=e,r}function R(t){return C(t)?F((()=>N(t)),null,t.debugLabel):t}function L(t){return 3===t[g]}function A(t){const e=F((()=>N(t)),(e=>W(t,e)));return e.debugLabel=t.debugLabel,e[g]=3,e}function S(t){return t.tag===o}function C(t){return null!==t.update}function N(t){const e=t;let{tag:n}=e;if(n===o)return e.lastValue;const{lastRevision:r}=e;let i;if(null!==n&&a(n,r))i=e.lastValue;else{const{compute:t}=e,r=c((()=>{i=e.lastValue=t()}),!1);n=e.tag=r,e.lastRevision=p(r)}return f(n),i}function W(t,e){i(t.update,"called update on a non-updatable reference")(e)}function j(n,r){const i=n,s=i[g];let l,o=i.children;if(null===o)o=i.children=new Map;else if(l=o.get(r),void 0!==l)return l;if(s===k){const t=N(i);l=u(t)?x(t[r]):y}else l=F((()=>{const t=N(i);if(u(t))return e(t,r)}),(e=>{const n=N(i);if(u(n))return t(n,r,e)}));return o.set(r,l),l}function q(t,e){let n=t;for(const t of e)n=j(n,t);return n}let z;const B={},D=(t,e)=>e,G=(t,e)=>String(e),H=t=>null===t?B: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){l(t)?this.weakMap.set(t,e):this.primitiveMap.set(t,e)}get(t){return l(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 F((()=>{let i=N(t),u=function(t){switch(t){case"@key":return K(D);case"@index":return K(G);case"@identity":return K(H);default:return e=t,K((t=>r(t,e)))}var e}(e);if(Array.isArray(i))return new T(i,u);let l=n(i);return null===l?new T(s,(()=>null)):new Q(l,u)}))}function P(t){let e=t,n=m();return F((()=>(f(n),e)),(t=>{e!==t&&(e=t,d(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,b as NULL_REFERENCE,g as REFERENCE,_ as TRUE_REFERENCE,y as UNDEFINED_REFERENCE,j as childRefFor,q as childRefFromParts,F as createComputeRef,V as createConstRef,z as createDebugAliasRef,A as createInvokableRef,P as createIteratorItemRef,O as createIteratorRef,M as createPrimitiveRef,R as createReadOnlyRef,x as createUnboundRef,S as isConstRef,L as isInvokableRef,C as isUpdatableRef,W as updateRef,N as valueForRef}; | ||
import{setProp as t,getProp as e,toIterator as n,getPath as r}from"@glimmer/global-context";import{isDict as i,EMPTY_ARRAY as u,isIndexable as s}from"@glimmer/util";import{CONSTANT_TAG as l,validateTag as o,track as a,valueForTag as c,consumeTag as p,INITIAL as h,createTag as f,dirtyTag as m}from"@glimmer/validator";const g=Symbol("REFERENCE");class d{[g];tag=null;lastRevision=h;lastValue;children=null;compute=null;update=null;debugLabel;constructor(t){this[g]=t}}function v(t){const e=new d(2);return e.tag=l,e.lastValue=t,e}const k=v(void 0),w=v(null),M=v(!0),y=v(!1);function b(t,e){const n=new d(0);return n.lastValue=t,n.tag=l,n}function _(t,e){const n=new d(2);return n.lastValue=t,n.tag=l,n}function E(t,e=null,n="unknown"){const r=new d(1);return r.compute=t,r.update=e,r}function V(t){return L(t)?E((()=>A(t)),null,t.debugLabel):t}function x(t){return 3===t[g]}function F(t){const e=E((()=>A(t)),(e=>S(t,e)));return e.debugLabel=t.debugLabel,e[g]=3,e}function R(t){return t.tag===l}function L(t){return null!==t.update}function A(t){const e=t;let{tag:n}=e;if(n===l)return e.lastValue;const{lastRevision:r}=e;let i;if(null!==n&&o(n,r))i=e.lastValue;else{const{compute:t}=e,r=a((()=>{i=e.lastValue=t()}),!1);n=e.tag=r,e.lastRevision=c(r)}return p(n),i}function S(t,e){(0,t.update)(e)}function C(n,r){const u=n,s=u[g];let l,o=u.children;if(null===o)o=u.children=new Map;else if(l=o.get(r),void 0!==l)return l;if(2===s){const t=A(u);l=i(t)?_(t[r]):k}else l=E((()=>{const t=A(u);if(i(t))return e(t,r)}),(e=>{const n=A(u);if(i(n))return t(n,r,e)}));return o.set(r,l),l}function N(t,e){let n=t;for(const t of e)n=C(n,t);return n}let W;const j={},q=(t,e)=>e,z=(t,e)=>String(e),B=t=>null===t?j:t;class D{_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 G=new D;function H(t){let e=new D;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=G.get(t);void 0===n&&(n=[],G.set(t,n));let r=n[e];return void 0===r&&(r={value:t,count:e},n[e]=r),r}(i,u)}}function I(t,e){return E((()=>{let i=A(t),s=function(t){switch(t){case"@key":return H(q);case"@index":return H(z);case"@identity":return H(B);default:return e=t,H((t=>r(t,e)))}var e}(e);if(Array.isArray(i))return new O(i,s);let l=n(i);return null===l?new O(u,(()=>null)):new K(l,s)}))}function J(t){let e=t,n=f();return E((()=>(p(n),e)),(t=>{e!==t&&(e=t,m(n))}))}class K{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 O{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{y as FALSE_REFERENCE,w as NULL_REFERENCE,g as REFERENCE,M as TRUE_REFERENCE,k as UNDEFINED_REFERENCE,C as childRefFor,N as childRefFromParts,E as createComputeRef,b as createConstRef,W as createDebugAliasRef,F as createInvokableRef,J as createIteratorItemRef,I as createIteratorRef,v as createPrimitiveRef,V as createReadOnlyRef,_ as createUnboundRef,R as isConstRef,x as isInvokableRef,L as isUpdatableRef,S as updateRef,A as valueForRef}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@glimmer/reference", | ||
"version": "0.92.3", | ||
"version": "0.93.0", | ||
"license": "MIT", | ||
@@ -12,4 +12,22 @@ "description": "Objects used to track values and their dirtiness in Glimmer", | ||
"type": "module", | ||
"main": null, | ||
"types": "dist/dev/index.d.ts", | ||
"exports": { | ||
".": { | ||
"require": { | ||
"development": { | ||
"types": "./dist/dev/index.d.cts", | ||
"default": "./dist/dev/index.cjs" | ||
} | ||
}, | ||
"default": { | ||
"development": { | ||
"types": "./dist/dev/index.d.ts", | ||
"default": "./dist/dev/index.js" | ||
}, | ||
"default": { | ||
"types": "./dist/prod/index.d.ts", | ||
"default": "./dist/prod/index.js" | ||
} | ||
} | ||
} | ||
}, | ||
"publishConfig": { | ||
@@ -23,6 +41,6 @@ "access": "public" | ||
"@glimmer/env": "^0.1.7", | ||
"@glimmer/global-context": "0.92.3", | ||
"@glimmer/interfaces": "0.92.3", | ||
"@glimmer/validator": "0.92.3", | ||
"@glimmer/util": "0.92.3" | ||
"@glimmer/global-context": "0.92.4", | ||
"@glimmer/interfaces": "0.93.0", | ||
"@glimmer/util": "0.93.0", | ||
"@glimmer/validator": "0.93.0" | ||
}, | ||
@@ -34,4 +52,5 @@ "devDependencies": { | ||
"typescript": "*", | ||
"@glimmer/local-debug-flags": "0.92.0", | ||
"@glimmer-workspace/build-support": "1.0.0" | ||
"@glimmer-workspace/build-support": "1.0.0", | ||
"@glimmer/debug-util": "0.92.3", | ||
"@glimmer/local-debug-flags": "0.92.0" | ||
}, | ||
@@ -43,15 +62,3 @@ "scripts": { | ||
"test:types": "tsc --noEmit -p ../tsconfig.json" | ||
}, | ||
"exports": { | ||
".": { | ||
"types": "./dist/dev/index.d.ts", | ||
"development": { | ||
"require": "./dist/dev/index.cjs", | ||
"import": "./dist/dev/index.js" | ||
}, | ||
"require": "./dist/dev/index.cjs", | ||
"import": "./dist/prod/index.js" | ||
} | ||
}, | ||
"module": "dist/dev/index.js" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
58277
7
14
757
+ Added@glimmer/global-context@0.92.4(transitive)
+ Added@glimmer/interfaces@0.93.0(transitive)
+ Added@glimmer/util@0.93.0(transitive)
+ Added@glimmer/validator@0.93.0(transitive)
- Removed@glimmer/global-context@0.92.3(transitive)
- Removed@glimmer/interfaces@0.92.3(transitive)
- Removed@glimmer/util@0.92.3(transitive)
- Removed@glimmer/validator@0.92.3(transitive)
Updated@glimmer/interfaces@0.93.0
Updated@glimmer/util@0.93.0
Updated@glimmer/validator@0.93.0