Comparing version 1.5.0 to 1.5.1
@@ -1,1 +0,1 @@ | ||
import{useState as t,useRef as e,useEffect as s,memo as r}from"react";function i(t,e,s,r){if("a"===s&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?r:"a"===s?r.call(t):r?r.value:e.get(t)}var n,o,a,c,f,h,u,l,d;class m{constructor(t,e){n.add(this),o.set(this,{}),a.set(this,new Map),c.set(this,{}),this.statics={},i(this,n,"m",f).call(this,"*"),i(this,n,"m",u).call(this,t),this.setStatics(e)}setStatics(t){"object"==typeof t&&Object.entries(t).forEach((([t,e])=>{this.statics[t]="function"==typeof e?e.bind(this):e}))}subscribe(t,e){if("function"!=typeof e)return s=["listener must be a function"],console.warn(s.join("\n")),()=>!1;var s;const r=Array.isArray(t)?Array.from(new Set(t)).filter((t=>"*"!==t)):[t];i(this,n,"m",h).call(this,e);const c=r.map(y);return c.forEach((t=>{i(this,n,"m",f).call(this,t),i(this,a,"f").get(e).add(t),i(this,o,"f")[t].listeners.add(e)})),()=>{i(this,a,"f").delete(e),c.forEach((t=>i(this,o,"f")[t].listeners.delete(e)))}}set(t,{silent:e}={silent:!1}){if("function"==typeof t&&(t=t(w(i(this,c,"f")))),"object"!=typeof t)return;const s=i(this,n,"m",u).call(this,t);!e&&s&&i(this,n,"m",l).call(this,s)}get(t){const e=t=>(t=t.toString(),this.statics[t]||i(this,c,"f")[t.toLowerCase()]);return"string"==typeof t?e(t):Array.isArray(t)?Object.fromEntries(t.map((t=>[t,e(t)]))):void 0}get state(){return w(i(this,c,"f"))}isValid(t){return void 0!==i(this,o,"f")[t.toLowerCase()]}}o=new WeakMap,a=new WeakMap,c=new WeakMap,n=new WeakSet,f=function(t){i(this,o,"f")[t]||(i(this,o,"f")[t]={listeners:new Set})},h=function(t){i(this,a,"f").has(t)||i(this,a,"f").set(t,new Set)},u=function(t){if("object"!=typeof t)return;const e=Object.keys(t).filter((t=>!this.statics[t])),s=e.map(y);return s.forEach(((s,r)=>{i(this,n,"m",f).call(this,s),i(this,c,"f")[s]=t[e[r]]})),s},l=function(t){const e=new Set;i(this,o,"f")["*"].listeners.forEach((t=>e.add(t))),t.forEach((t=>{i(this,o,"f")[t.toLowerCase()].listeners.forEach((t=>e.add(t)))})),e.forEach((t=>t(i(this,n,"m",d).call(this,t))))},d=function(t){if(i(this,o,"f")["*"].listeners.has(t))return this.state;const e=Array.from(i(this,a,"f").get(t));return 1===e.length?i(this,c,"f")[e[0]]:Object.fromEntries(e.map((t=>[t,i(this,c,"f")[t]])))};const p=new m;function w(t){return new Proxy(t,{get:(t,e)=>t[y(e)],set:(t,e,s)=>(t[y(e)]=s,!0)})}function y(t){return t.toString().toLowerCase()}function b(r=undefined){const i=r instanceof m,n=i?void 0:r,o=i?r:p,a=t({}),c=e({keys:new Set});return s((()=>{const{keys:t}=c.current;if(0===t.size)return;const e=o.subscribe(Array.from(t),(function(t){a[1]({value:t})}));return()=>e()}),[]),new Proxy({},{get(t,e){const{keys:s}=c.current,r=e.toLowerCase();if("set"===r)return(...t)=>{o.set(...t)};if(r.startsWith("set")){const t=r.replace("set","");return void 0!==n&&f(t),e=>{o.set({[t]:h(e,t)})}}return t[e]?t[e]:o.statics[e]?o.statics[e]:(s.add(r),f(r))},defineProperty:(t,e,s)=>(t[e]=s.value,!0)});function f(t){let e=o.get(t);return o.isValid(t)||(e=h(n,t),o.set({[t]:e})),e}function h(t,e){return"function"==typeof t?t(o.get(e)):t}}function g(t,e){function s(s){const r=b(e);return Object.defineProperties(r,Object.fromEntries(Object.entries(s).map((([t,e])=>[t,{value:e}])))),t(r)}return r(s)}export{m as Observer,p as observer,b as useObserver,g as withState}; | ||
import{useState as t,useRef as e,useEffect as s,memo as r}from"react";function i(t,e,s,r){if("a"===s&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?r:"a"===s?r.call(t):r?r.value:e.get(t)}var n,o,a,c,f,h,u,l,d;class m{constructor(t,e){n.add(this),o.set(this,{}),a.set(this,new Map),c.set(this,{}),this.statics={},i(this,n,"m",f).call(this,"*"),i(this,n,"m",u).call(this,t),this.setStatics(e)}setStatics(t){"object"==typeof t&&Object.entries(t).forEach((([t,e])=>{this.statics[t]="function"==typeof e?e.bind(this):e}))}subscribe(t,e){if("function"!=typeof e)return s=["listener must be a function"],console.warn(s.join("\n")),()=>!1;var s;const r=Array.isArray(t)?Array.from(new Set(t)).filter((t=>"*"!==t)):[t];i(this,n,"m",h).call(this,e);const c=r.map(y);return c.forEach((t=>{i(this,n,"m",f).call(this,t),i(this,a,"f").get(e).add(t),i(this,o,"f")[t].listeners.add(e)})),()=>{i(this,a,"f").delete(e),c.forEach((t=>i(this,o,"f")[t].listeners.delete(e)))}}set(t,{silent:e}={silent:!1}){if("function"==typeof t&&(t=t(w(i(this,c,"f")))),"object"!=typeof t)return;const s=i(this,n,"m",u).call(this,t);!e&&s&&i(this,n,"m",l).call(this,s)}get(t){const e=t=>(t=t.toString(),this.statics[t]||i(this,c,"f")[t.toLowerCase()]);return"string"==typeof t?e(t):Array.isArray(t)?Object.fromEntries(t.map((t=>[t,e(t)]))):void 0}get state(){return w(i(this,c,"f"))}isValid(t){return void 0!==i(this,o,"f")[t.toLowerCase()]}}o=new WeakMap,a=new WeakMap,c=new WeakMap,n=new WeakSet,f=function(t){i(this,o,"f")[t]||(i(this,o,"f")[t]={listeners:new Set})},h=function(t){i(this,a,"f").has(t)||i(this,a,"f").set(t,new Set)},u=function(t){if("object"!=typeof t)return;const e=Object.keys(t).filter((t=>!this.statics[t])),s=e.map(y);return s.forEach(((s,r)=>{i(this,n,"m",f).call(this,s),i(this,c,"f")[s]=t[e[r]]})),s},l=function(t){const e=new Set;i(this,o,"f")["*"].listeners.forEach((t=>e.add(t))),t.forEach((t=>{i(this,o,"f")[t.toLowerCase()].listeners.forEach((t=>e.add(t)))})),e.forEach((t=>t(i(this,n,"m",d).call(this,t))))},d=function(t){if(i(this,o,"f")["*"].listeners.has(t))return this.state;const e=Array.from(i(this,a,"f").get(t));return 1===e.length?i(this,c,"f")[e[0]]:Object.fromEntries(e.map((t=>[t,i(this,c,"f")[t]])))};const p=new m;function w(t){return new Proxy(t,{get:(t,e)=>t[y(e)],set:(t,e,s)=>(t[y(e)]=s,!0)})}function y(t){return t.toString().toLowerCase()}function b(r=undefined){const i=r instanceof m,n=i?void 0:r,o=i?r:p,a=t({}),c=e({keys:new Set});return s((()=>{const{keys:t}=c.current;if(0===t.size)return;const e=o.subscribe(Array.from(t),(function(t){a[1]({value:t})}));return()=>e()}),[]),new Proxy({},{get(t,e){if(o.statics[e])return o.statics[e];const{keys:s}=c.current,r=e.toLowerCase();if("set"===r)return(...t)=>{o.set(...t)};if(r.startsWith("set")){const t=r.replace("set","");return void 0!==n&&f(t),e=>{o.set({[t]:h(e,t)})}}return t[e]?t[e]:(s.add(r),f(r))},defineProperty:(t,e,s)=>(t[e]=s.value,!0)});function f(t){let e=o.get(t);return o.isValid(t)||(e=h(n,t),o.set({[t]:e})),e}function h(t,e){return"function"==typeof t?t(o.get(e)):t}}function g(t,e){function s(s){const r=b(e);return Object.defineProperties(r,Object.fromEntries(Object.entries(s).map((([t,e])=>[t,{value:e}])))),t(r)}return r(s)}export{m as Observer,p as observer,b as useObserver,g as withState}; |
{ | ||
"name": "rosma", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -23,3 +23,3 @@ import { Observer } from '../observer'; | ||
export declare type BindObserver<T, O> = { | ||
[K in keyof T]: T[K] extends (...args: any[]) => any ? (this: Observer<O>, ...args: Parameters<T[K]>) => ReturnType<T[K]> : T[K]; | ||
[K in keyof T]: T[K] extends (...args: any[]) => any ? (this: Observer<O, T>, ...args: Parameters<T[K]>) => ReturnType<T[K]> : T[K]; | ||
}; | ||
@@ -26,0 +26,0 @@ export interface GlobalState extends Record<string, any> { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15671