@qtpy/state-management-observable
Version:
1. [Основная идея и архитектура](#основная-идея-и-архитектура) 1.1. [Прозрачная реактивность](#прозрачная-реактивность) 1.2. [Поддержка типизированных строковых ключей](#поддержка-типизированных-строковых-ключей) 1.3. [Подписки с «гранул
2 lines (1 loc) • 4.5 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function j(e){const t=e.match(/\((.*?)\)/);return t?t[1].split(/\s*,\s*/).filter(Boolean):[]}function A(e,t){const n=t.toString().trim(),o=j(n),s=o.map(l=>l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),r=n.match(new RegExp(`^\\s*(?:\\(\\s*${s[0]}\\s*(?:,\\s*${s[1]}\\s*)?\\s*\\)|${s[0]})\\s*=>\\s*([\\s\\S]+)$`));if(!r)throw new Error("Invalid function format");let c=r[1].trim();c.startsWith("(")&&c.endsWith(")")&&(c=c.slice(1,-1).trim());let i=c.replace(/\s+/g,"");const a=/\[([^\[\]]+),([^\[\]]+)\]/;for(;a.test(i);)i=i.replace(/\[([^\[\]]+),([^\[\]]+)\]/g,"[$1][$2]");if(o.length<2){let l=i.replace(/\[['"]([^[\]]+)['"]\]/g,".$1").replace(/\[([^[\]]+)\]/g,".$1");return l.startsWith(".")&&(l=l.slice(1)),l}const u=o[1],d=u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),I=new RegExp(`${d}\\(\\s*([^\\)]+)\\s*\\)`),m=new RegExp(`${d}\\(\\s*([^\\)]+)\\s*\\)`,"g");if(!I.test(i)){let l=i.replace(/\[['"]([^[\]]+)['"]\]/g,".$1").replace(/\[([^[\]]+)\]/g,".$1");return l.startsWith(".")&&(l=l.slice(1)),l}const $=[];let S;for(;(S=m.exec(i))!==null;)$.push(S[1]);const w=[];let v=0;function E(l){const f=$[v];return w.push([`${u}(${f})`,l]),v++,l}try{t(e,E)}catch{}const M={};for(const[l,f]of w){const h=l.slice(u.length+1,-1);M[h]=f}let g=i.replace(m,(l,f)=>{const h=M[f];return h===void 0?"undefined":String(h)});g=g.replace(/\[['"]([\w$]+)['"]\]/g,".$1").replace(/\[([\w$]+)\]/g,".$1");const y=g.replace(/\.\./g,".");return y.startsWith(".")?y.slice(1):y}function N(e){if(!(typeof e=="string")&&!(typeof e=="function")){const o=e===null?"null":typeof e,s=typeof e=="object"?JSON.stringify(Object.keys(e)):String(e);throw new Error(`[store] Ожидался путь (строка или функция-доступ), получено: ${o} (${s}).`)}}function O(e,t){let n;typeof t=="string"?n=t:n=A(e,t);let o="$";if(typeof t!="string"){const c=t.toString().trim();o=j(c)[0]||"$"}const s=`${o}.`,r=n.indexOf(s);return r>=0?n.slice(r+s.length):n}function D(e,t){return Array.isArray(e)?e.map(n=>D(n,t)).filter(n=>n!=="").join("."):typeof e=="function"?O(t,e):e==null?"":String(e)}function U(e,t){if(e===t)return!0;if(e==null||t==null)return e===t;if(typeof e!=typeof t)return!1;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(typeof e!="object")return!1;const n=Object.keys(e),o=Object.keys(t);if(n.length!==o.length)return!1;for(let s=0;s<n.length;s++){const r=n[s];if(!Object.prototype.hasOwnProperty.call(t,r)||e[r]!==t[r])return!1}return!0}function W(e){return e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function C(e,t=[]){switch(e){case"push":case"pop":case"splice":case"shift":case"unshift":case"sort":case"reverse":return!t.length||t.includes(e)}return!1}function p(e,t){return e===null||!(Array.isArray(e)||typeof e=="object"||typeof e=="function")?!1:t==null?void 0:t()}function P(e,t,n){p(t,()=>e.set(t,n))}function k(e,t){return p(t,()=>e.get(t))}function R(e,t){p(t,()=>e.delete(t))}function _(e,t){return p(t,()=>{const n=k(e,t)??{};P(e,t,{revision:crypto.randomUUID(),_prevRevision:n.revision??null})}),t}function b(e){try{const t=x(e);let n=5381;for(let o=0;o<t.length;o++){const s=t.charCodeAt(o);n=((n<<5)+n^s)>>>0}return(n>>>0).toString(16)}catch{return!1}}function x(e){const t=[{value:e}],n=[],o=new WeakSet;for(;t.length>0;){const s=t.pop();if(typeof s=="string"){n.push(s);continue}let{value:r,parentIsArray:c}=s;if(r==null||typeof r!="object"){r===void 0?n.push(c?"null":""):typeof r=="number"?n.push(isFinite(r)?r.toString():"null"):n.push(JSON.stringify(r));continue}if(o.has(r)){n.push('"__cycle__"');continue}if(o.add(r),Array.isArray(r)){if(r.length===0){n.push("[]");continue}t.push("]");for(let i=r.length-1;i>=0;i--)t.push({value:r[i],parentIsArray:!0}),i>0&&t.push(",");t.push("[")}else{const i=Object.keys(r);if(i.length===0){n.push("{}");continue}t.push("}");for(let a=i.length-1;a>=0;a--){const u=i[a];t.push({value:r[u]}),t.push(`"${u}":`),a>0&&t.push(",")}t.push("{")}}return n.join("")}function T(){return`${Math.floor(performance.now()).toString(36)}-${Math.random().toString(36).slice(2,6)}`}exports.calculateSnapshotHash=b;exports.deleteMetaData=R;exports.detRandomId=T;exports.getMetaData=k;exports.getStringOfObject=A;exports.getStringPath=O;exports.isArrayMethod=C;exports.normalizeCacheKey=D;exports.setMetaData=P;exports.shallowEqual=U;exports.splitPath=W;exports.stringify=x;exports.validatePath=N;exports.withMetaSupport=p;exports.wrapWithMetaUsingUUID=_;