Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

observable-membrane

Package Overview
Dependencies
Maintainers
12
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

observable-membrane - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

10

dist/commonjs/observable-membrane.js

@@ -7,3 +7,3 @@ /**

const { isArray } = Array;
const { getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, defineProperties: ObjectDefineProperties, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, freeze, } = Object;
const { getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, defineProperties: ObjectDefineProperties, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, } = Object;
const { push: ArrayPush, concat: ArrayConcat, map: ArrayMap, } = Array.prototype;

@@ -38,4 +38,2 @@ const OtS = {}.toString;

this.membrane = membrane;
// future proxy optimizations
freeze(this);
}

@@ -151,4 +149,2 @@ // Shared utility methods

}
// future proxy optimizations
freeze(BaseProxyHandler.prototype);

@@ -294,4 +290,2 @@ const getterMap = new WeakMap();

}
// future proxy optimizations
freeze(ReactiveProxyHandler.prototype);

@@ -367,4 +361,2 @@ const getterMap$1 = new WeakMap();

}
// future proxy optimizations
freeze(ReadOnlyHandler.prototype);

@@ -371,0 +363,0 @@ function extract(objectOrArray) {

@@ -5,3 +5,3 @@ /**

const { isArray } = Array;
const { getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, defineProperties: ObjectDefineProperties, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, freeze, } = Object;
const { getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, defineProperties: ObjectDefineProperties, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, } = Object;
const { push: ArrayPush, concat: ArrayConcat, map: ArrayMap, } = Array.prototype;

@@ -36,4 +36,2 @@ const OtS = {}.toString;

this.membrane = membrane;
// future proxy optimizations
freeze(this);
}

@@ -149,4 +147,2 @@ // Shared utility methods

}
// future proxy optimizations
freeze(BaseProxyHandler.prototype);

@@ -292,4 +288,2 @@ const getterMap = new WeakMap();

}
// future proxy optimizations
freeze(ReactiveProxyHandler.prototype);

@@ -365,4 +359,2 @@ const getterMap$1 = new WeakMap();

}
// future proxy optimizations
freeze(ReadOnlyHandler.prototype);

@@ -369,0 +361,0 @@ function extract(objectOrArray) {

8

dist/types/shared.d.ts

@@ -5,7 +5,3 @@ declare const isArray: (arg: any) => arg is any[];

(o: object | null, properties: PropertyDescriptorMap & ThisType<any>): any;
}, ObjectDefineProperty: (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType<any>) => any, ObjectDefineProperties: (o: any, properties: PropertyDescriptorMap & ThisType<any>) => any, isExtensible: (o: any) => boolean, getOwnPropertyDescriptor: (o: any, p: string | number | symbol) => PropertyDescriptor | undefined, getOwnPropertyNames: (o: any) => string[], getOwnPropertySymbols: (o: any) => symbol[], preventExtensions: <T>(o: T) => T, hasOwnProperty: (v: string | number | symbol) => boolean, freeze: {
<T>(a: T[]): readonly T[];
<T_1 extends Function>(f: T_1): T_1;
<T_2>(o: T_2): Readonly<T_2>;
};
}, ObjectDefineProperty: (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType<any>) => any, ObjectDefineProperties: (o: any, properties: PropertyDescriptorMap & ThisType<any>) => any, isExtensible: (o: any) => boolean, getOwnPropertyDescriptor: (o: any, p: string | number | symbol) => PropertyDescriptor | undefined, getOwnPropertyNames: (o: any) => string[], getOwnPropertySymbols: (o: any) => symbol[], preventExtensions: <T>(o: T) => T, hasOwnProperty: (v: string | number | symbol) => boolean;
declare const ArrayPush: (...items: any[]) => number, ArrayConcat: {

@@ -15,3 +11,3 @@ (...items: ConcatArray<any>[]): any[];

}, ArrayMap: <U>(callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[];
export { ArrayPush, ArrayConcat, ArrayMap, isArray, getPrototypeOf, ObjectCreate, ObjectDefineProperty, ObjectDefineProperties, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, freeze, };
export { ArrayPush, ArrayConcat, ArrayMap, isArray, getPrototypeOf, ObjectCreate, ObjectDefineProperty, ObjectDefineProperties, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, };
export declare function toString(obj: any): string;

@@ -18,0 +14,0 @@ export declare function isUndefined(obj: any): obj is undefined;

@@ -11,3 +11,3 @@ /**

const { isArray } = Array;
const { getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, defineProperties: ObjectDefineProperties, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, freeze, } = Object;
const { getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, defineProperties: ObjectDefineProperties, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, } = Object;
const { push: ArrayPush, concat: ArrayConcat, map: ArrayMap, } = Array.prototype;

@@ -42,4 +42,2 @@ const OtS = {}.toString;

this.membrane = membrane;
// future proxy optimizations
freeze(this);
}

@@ -155,4 +153,2 @@ // Shared utility methods

}
// future proxy optimizations
freeze(BaseProxyHandler.prototype);

@@ -298,4 +294,2 @@ const getterMap = new WeakMap();

}
// future proxy optimizations
freeze(ReactiveProxyHandler.prototype);

@@ -367,4 +361,2 @@ const getterMap$1 = new WeakMap();

}
// future proxy optimizations
freeze(ReadOnlyHandler.prototype);

@@ -371,0 +363,0 @@ function extract(objectOrArray) {

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).ObservableMembrane=t()}(this,(function(){"use strict";const{isArray:e}=Array,{getPrototypeOf:t,create:r,defineProperty:n,defineProperties:a,isExtensible:s,getOwnPropertyDescriptor:o,getOwnPropertyNames:i,getOwnPropertySymbols:u,preventExtensions:l,hasOwnProperty:c,freeze:p}=Object,{push:h,concat:g,map:y}=Array.prototype;function f(e){return void 0===e}function v(e){return"function"==typeof e}const w=new WeakMap;function b(e,t){w.set(e,t)}const d=e=>w.get(e)||e;class m{constructor(e,t){this.originalTarget=t,this.membrane=e,p(this)}wrapDescriptor(e){if(c.call(e,"value"))e.value=this.wrapValue(e.value);else{const{set:t,get:r}=e;f(r)||(e.get=this.wrapGetter(r)),f(t)||(e.set=this.wrapSetter(t))}return e}copyDescriptorIntoShadowTarget(e,t){const{originalTarget:r}=this,a=o(r,t);if(!f(a)){const r=this.wrapDescriptor(a);n(e,t,r)}}lockShadowTarget(e){const{originalTarget:t}=this;g.call(i(t),u(t)).forEach(t=>{this.copyDescriptorIntoShadowTarget(e,t)});const{membrane:{tagPropertyKey:a}}=this;f(a)||c.call(e,a)||n(e,a,r(null)),l(e)}apply(e,t,r){}construct(e,t,r){}get(e,t){const{originalTarget:r,membrane:{valueObserved:n}}=this,a=r[t];return n(r,t),this.wrapValue(a)}has(e,t){const{originalTarget:r,membrane:{tagPropertyKey:n,valueObserved:a}}=this;return a(r,t),t in r||t===n}ownKeys(e){const{originalTarget:t,membrane:{tagPropertyKey:r}}=this,n=f(r)||c.call(t,r)?[]:[r];return h.apply(n,i(t)),h.apply(n,u(t)),n}isExtensible(e){const{originalTarget:t}=this;return!!s(e)&&(!!s(t)||(this.lockShadowTarget(e),!1))}getPrototypeOf(e){const{originalTarget:r}=this;return t(r)}getOwnPropertyDescriptor(e,t){const{originalTarget:r,membrane:{valueObserved:a,tagPropertyKey:s}}=this;a(r,t);let i=o(r,t);if(f(i)){if(t!==s)return;return i={value:void 0,writable:!1,configurable:!1,enumerable:!1},n(e,s,i),i}return!1===i.configurable&&this.copyDescriptorIntoShadowTarget(e,t),this.wrapDescriptor(i)}}p(m.prototype);const O=new WeakMap,P=new WeakMap,T=new WeakMap,x=new WeakMap;class D extends m{wrapValue(e){return this.membrane.getProxy(e)}wrapGetter(e){const t=O.get(e);if(!f(t))return t;const r=this,n=function(){return r.wrapValue(e.call(d(this)))};return O.set(e,n),T.set(n,e),n}wrapSetter(e){const t=P.get(e);if(!f(t))return t;const r=function(t){e.call(d(this),d(t))};return P.set(e,r),x.set(r,e),r}unwrapDescriptor(e){if(c.call(e,"value"))e.value=d(e.value);else{const{set:t,get:r}=e;f(r)||(e.get=this.unwrapGetter(r)),f(t)||(e.set=this.unwrapSetter(t))}return e}unwrapGetter(e){const t=T.get(e);if(!f(t))return t;const r=this,n=function(){return d(e.call(r.wrapValue(this)))};return O.set(n,e),T.set(e,n),n}unwrapSetter(e){const t=x.get(e);if(!f(t))return t;const r=this,n=function(t){e.call(r.wrapValue(this),r.wrapValue(t))};return P.set(n,e),x.set(e,n),n}set(t,r,n){const{originalTarget:a,membrane:{valueMutated:s}}=this;return a[r]!==n?(a[r]=n,s(a,r)):"length"===r&&e(a)&&s(a,r),!0}deleteProperty(e,t){const{originalTarget:r,membrane:{valueMutated:n}}=this;return delete r[t],n(r,t),!0}setPrototypeOf(e,t){}preventExtensions(e){if(s(e)){const{originalTarget:t}=this;if(l(t),s(t))return!1;this.lockShadowTarget(e)}return!0}defineProperty(e,t,r){const{originalTarget:a,membrane:{valueMutated:s,tagPropertyKey:o}}=this;return t===o&&!c.call(a,t)||(n(a,t,this.unwrapDescriptor(r)),!1===r.configurable&&this.copyDescriptorIntoShadowTarget(e,t),s(a,t),!0)}}p(D.prototype);const S=new WeakMap,M=new WeakMap;class k extends m{wrapValue(e){return this.membrane.getReadOnlyProxy(e)}wrapGetter(e){const t=S.get(e);if(!f(t))return t;const r=this,n=function(){return r.wrapValue(e.call(d(this)))};return S.set(e,n),n}wrapSetter(e){const t=M.get(e);if(!f(t))return t;const r=function(e){};return M.set(e,r),r}set(e,t,r){return!1}deleteProperty(e,t){return!1}setPrototypeOf(e,t){}preventExtensions(e){return!1}defineProperty(e,t,r){return!1}}p(k.prototype);const I=Object.prototype;function V(r){if(null===r)return!1;if("object"!=typeof r)return!1;if(e(r))return!0;const n=t(r);return n===I||null===n||null===t(n)}const K=(e,t)=>{},W=(e,t)=>{},G=e=>e;function j(t){return e(t)?[]:{}}return class{constructor(e){if(this.valueDistortion=G,this.valueMutated=W,this.valueObserved=K,this.valueIsObservable=V,this.objectGraph=new WeakMap,!f(e)){const{valueDistortion:t,valueMutated:r,valueObserved:n,valueIsObservable:a,tagPropertyKey:s}=e;this.valueDistortion=v(t)?t:G,this.valueMutated=v(r)?r:W,this.valueObserved=v(n)?n:K,this.valueIsObservable=v(a)?a:V,this.tagPropertyKey=s}}getProxy(e){const t=d(e),r=this.valueDistortion(t);if(this.valueIsObservable(r)){const n=this.getReactiveState(t,r);return n.readOnly===e?e:n.reactive}return r}getReadOnlyProxy(e){e=d(e);const t=this.valueDistortion(e);return this.valueIsObservable(t)?this.getReactiveState(e,t).readOnly:t}unwrapProxy(e){return d(e)}getReactiveState(e,t){const{objectGraph:r}=this;let a=r.get(t);if(a)return a;const s=this;return a={get reactive(){const r=new D(s,t),a=new Proxy(j(t),r);return b(a,e),n(this,"reactive",{value:a}),a},get readOnly(){const r=new k(s,t),a=new Proxy(j(t),r);return b(a,e),n(this,"readOnly",{value:a}),a}},r.set(t,a),a}}}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).ObservableMembrane=t()}(this,(function(){"use strict";const{isArray:e}=Array,{getPrototypeOf:t,create:r,defineProperty:n,defineProperties:a,isExtensible:s,getOwnPropertyDescriptor:o,getOwnPropertyNames:i,getOwnPropertySymbols:u,preventExtensions:l,hasOwnProperty:c}=Object,{push:p,concat:h,map:g}=Array.prototype;function y(e){return void 0===e}function f(e){return"function"==typeof e}const v=new WeakMap;function w(e,t){v.set(e,t)}const b=e=>v.get(e)||e;class d{constructor(e,t){this.originalTarget=t,this.membrane=e}wrapDescriptor(e){if(c.call(e,"value"))e.value=this.wrapValue(e.value);else{const{set:t,get:r}=e;y(r)||(e.get=this.wrapGetter(r)),y(t)||(e.set=this.wrapSetter(t))}return e}copyDescriptorIntoShadowTarget(e,t){const{originalTarget:r}=this,a=o(r,t);if(!y(a)){const r=this.wrapDescriptor(a);n(e,t,r)}}lockShadowTarget(e){const{originalTarget:t}=this;h.call(i(t),u(t)).forEach(t=>{this.copyDescriptorIntoShadowTarget(e,t)});const{membrane:{tagPropertyKey:a}}=this;y(a)||c.call(e,a)||n(e,a,r(null)),l(e)}apply(e,t,r){}construct(e,t,r){}get(e,t){const{originalTarget:r,membrane:{valueObserved:n}}=this,a=r[t];return n(r,t),this.wrapValue(a)}has(e,t){const{originalTarget:r,membrane:{tagPropertyKey:n,valueObserved:a}}=this;return a(r,t),t in r||t===n}ownKeys(e){const{originalTarget:t,membrane:{tagPropertyKey:r}}=this,n=y(r)||c.call(t,r)?[]:[r];return p.apply(n,i(t)),p.apply(n,u(t)),n}isExtensible(e){const{originalTarget:t}=this;return!!s(e)&&(!!s(t)||(this.lockShadowTarget(e),!1))}getPrototypeOf(e){const{originalTarget:r}=this;return t(r)}getOwnPropertyDescriptor(e,t){const{originalTarget:r,membrane:{valueObserved:a,tagPropertyKey:s}}=this;a(r,t);let i=o(r,t);if(y(i)){if(t!==s)return;return i={value:void 0,writable:!1,configurable:!1,enumerable:!1},n(e,s,i),i}return!1===i.configurable&&this.copyDescriptorIntoShadowTarget(e,t),this.wrapDescriptor(i)}}const m=new WeakMap,O=new WeakMap,P=new WeakMap,T=new WeakMap;class x extends d{wrapValue(e){return this.membrane.getProxy(e)}wrapGetter(e){const t=m.get(e);if(!y(t))return t;const r=this,n=function(){return r.wrapValue(e.call(b(this)))};return m.set(e,n),P.set(n,e),n}wrapSetter(e){const t=O.get(e);if(!y(t))return t;const r=function(t){e.call(b(this),b(t))};return O.set(e,r),T.set(r,e),r}unwrapDescriptor(e){if(c.call(e,"value"))e.value=b(e.value);else{const{set:t,get:r}=e;y(r)||(e.get=this.unwrapGetter(r)),y(t)||(e.set=this.unwrapSetter(t))}return e}unwrapGetter(e){const t=P.get(e);if(!y(t))return t;const r=this,n=function(){return b(e.call(r.wrapValue(this)))};return m.set(n,e),P.set(e,n),n}unwrapSetter(e){const t=T.get(e);if(!y(t))return t;const r=this,n=function(t){e.call(r.wrapValue(this),r.wrapValue(t))};return O.set(n,e),T.set(e,n),n}set(t,r,n){const{originalTarget:a,membrane:{valueMutated:s}}=this;return a[r]!==n?(a[r]=n,s(a,r)):"length"===r&&e(a)&&s(a,r),!0}deleteProperty(e,t){const{originalTarget:r,membrane:{valueMutated:n}}=this;return delete r[t],n(r,t),!0}setPrototypeOf(e,t){}preventExtensions(e){if(s(e)){const{originalTarget:t}=this;if(l(t),s(t))return!1;this.lockShadowTarget(e)}return!0}defineProperty(e,t,r){const{originalTarget:a,membrane:{valueMutated:s,tagPropertyKey:o}}=this;return t===o&&!c.call(a,t)||(n(a,t,this.unwrapDescriptor(r)),!1===r.configurable&&this.copyDescriptorIntoShadowTarget(e,t),s(a,t),!0)}}const D=new WeakMap,S=new WeakMap;class M extends d{wrapValue(e){return this.membrane.getReadOnlyProxy(e)}wrapGetter(e){const t=D.get(e);if(!y(t))return t;const r=this,n=function(){return r.wrapValue(e.call(b(this)))};return D.set(e,n),n}wrapSetter(e){const t=S.get(e);if(!y(t))return t;const r=function(e){};return S.set(e,r),r}set(e,t,r){return!1}deleteProperty(e,t){return!1}setPrototypeOf(e,t){}preventExtensions(e){return!1}defineProperty(e,t,r){return!1}}const k=Object.prototype;function I(r){if(null===r)return!1;if("object"!=typeof r)return!1;if(e(r))return!0;const n=t(r);return n===k||null===n||null===t(n)}const V=(e,t)=>{},K=(e,t)=>{},W=e=>e;function G(t){return e(t)?[]:{}}return class{constructor(e){if(this.valueDistortion=W,this.valueMutated=K,this.valueObserved=V,this.valueIsObservable=I,this.objectGraph=new WeakMap,!y(e)){const{valueDistortion:t,valueMutated:r,valueObserved:n,valueIsObservable:a,tagPropertyKey:s}=e;this.valueDistortion=f(t)?t:W,this.valueMutated=f(r)?r:K,this.valueObserved=f(n)?n:V,this.valueIsObservable=f(a)?a:I,this.tagPropertyKey=s}}getProxy(e){const t=b(e),r=this.valueDistortion(t);if(this.valueIsObservable(r)){const n=this.getReactiveState(t,r);return n.readOnly===e?e:n.reactive}return r}getReadOnlyProxy(e){e=b(e);const t=this.valueDistortion(e);return this.valueIsObservable(t)?this.getReactiveState(e,t).readOnly:t}unwrapProxy(e){return b(e)}getReactiveState(e,t){const{objectGraph:r}=this;let a=r.get(t);if(a)return a;const s=this;return a={get reactive(){const r=new x(s,t),a=new Proxy(G(t),r);return w(a,e),n(this,"reactive",{value:a}),a},get readOnly(){const r=new M(s,t),a=new Proxy(G(t),r);return w(a,e),n(this,"readOnly",{value:a}),a}},r.set(t,a),a}}}));
{
"name": "observable-membrane",
"version": "1.0.0",
"version": "1.0.1",
"description": "A Javascript Membrane implementation using Proxies to observe mutation on an object graph",

@@ -5,0 +5,0 @@ "main": "dist/commonjs/observable-membrane.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc