Comparing version 1.2.5 to 1.2.6
@@ -16,6 +16,10 @@ // Generated by dts-bundle-generator v7.2.0 | ||
} | ||
export type LComputedValue<T extends {}> = [ | ||
value: FullReadOnly<T>, | ||
pending: boolean | ||
]; | ||
export interface LComputed<T extends {}> { | ||
$: { | ||
get(): FullReadOnly<T>; | ||
subscribe(subscription: (value: FullReadOnly<T>) => void): () => void; | ||
get(): LComputedValue<T>; | ||
subscribe(subscription: (value: LComputedValue<T>) => void): () => void; | ||
destroy(): void; | ||
@@ -76,3 +80,3 @@ }; | ||
export declare function useLState<T extends {}>(state: LState<T>): FullReadOnly<T>; | ||
export declare function useLState<T extends {}>(state: LComputed<T>): FullReadOnly<T>; | ||
export declare function useLState<T extends {}>(state: LComputed<T>): LComputedValue<T>; | ||
export declare function useLState<T extends {}, ID extends keyof T>(state: LCollection<T, ID>): FullReadOnly<T[]>; | ||
@@ -79,0 +83,0 @@ export declare function useLState<T extends {}, ID extends keyof T>(state: LCollection<T, ID>, id: T[ID]): FullReadOnly<T>; |
@@ -1,1 +0,1 @@ | ||
import{useCallback as h,useEffect as A,useState as w}from"react";function x(t,a,l){if(t===a)return 0;let s=t===null?"null":typeof t,u=a===null?"null":typeof a,r;if(t instanceof Date)return a instanceof Date?t.getTime()-a.getTime():u==="string"?t.getTime()-new Date(a).getTime():-1;if(a instanceof Date)return s==="string"?new Date(t).getTime()-a.getTime():1;if(s!==u)return s==="undefined"?-1:u==="undefined"?1:s<u?-1:1;if(Array.isArray(t))return r=t.length-a.length,r||t.some((d,m)=>(r=x(d,a[m],l),!!r)),r;if(s==="object"){let d=Object.getOwnPropertyNames(t);return d.sort(),r=0,d.some(m=>(r=x(t[m],a[m],l),!!r)),r===0&&l&&(r=d.length-Object.getOwnPropertyNames(a).length),r}else return s==="function"?0:t<a?-1:1}function N(t){let a=t.compare||((e,n)=>e===n?0:1),l=t.id,s=l&&t.items,u=t.initial||s||t.default,r=t.disconnect,d=t.dependencies,m=t.debounce||100,D=t.compute,f=new Set,L,o={$:{get:R,subscribe(e){return d&&!L&&$(),f.add(e),()=>f&&f.delete(e)&&C()},destroy(){o&&(C(),Object.keys(o.$).forEach(e=>{delete o.$[e]}),Object.keys(o).forEach(e=>{delete o[e]}),u=void 0,f.clear(),f=void 0,o=void 0,a=void 0,d=void 0,D=void 0,r&&(setTimeout(r,1),r=void 0))}}};if(!D){o.$.setter=y;let e=t.reducers;e&&(o={...o,...e(s?{setter:y,update:F,upsert:b,remove:E}:y)})}return s&&(o.$.load=e=>{y(()=>e)},o.$.getItem=e=>R().find(n=>n[l]===e),o.$.subscribeItem=(e,n)=>o.$.subscribe(i=>{let c=i.find(T=>T[l]===e);c&&n(c)}),o.$.upsert=b,o.$.update=F,o.$.remove=E),o;function R(){return d&&f.size===0&&v(),u}function y(e){let n=e(u);n&&a(u,n)!==0&&(u=n,k())}function k(){f.forEach(e=>{setTimeout(()=>e(u),1)})}function $(){let e;L=d.map(i=>i.$.subscribe(n)),n();function n(){e&&clearTimeout(e),e=setTimeout(()=>{L&&v()},m)}}function C(){L&&(L.forEach(e=>setTimeout(e,1)),L=void 0)}function v(){D(y,...d.map(e=>e.$.get()))}function b(e){y(n=>{let i=!1,c=!0,T=n.map(p=>p[l]===e[l]?(c=!1,i=i||x(p,e)!==0,e):p);if(c&&(T.push(e),i=!0),i)return T})}function g(e){return typeof e=="function"?e:n=>n[l]===e}function F(e,n){y(i=>{let c=!1,T=g(e),p=i.map(S=>{if(T(S)){let O=n(S);if(O){let I={...S,...O};return c=c||x(S,I)!==0,I}}return S});if(c)return p})}function E(e){y(n=>{let i=!1,c=g(e),T=n.filter(p=>c(p)?(i=!0,!1):!0);if(i)return T})}}function V(t,a){let[l,s]=w(()=>arguments.length===2?t.$.getItem(a):t.$.get()),u=h(r=>s(r),[t,s]);return A(()=>arguments.length===2?t.$.subscribeItem(a,u):t.$.subscribe(u),[t,s]),l}export{N as createLState,x as deepCompare,V as useLState}; | ||
import{useCallback as h,useEffect as A,useState as w}from"react";function S(t,a,i){if(t===a)return 0;let u=t===null?"null":typeof t,r=a===null?"null":typeof a,o;if(t instanceof Date)return a instanceof Date?t.getTime()-a.getTime():r==="string"?t.getTime()-new Date(a).getTime():-1;if(a instanceof Date)return u==="string"?new Date(t).getTime()-a.getTime():1;if(u!==r)return u==="undefined"?-1:r==="undefined"?1:u<r?-1:1;if(Array.isArray(t))return o=t.length-a.length,o||t.some((d,L)=>(o=S(d,a[L],i),!!o)),o;if(u==="object"){let d=Object.getOwnPropertyNames(t);return d.sort(),o=0,d.some(L=>(o=S(t[L],a[L],i),!!o)),o===0&&i&&(o=d.length-Object.getOwnPropertyNames(a).length),o}else return u==="function"?0:t<a?-1:1}function V(t){let a=t.compare||((e,n)=>e===n?0:1),i=t.id,u=i&&t.items,r=t.initial||u||[t.default,!0],o=t.disconnect,d=t.dependencies,L=t.debounce||100,D=t.compute,f=new Set,p,s={$:{get:C,subscribe(e){return d&&!p&&$(),f.add(e),()=>f&&f.delete(e)&&v()},destroy(){s&&(v(),Object.keys(s.$).forEach(e=>{delete s.$[e]}),Object.keys(s).forEach(e=>{delete s[e]}),r=void 0,f.clear(),f=void 0,s=void 0,a=void 0,d=void 0,D=void 0,o&&(setTimeout(o,1),o=void 0))}}};if(!D){s.$.setter=y;let e=t.reducers;e&&(s={...s,...e(u?{setter:y,update:F,upsert:g,remove:O}:y)})}return u&&(s.$.load=e=>{y(()=>e)},s.$.getItem=e=>C().find(n=>n[i]===e),s.$.subscribeItem=(e,n)=>s.$.subscribe(l=>{let c=l.find(T=>T[i]===e);c&&n(c)}),s.$.upsert=g,s.$.update=F,s.$.remove=O),s;function C(){return d&&f.size===0&&b(),r}function y(e){let n=e(r);n&&a(r,n)!==0&&(r=n,R())}function R(){f.forEach(e=>{setTimeout(()=>e(r),1)})}function $(){let e;p=d.map(l=>l.$.subscribe(n)),n();function n(){p&&!r[1]&&(r[1]=!0,R()),e&&clearTimeout(e),e=setTimeout(()=>{p&&b()},L)}}function v(){p&&(p.forEach(e=>setTimeout(e,1)),p=void 0)}function b(){D(e=>{let n=e(r[0]);n&&y(()=>[n,!1])},...d.map(e=>e.$.get()))}function g(e){y(n=>{let l=!1,c=!0,T=n.map(m=>m[i]===e[i]?(c=!1,l=l||S(m,e)!==0,e):m);if(c&&(T.push(e),l=!0),l)return T})}function E(e){return typeof e=="function"?e:n=>n[i]===e}function F(e,n){y(l=>{let c=!1,T=E(e),m=l.map(x=>{if(T(x)){let I=n(x);if(I){let k={...x,...I};return c=c||S(x,k)!==0,k}}return x});if(c)return m})}function O(e){y(n=>{let l=!1,c=E(e),T=n.filter(m=>c(m)?(l=!0,!1):!0);if(l)return T})}}function N(t,a){let[i,u]=w(()=>arguments.length===2?t.$.getItem(a):t.$.get()),r=h(o=>u(o),[t,u]);return A(()=>arguments.length===2?t.$.subscribeItem(a,r):t.$.subscribe(r),[t,u]),i}export{V as createLState,S as deepCompare,N as useLState}; |
{ | ||
"name": "lstate", | ||
"description": "A simple, super-efficient and small (just 2.4kb) global state for React/Typescript applications", | ||
"version": "1.2.5", | ||
"version": "1.2.6", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "dist/index.js", |
@@ -31,7 +31,5 @@ # lstate | ||
export function App() { | ||
export function Sample() { | ||
const { count } = useLState(sample) | ||
return <div className="App"> | ||
<h1>Testing lstate</h1> | ||
<h2>A simple, super-efficient and small (just 2.4kb) global state for React/Typescript applications</h2> | ||
<p>count: {count}</p> | ||
@@ -65,8 +63,19 @@ <button onClick={sample.inc}>+</button> | ||
const double = createLState({ | ||
default: {value: 0}, | ||
deps: [sample], | ||
computed: (setter, [sampleState]) => ({ | ||
setter((old) => ({count: sampleState.count * 2})) | ||
}) | ||
default: {doubleOfCount: 0}, | ||
dependencies: [sample], | ||
debounce: 3000, | ||
compute: (setter, sampleValue) => { | ||
setter((old) => ({doubleOfCount: sampleValue.count * 2})) | ||
} | ||
}) | ||
export function Computed() { | ||
const { doubleOfCount } = useLState(double) | ||
const { count } = useLState(sample) | ||
return <div className="App"> | ||
<p>count: {count}</p> | ||
<p>doubleOfCount: {doubleOfCount}</p> | ||
<button onClick={sample.inc}>+</button> | ||
</div> | ||
} | ||
```` | ||
@@ -73,0 +82,0 @@ |
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
46649
92
128