valdres 0.1.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +1 -0
- package/dist/index.js +1 -0
- package/package.json +28 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Eigil Sagafos
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Se [valdres.dev](https://valdres.dev) for docs
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var J=(o,p)=>{if(!p)return{defaultValue:o};return{defaultValue:o,...p}};var S=(o)=>o&&o.then&&typeof o.then==="function";var _=(o,p)=>{if(typeof o==="string"&&!o.includes('"')&&!o.includes("\\"))return`"${o}"`;switch(typeof o){case"undefined":return"";case"boolean":return o?"true":"false";case"number":case"symbol":return String(o);case"string":return JSON.stringify(o);case"function":return`__FUNCTION(${o.toString()})__`}if(o===null)return"null";if(typeof o!=="object")return JSON.stringify(o)??"";if(S(o))return"__PROMISE__";if(Array.isArray(o))return`[${o.map((m,f)=>_(m,f.toString()))}]`;if(typeof o.toJSON==="function")return _(o.toJSON(p),p);if(o instanceof Map){const m={};for(let[f,n]of o)m[typeof f==="string"?f:stringify(f,opt)]=n;return _(m,p)}if(o instanceof Set)return _(Array.from(o).sort((m,f)=>_(m).localeCompare(_(f))),p);if(Symbol!==void 0&&o[Symbol.iterator]!=null&&typeof o[Symbol.iterator]==="function")return _(Array.from(o),p);return`{${Object.keys(o).filter((m)=>o[m]!==void 0).sort().map((m)=>`${_(m)}:${_(o[m],m)}`).join(",")}}`},N=(o)=>{if(typeof o==="string"||typeof o==="boolean"||typeof o==="number")return o;return _(o)};var F=(o,p,m)=>{if(p)return typeof p==="function"?()=>typeof o==="function"?p(o(m)):p(o):p;else return typeof o==="function"?()=>o(m):o},W=(o,p)=>{const m=new Map,f=(n,i)=>{const t=N(n);if(m.has(t)){if(i)throw new Error("defaultOverride is only allowed first time an atom is initiaizlied");return m.get(t)}const r=p&&p+"_"+t,y=J(F(o,i,n),{label:r});return y.family=f,y.familyKey=Object.freeze(n),m.set(t,y),y};return f._map=m,f};var j=(o,p)=>{const m=p.subscriptions.get(o);if(m?.size)for(let f of m)f.callback();if(o.family){const f=p.subscriptions.get(o.family);if(f?.size)for(let n of f)n.callback(o.familyKey)}};import c from"fast-deep-equal";import no from"fast-deep-equal";class w extends Error{promise;constructor(o){super();this.promise=o}}var Y=(o,p)=>{const m=p.stateConsumers.get(o);if(m)return m;const f=new Set;return p.stateConsumers.set(o,f),f},g=(o,p)=>{const m=p.stateDependencies.get(o)??new Set,f=new Set;let n;try{n=o.get((r)=>{const y=A(r,p);if(f.add(r),S(y))throw new w(y);return y})}catch(r){if(r instanceof w)n=r;else throw r}const i=f?.difference(m),t=m?.difference(f);for(let r of i)Y(r,p).add(o);for(let r of t)Y(r,p).delete(o);return p.stateDependencies.set(o,f),n};var z=(o,p)=>{const m=g(o,p);if(m instanceof w)return m.promise.then(()=>z(o,p)),p.values.set(o,m.promise),m.promise;else if(S(m))return m.then((f)=>{p.values.set(o,f),j(o,p),console.log("TODO: Should we check if other selectors are using this?")}),p.values.set(o,m),m;else return p.values.set(o,m),m};var Z=(o,p,m)=>{const f=p.subscriptions.get(o),n=o.family&&p.subscriptions.get(o.family);if(!f?.size&&!n?.size)return;const i=z(o,p);if(c(i,m))return;if(f?.size)for(let t of f)t.callback();if(n?.size)for(let t of n)t.callback(state.familyKey)};var P=(o,p,m,f)=>{for(let n of o)if(!m.has(n)){m.add(n),f.set(n,p.values.get(n)),p.values.delete(n);const i=p.stateConsumers.get(n);if(i?.size)P(i,p,m,f)}},M=(o,p)=>{const m=new Set,f=new Map;for(let n of o){const i=p.stateConsumers.get(n);if(i&&i.size)P(i,p,m,f);if(n.family){const t=p.stateConsumers.get(n.family);if(t?.size)P(t,p,m,f)}}for(let n of m)Z(n,p,f.get(n));for(let n of o)j(n,p)};import L from"fast-deep-equal";var U=(o,p,m)=>{const f=A(o,m);if(typeof p==="function"){if(p=p(f),S(p)||S(f))throw new Error("Todo, how should we handle this?")}if(L(f,p))return;if(m.values.set(o,p),f?.__isEmptyAtomPromise__)f.__resolveEmptyAtomPromise__(p);M([o],m)};var Q=(o,p)=>{if(o.defaultValue===void 0){let m;const f=new Promise((n)=>{m=n});return f.__isEmptyAtomPromise__=!0,f.__resolveEmptyAtomPromise__=m,f}else if(typeof o.defaultValue==="function"){const m=o.defaultValue();if(S(m))m.then((f)=>{p.values.set(o,f),M([o],p)});return m}else return o.defaultValue},B=(o,p)=>{const m=Q(o,p);if(p.values.set(o,m),o.onInit)o.onInit((f)=>{U(o,f,p)});return m};var G=(o)=>Object.hasOwn(o,"defaultValue");var K=(o)=>Object.hasOwn(o,"get");var I=(o)=>Object.hasOwn(o,"_map");var A=(o,p)=>{if(p.values.has(o))return p.values.get(o);if(G(o))return B(o,p);if(K(o))return z(o,p);if(I(o)){const m=[];for(let f of o._map.values())m.push([f.familyKey,A(f,p)]);return m}throw console.log("nsadf",I(o),o,o._map),new Error("Invalid object passed to get")};var $=(o,p,m,f)=>{const n=m.subscriptions.get(o);if(n){if(n.delete(p),n.size===0){if(o.onUnmount)o.onUnmount(f)}}};var R=(o,p)=>{const m=new Set;return p.subscriptions.set(o,m),m},C=(o,p,m)=>{const f=m.subscriptions.get(o)||R(o,m);if(K(o)&&!m.values.has(o))z(o,m);let n;if(I(o))n={callback:p,state:o};else n={callback:p};let i;if(f.size===0&&o.onMount)i=o.onMount((t)=>{U(o,t,m)});return f.add(n),()=>$(o,n,m,i)};import b from"fast-deep-equal";var O=(o,p)=>{const m=[];for(let[f,n]of o){const i=A(f,p);if(!b(i,n))m.push(f),p.values.set(f,n)}M(m,p)};var T=(o,p,m=new Set)=>{const f=p.stateConsumers.get(o);if(f?.size){for(let n of f)if(!m.has(n))m.add(n),T(n,p,m)}return m},q=(o,p)=>{let m=new Map,f=new Set;const n=(D)=>{const V=m.get(D);if(V)return V;else if(f.has(D)){const h=D.get(n);return m.set(D,h),h}else return A(D,p)},i=(D,V)=>{if(!G(D))throw new Error("Not an atom");if(typeof V==="function"){const h=n(D);V=V(h)}for(let h of T(D,p))f.add(h),m.delete(h);m.set(D,V)},t=(D)=>{const V=Q(D,p);return m.set(D,V),V},r=()=>{O(m,p),f.clear()},y=o(i,n,t,r);return r(),y};var E=(o,p)=>{const m=B(o,p);if(!S(m))M([o],p);return m};var s=()=>(Math.random()+1).toString(36).substring(7),H=(o)=>{const p={id:o??s(),values:new WeakMap,subscriptions:new WeakMap,stateConsumers:new WeakMap,stateDependencies:new WeakMap},m=(r)=>A(r,p),f=(r,y)=>{if(G(r))return U(r,y,p);else{if(K(r))if(r.set){t((D,V)=>r.set({get:V,set:D},y));return}else throw new Error("set on selector is not supported");throw new Error("Invalid state object passed to set")}},n=(r)=>E(r,p),i=(r,y)=>C(r,y,p),t=(r)=>q(r,p);return{get:m,set:f,sub:i,txn:t,reset:n,data:p}};if(!globalThis._valdresStore)globalThis._valdresStore=H("default");var x=()=>globalThis._valdresStore,k=()=>globalThis._valdresStore=H();var X=(o,p)=>({get:o,debugLabel:p});var v=(o,p)=>{const m=new Map,f=(n)=>{let i;try{i=N(n)}catch(y){throw console.log("errro",{key:n,debugLabel:p,e:y}),y}if(m.has(i))return m.get(i);const t=p?p+"_"+i:void 0,r=X((y)=>o(n)(y),t);return r.family=f,m.set(i,r),r};return f._map=m,f};export{v as selectorFamily,X as selector,k as resetDefaultStore,K as isSelector,S as isPromiseLike,I as isFamily,G as isAtom,x as getDefaultStore,H as createStore,W as atomFamily,J as atom};
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "valdres",
|
|
3
|
+
"version": "0.1.0-alpha.8",
|
|
4
|
+
"module": "dist/index.js",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "bun scripts/build.ts",
|
|
11
|
+
"test": "bun test"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"fast-deep-equal": ">=3"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@testing-library/react-hooks": "8.0.1",
|
|
18
|
+
"react": ">=18",
|
|
19
|
+
"react-dom": ">=18",
|
|
20
|
+
"recoil": "0.7.7",
|
|
21
|
+
"typescript": "5.5.4"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"registry": "https://registry.npmjs.org/"
|
|
26
|
+
},
|
|
27
|
+
"gitHead": "d4b29c9b00ea2da90297ec6f13f5f7eb18392e41"
|
|
28
|
+
}
|