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

lstate

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lstate - npm Package Compare versions

Comparing version 1.2.6 to 1.2.7

9

dist/index.d.ts

@@ -6,3 +6,3 @@ // Generated by dts-bundle-generator v7.2.0

} : T;
export type LStateSetter<T> = (fn: (oldvalue: FullReadOnly<T>) => undefined | T) => void;
export type LStateSetter<T> = (value: FullReadOnly<T> | ((oldvalue: FullReadOnly<T>) => undefined | FullReadOnly<T>)) => void;
export type Unscribe = () => void;

@@ -51,3 +51,4 @@ export interface LState<T extends {}> {

}
export type DependencyCompute<T extends {}, DEPS extends Array<LAnyState<any>>> = (setter: LStateSetter<T>, ...deps: ExtractLAnyStates<DEPS>) => void;
export type DependencyComputeSetter<T extends {}, DEPS extends Array<LAnyState<any>>> = (value: FullReadOnly<T> | ((oldvalue: FullReadOnly<T>, ...deps: ExtractLAnyStates<DEPS>) => undefined | FullReadOnly<T>)) => void;
export type DependencyCompute<T extends {}, DEPS extends Array<LAnyState<any>>> = (setter: DependencyComputeSetter<T, DEPS>) => void | Promise<void>;
export interface LStateDef<T extends {}, REDUCERS extends LStateReducers> {

@@ -63,3 +64,3 @@ initial: T;

compute: DependencyCompute<T, DEPS>;
debounce?: number;
throttle?: number;
compare?: (a: FullReadOnly<T>, b: T) => number;

@@ -72,3 +73,3 @@ }

reducers: (dml: {
setter: LStateSetter<FullReadOnly<T[]>>;
setter: LStateSetter<T[]>;
upsert(item: T): void;

@@ -75,0 +76,0 @@ update(id: LCollectionFilter<T, ID>, fn: (old: FullReadOnly<T>) => undefined | Partial<T>): void;

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

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};
import{useCallback as A,useEffect as $,useState as P}from"react";function x(t,r,l){if(t===r)return 0;let d=t===null?"null":typeof t,a=r===null?"null":typeof r,o;if(t instanceof Date)return r instanceof Date?t.getTime()-r.getTime():a==="string"?t.getTime()-new Date(r).getTime():-1;if(r instanceof Date)return d==="string"?new Date(t).getTime()-r.getTime():1;if(d!==a)return d==="undefined"?-1:a==="undefined"?1:d<a?-1:1;if(Array.isArray(t))return o=t.length-r.length,o||t.some((i,m)=>(o=x(i,r[m],l),!!o)),o;if(d==="object"){let i=Object.getOwnPropertyNames(t);return i.sort(),o=0,i.some(m=>(o=x(t[m],r[m],l),!!o)),o===0&&l&&(o=i.length-Object.getOwnPropertyNames(r).length),o}else return d==="function"?0:t<r?-1:1}function V(t){let r=t.compare||((e,n)=>e===n?0:1),l=t.id,d=l&&t.items,a=t.initial||d||[t.default,!0],o=t.disconnect,i=t.dependencies,m=t.throttle||100,D=t.compute,L=new Set,f,u={$:{get:R,subscribe(e){return i&&!f&&h(),L.add(e),()=>L&&L.delete(e)&&v()},destroy(){u&&(v(),Object.keys(u.$).forEach(e=>{delete u.$[e]}),Object.keys(u).forEach(e=>{delete u[e]}),a=void 0,L.clear(),L=void 0,u=void 0,r=void 0,i=void 0,D=void 0,o&&(setTimeout(o,1),o=void 0))}}};if(!D){u.$.setter=c;let e=t.reducers;e&&(u={...u,...e(d?{setter:c,update:b,upsert:F,remove:g}:c)})}return d&&(u.$.load=e=>{c(()=>e)},u.$.getItem=e=>R().find(n=>n[l]===e),u.$.subscribeItem=(e,n)=>u.$.subscribe(s=>{let y=s.find(T=>T[l]===e);y&&n(y)}),u.$.upsert=F,u.$.update=b,u.$.remove=g),u;function R(){return a}function c(e){Promise.resolve(typeof e=="function"?e(a):e).then(n=>{n&&r(a,n)!==0&&(a=n,C())})}function C(){L.forEach(e=>e(a))}function h(){let e=!0;f=i.map(s=>s.$.subscribe(n)),n();function n(){f&&!a[1]&&(a=[a[0],!0],setTimeout(C,1)),e&&setTimeout(()=>{e=!0,k()},m),e=!1}}function v(){f&&(f.forEach(e=>setTimeout(e,1)),f=void 0)}function k(){f&&a[1]&&D(n=>{Promise.resolve(typeof n=="function"?n(a[0],...i.map(s=>s.$.get())):n).then(s=>{s&&c([s,!1])})})}function F(e){c(n=>{let s=!1,y=!0,T=n.map(p=>p[l]===e[l]?(y=!1,s=s||x(p,e)!==0,e):p);if(y&&(T.push(e),s=!0),s)return T})}function E(e){return typeof e=="function"?e:n=>n[l]===e}function b(e,n){c(s=>{let y=!1,T=E(e),p=s.map(S=>{if(T(S)){let O=n(S);if(O){let I={...S,...O};return y=y||x(S,I)!==0,I}}return S});if(y)return p})}function g(e){c(n=>{let s=!1,y=E(e),T=n.filter(p=>y(p)?(s=!0,!1):!0);if(s)return T})}}function N(t,r){let l=arguments.length===2,[d,a]=P(()=>l?t.$.getItem(r):t.$.get()),o=A(i=>a(i),[t,a]);return $(()=>l?t.$.subscribeItem(r,o):t.$.subscribe(o),[t,a]),d}export{V as createLState,x 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.6",
"version": "1.2.7",
"private": false,

@@ -6,0 +6,0 @@ "main": "dist/index.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