Skip to content

Commit

Permalink
fix edge cases: missing ref check in deep-replace, prefer Object.hasOwn
Browse files Browse the repository at this point in the history
  • Loading branch information
gr0uch committed Jun 2, 2022
1 parent f80ae01 commit 0e1f701
Show file tree
Hide file tree
Showing 11 changed files with 321 additions and 321 deletions.
2 changes: 1 addition & 1 deletion dist/computed-properties.min.mjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var r=new WeakMap,t=new WeakMap,e=[],n=!1,o=Symbol("stackDelimiter"),f=Symbol("ref"),i=Symbol("hasUnmounted"),a=Symbol("proxyTarget"),u=function(){var r=h();return{get:s,set:r,deleteProperty:r}}(),l=function(){var r=h(!0);return{get:s,set:r,deleteProperty:r}}();function c(){for(;e.length;)e.pop();return n=!1}function v(){for(var r=e.length-1;r>=0&&e.pop()!==o;r-=1);}function s(r,t,f){if(t===a)return r;for(var i=!1,u=e.length-1;u>=0;u-=1){var l=e[u];if(l===o)break;l[0]===r&&l[1]===t&&(i=!0)}return i||(e.push([r,t]),n||(n=!0,queueMicrotask(c))),Reflect.get(r,t,f)}function p(r){return r&&"object"==typeof r}function h(t){return function(e,n,o,u){var l=e[n];if(l===o)return!0;if(t&&p(o)&&!o[f]){if(p(l)&&!l[f])return y(u[a][n],o),!0;o=g(o,!0)}void 0!==o?Reflect.set(e,n,o,u):Reflect.deleteProperty(e,n);var c,v=r.get(e);if(!v)return!0;for(var s=(c=v[n]||[]).length-1;s>=0;s-=1){var h=c[s];if(h){var d=h[0],m=h[1],P=h[2];d[i]||b(d,m,P)}}return!0}}function y(r,t){var e=r[a];for(var n in t){var o=t[n],f=e[n];p(o)&&p(f)?y(f,o):r[n]=o}for(var n in e){e[n];t.hasOwnProperty(n)||delete r[n]}}function g(r,t){r||(r={});var e=new Proxy(r,t?l:u),n=r[Object.getOwnPropertySymbols(r)[0]];if(t)for(var o in r){var i=r[o];p(i)&&!i[f]&&(r[o]=g(i,!0))}return"function"==typeof n&&n.call(e),e}function b(n,f,i){e.push(o);var a=e.length-1,u=null,l=i.call(n),c=[];void 0!==l?n[f]=l:delete n[f],t.set(n,c);for(var s=e.length-1,p=a+1;p<=s&&e[p]!==o;p+=1)u=p;var h=a+1;for(p=u;p>=h;p-=1){var y=e[p],g=y[0],b=y[1],d=null;c.includes(g)||c.push(g),r.has(g)||r.set(g,{}),(d=r.get(g)).hasOwnProperty(b)||(d[b]=[]);var m=d[b],P=m.findIndex((function(r){return r[0]===n&&r[1]===f}));-1!==P&&m.splice(P,1),m.push([n,f,i])}return v(),l}function d(e){var n=t.get(e);if(n){for(var o=n.length,f=0;f<o;f+=1){var a=n[f],u=r.get(a);for(var l in u)for(var c=u[l],v=c.length-1;v>=0;v-=1){c[v][0]===e&&c.splice(v,1)}}return e[i]=!0}}function m(r,t){return function(e){var n=e[r],o=e[t];return e[r]=function(){if(n&&n.call(this),!arguments.length)for(var r in e){var t=e[r];"function"==typeof t&&t.call(this)}},e[t]=function(){return o&&o.call(this),d(this)},Object.keys(e).forEach((function(r){var t=e[r];if("function"==typeof t){return e[r]=function(){var e=this[r];return e&&e.isEventListener?t.apply(this,arguments):b(this,r,t)}}})),e}}function P(r){return r[f]=!0,r}export{g as observable,g as createSource,m as createComputed,P as ref};
var r=new WeakMap,t=new WeakMap,e=[],n=!1,o=Symbol("stackDelimiter"),f=Symbol("ref"),i=Symbol("hasUnmounted"),a=Symbol("proxyTarget"),u=function(){var r=p();return{get:s,set:r,deleteProperty:r}}(),c=function(){var r=p(!0);return{get:s,set:r,deleteProperty:r}}();function l(){for(;e.length;)e.pop();return n=!1}function v(){for(var r=e.length-1;r>=0&&e.pop()!==o;r-=1);}function s(r,t,f){if(t===a)return r;for(var i=!1,u=e.length-1;u>=0;u-=1){var c=e[u];if(c===o)break;c[0]===r&&c[1]===t&&(i=!0)}return i||(e.push([r,t]),n||(n=!0,queueMicrotask(l))),Reflect.get(r,t,f)}function h(r){return r&&"object"==typeof r}function p(t){return function(e,n,o,a){var u=e[n];if(u===o)return!0;if(t&&h(o)&&!o[f]){if(h(u)&&!u[f])return g(u,o),!0;o=y(o,!0)}void 0!==o?Reflect.set(e,n,o,a):Reflect.deleteProperty(e,n);var c,l=r.get(e);if(!l)return!0;for(var v=(c=l[n]||[]).length-1;v>=0;v-=1){var s=c[v];if(s){var p=s[0],d=s[1],m=s[2];p[i]||b(p,d,m)}}return!0}}function g(r,t){var e=r[a];for(var n in t){var o=t[n],i=e[n];h(o)&&h(i)&&!i[f]?g(i,o):r[n]=o}for(var n in e){e[n];Object.hasOwn(t,n)||delete r[n]}}function y(r,t){r||(r={});var e=new Proxy(r,t?c:u),n=r[Object.getOwnPropertySymbols(r)[0]];if(t)for(var o in r){var i=r[o];h(i)&&!i[f]&&(r[o]=y(i,!0))}return"function"==typeof n&&n.call(e),e}function b(n,f,i){e.push(o);var a=e.length-1,u=null,c=i.call(n),l=[];void 0!==c?n[f]=c:delete n[f],t.set(n,l);for(var s=e.length-1,h=a+1;h<=s&&e[h]!==o;h+=1)u=h;var p=a+1;for(h=u;h>=p;h-=1){var g=e[h],y=g[0],b=g[1],d=null;l.includes(y)||l.push(y),r.has(y)||r.set(y,{}),d=r.get(y),Object.hasOwn(d,b)||(d[b]=[]);var m=d[b],O=m.findIndex((function(r){return r[0]===n&&r[1]===f}));-1!==O&&m.splice(O,1),m.push([n,f,i])}return v(),c}function d(e){var n=t.get(e);if(n){for(var o=n.length,f=0;f<o;f+=1){var a=n[f],u=r.get(a);for(var c in u)for(var l=u[c],v=l.length-1;v>=0;v-=1){l[v][0]===e&&l.splice(v,1)}}return e[i]=!0}}function m(r,t){return function(e){var n=e[r],o=e[t];return e[r]=function(){if(n&&n.call(this),!arguments.length)for(var r in e){var t=e[r];"function"==typeof t&&t.call(this)}},e[t]=function(){return o&&o.call(this),d(this)},Object.keys(e).forEach((function(r){var t=e[r];if("function"==typeof t){return e[r]=function(){var e=this[r];return e&&e.isEventListener?t.apply(this,arguments):b(this,r,t)}}})),e}}function O(r){return r[f]=!0,r}export{y as observable,y as createSource,m as createComputed,O as ref};
34 changes: 17 additions & 17 deletions dist/computed-properties.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ function isObject(obj) {
(IF (AND (IS-OBJECT OLD-VALUE)
(NOT (GETPROP OLD-VALUE *REF-SYMBOL*)))
(PROGN
(DEEP-REPLACE
(GETPROP (GETPROP RECEIVER *PROXY-TARGET-SYMBOL*) KEY) VALUE)
(DEEP-REPLACE OLD-VALUE VALUE)
(RETURN-FROM SET-PROPERTY T))
(SETF VALUE (CREATE-SOURCE VALUE T)))))
(IF (NOT (EQ VALUE UNDEFINED))
Expand Down Expand Up @@ -138,7 +137,7 @@ function makeSetProperty(isDeep) {
};
if (isDeep && isObject(value) && !value[REFSYMBOL]) {
if (isObject(oldValue) && !oldValue[REFSYMBOL]) {
deepReplace(receiver[PROXYTARGETSYMBOL][key], value);
deepReplace(oldValue, value);

return true;
} else {
Expand Down Expand Up @@ -180,27 +179,28 @@ function makeSetProperty(isDeep) {
(LOOP FOR KEY OF OBJ
DO (LET ((VALUE (GETPROP OBJ KEY))
(OLD-VALUE (GETPROP OLD-TARGET KEY)))
(IF (AND (IS-OBJECT VALUE) (IS-OBJECT OLD-VALUE))
(IF (AND (IS-OBJECT VALUE) (IS-OBJECT OLD-VALUE)
(NOT (GETPROP OLD-VALUE *REF-SYMBOL*)))
(DEEP-REPLACE OLD-VALUE VALUE)
(SETF (GETPROP PROXY KEY) VALUE))))
(LOOP FOR KEY OF OLD-TARGET
DO (LET ((OLD-VALUE (GETPROP OLD-TARGET KEY)))
(WHEN (NOT (CHAIN OBJ (HAS-OWN-PROPERTY KEY)))
(WHEN (NOT (CHAIN *OBJECT (HAS-OWN OBJ KEY)))
(DELETE (GETPROP PROXY KEY))))))) */
function deepReplace(proxy, obj) {
var oldTarget = proxy[PROXYTARGETSYMBOL];
for (var key in obj) {
var value = obj[key];
var oldValue = oldTarget[key];
if (isObject(value) && isObject(oldValue)) {
if (isObject(value) && isObject(oldValue) && !oldValue[REFSYMBOL]) {
deepReplace(oldValue, value);
} else {
proxy[key] = value;
};
};
for (var key in oldTarget) {
var oldValue1 = oldTarget[key];
if (!obj.hasOwnProperty(key)) {
var oldValue5 = oldTarget[key];
if (!Object.hasOwn(obj, key)) {
delete proxy[key];
};
};
Expand Down Expand Up @@ -269,7 +269,7 @@ function createSource(obj, isDeep) {
(CHAIN *OBSERVABLE-CONTEXT-MAP* (SET OBSERVABLE (CREATE))))
(SETF CONTEXT
(CHAIN *OBSERVABLE-CONTEXT-MAP* (GET OBSERVABLE)))
(WHEN (NOT (CHAIN CONTEXT (HAS-OWN-PROPERTY OBSERVABLE-KEY)))
(WHEN (NOT (CHAIN *OBJECT (HAS-OWN CONTEXT OBSERVABLE-KEY)))
(SETF (GETPROP CONTEXT OBSERVABLE-KEY) (LIST)))
(LET* ((KEY-BINDINGS (GETPROP CONTEXT OBSERVABLE-KEY))
(MATCH-INDEX
Expand All @@ -295,15 +295,15 @@ function computeDependencies(obj, key, fn) {
delete obj[key];
};
TARGETOBSERVABLESMAP.set(obj, observables);
var _js1 = READSTACK.length - 1;
for (var i = delimiterIndex + 1; i <= _js1; i += 1) {
var _js5 = READSTACK.length - 1;
for (var i = delimiterIndex + 1; i <= _js5; i += 1) {
if (READSTACK[i] === STACKDELIMITERSYMBOL) {
break;
};
upperIndex = i;
};
var _js2 = delimiterIndex + 1;
for (var i = upperIndex; i >= _js2; i -= 1) {
var _js6 = delimiterIndex + 1;
for (var i = upperIndex; i >= _js6; i -= 1) {
var tuple = READSTACK[i];
var observable = tuple[0];
var observableKey = tuple[1];
Expand All @@ -315,7 +315,7 @@ function computeDependencies(obj, key, fn) {
OBSERVABLECONTEXTMAP.set(observable, { });
};
context = OBSERVABLECONTEXTMAP.get(observable);
if (!context.hasOwnProperty(observableKey)) {
if (!Object.hasOwn(context, observableKey)) {
context[observableKey] = [];
};
var keyBindings = context[observableKey];
Expand Down Expand Up @@ -353,9 +353,9 @@ function unmountObject(obj) {
if (!observables) {
return;
};
var _js4 = observables.length;
for (var _js3 = 0; _js3 < _js4; _js3 += 1) {
var observable = observables[_js3];
var _js8 = observables.length;
for (var _js7 = 0; _js7 < _js8; _js7 += 1) {
var observable = observables[_js7];
var context = OBSERVABLECONTEXTMAP.get(observable);
for (var key in context) {
var keyBindings = context[key];
Expand Down
20 changes: 10 additions & 10 deletions dist/dep-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ function depCheck(root) {
if (PASSEDCHECK) {
return;
};
var _js2 = DEPMAP.length;
for (var _js1 = 0; _js1 < _js2; _js1 += 1) {
var tuple = DEPMAP[_js1];
var _js6 = DEPMAP.length;
for (var _js5 = 0; _js5 < _js6; _js5 += 1) {
var tuple = DEPMAP[_js5];
var path = tuple[0];
var typeStr = tuple[1];
var target = root || window;
if (typeStr === 'property') {
var _js3 = path.length - 2;
for (var i = 0; i <= _js3; i += 1) {
var _js7 = path.length - 2;
for (var i = 0; i <= _js7; i += 1) {
var key = path[i];
if (target[key]) {
target = target[key];
Expand All @@ -74,11 +74,11 @@ function depCheck(root) {
};
continue;
};
var _js5 = path.length;
for (var _js4 = 0; _js4 < _js5; _js4 += 1) {
var key6 = path[_js4];
if (target[key6]) {
target = target[key6];
var _js9 = path.length;
for (var _js8 = 0; _js8 < _js9; _js8 += 1) {
var key10 = path[_js8];
if (target[key10]) {
target = target[key10];
} else {
target = undefined;
break;
Expand Down
Loading

0 comments on commit 0e1f701

Please sign in to comment.