New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

universal-stores

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

universal-stores - npm Package Compare versions

Comparing version 2.4.2 to 2.4.3

12

dist/effect.d.ts

@@ -7,3 +7,3 @@ import { ReadonlyStore, Unsubscribe } from './store';

*/
instantiatingEffectId: number | undefined;
instantiatingEffect: Effect | undefined;
/**

@@ -32,12 +32,8 @@ * The number of effect ever register during the process runtime. This number is

declare type Effect = {
id: number;
effectFn: () => void | (() => void);
cleanupFn?: () => void;
dependencies: number[];
};
/**
* Error thrown if a store subscriber tied to an effect couldn't find the effect function
* in the runtime.
*/
export declare class MissingEffectError extends Error {
}
/**
* Error thrown if one or more cleanup functions registered by the effects inside a reactive

@@ -104,3 +100,3 @@ * root raised an exception.

*/
export declare function radioActiveContent<T>(store$: Pick<ReadonlyStore<T>, 'subscribe' | 'content'>): T;
export declare function radioActiveContent<T>(storeId: number, store$: Pick<ReadonlyStore<T>, 'subscribe' | 'content'>): T;
export {};
export * from './store';
export * from './composition';
export { MissingEffectError, ReactiveRootDisposeError, batchEffects, makeReactiveRoot, BatchingEffectError, NestedEffectError, type ReactiveRoot, } from './effect';
export { ReactiveRootDisposeError, batchEffects, makeReactiveRoot, BatchingEffectError, NestedEffectError, type ReactiveRoot, } from './effect';

@@ -57,3 +57,3 @@ var __defProp = Object.defineProperty;

const effectRuntime = {
instantiatingEffectId: void 0,
instantiatingEffect: void 0,
effectCount: 0,

@@ -67,4 +67,2 @@ isBatching: 0,

};
class MissingEffectError extends Error {
}
class ReactiveRootDisposeError extends Error {

@@ -92,3 +90,3 @@ constructor(errors) {

function makeEffect(fn) {
if (effectRuntime.instantiatingEffectId !== void 0) {
if (effectRuntime.instantiatingEffect !== void 0) {
throw new NestedEffectError();

@@ -101,10 +99,12 @@ }

const effect = {
effectFn: fn
id: effectId,
effectFn: fn,
dependencies: []
};
effectRuntime.effectById.set(effectId, effect);
effectRuntime.rootByEffectId.set(effectId, subscriptionsHolderId);
effectRuntime.instantiatingEffectId = effectId;
effectRuntime.instantiatingEffect = effect;
effect.cleanupFn = effect.effectFn();
} finally {
effectRuntime.instantiatingEffectId = void 0;
effectRuntime.instantiatingEffect = void 0;
}

@@ -158,27 +158,26 @@ }

}
function radioActiveContent(store$) {
if (effectRuntime.instantiatingEffectId !== void 0 && effectRuntime.instantiatingEffectId === effectRuntime.effectCount) {
let v;
const instanceId = effectRuntime.instantiatingEffectId;
let firstRun = true;
const rootId = effectRuntime.rootByEffectId.get(instanceId);
let unsubscribes = effectRuntime.rootUnsubscribes.get(rootId);
if (!unsubscribes) {
unsubscribes = [];
effectRuntime.rootUnsubscribes.set(rootId, unsubscribes);
}
const unsubscribe = store$.subscribe((current) => {
v = current;
if (firstRun) {
firstRun = false;
return;
function radioActiveContent(storeId, store$) {
if (effectRuntime.instantiatingEffect !== void 0) {
const effect = effectRuntime.instantiatingEffect;
const effectId = effect.id;
if (!effect.dependencies.includes(storeId)) {
effect.dependencies.push(storeId);
const rootId = effectRuntime.rootByEffectId.get(effectId);
let unsubscribes = effectRuntime.rootUnsubscribes.get(rootId);
if (!unsubscribes) {
unsubscribes = [];
effectRuntime.rootUnsubscribes.set(rootId, unsubscribes);
}
const effect = effectRuntime.effectById.get(instanceId);
if (!effect) {
throw new MissingEffectError(`effect with id "${instanceId}" not registered`);
} else {
let firstRun = true;
let v;
const unsubscribe = store$.subscribe((current) => {
v = current;
if (firstRun) {
firstRun = false;
return;
}
const effectRunner = () => {
var _a;
const prevRunning = effectRuntime.instantiatingEffectId;
effectRuntime.instantiatingEffectId = void 0;
const prevRunning = effectRuntime.instantiatingEffect;
effectRuntime.instantiatingEffect = void 0;
try {

@@ -188,14 +187,14 @@ (_a = effect.cleanupFn) == null ? void 0 : _a.call(effect);

} finally {
effectRuntime.instantiatingEffectId = prevRunning;
effectRuntime.instantiatingEffect = prevRunning;
}
};
if (effectRuntime.isBatching > 0) {
effectRuntime.pendingEffectBatch.set(instanceId, effectRunner);
effectRuntime.pendingEffectBatch.set(effectId, effectRunner);
} else {
effectRunner();
}
}
});
unsubscribes.push(unsubscribe);
return v;
});
unsubscribes.push(unsubscribe);
return v;
}
}

@@ -214,2 +213,5 @@ return store$.content();

*/
const storeRuntime = {
storeCount: 0
};
function makeStore(initialValue, startOrConfig) {

@@ -255,6 +257,8 @@ var _a;

};
storeRuntime.storeCount++;
const storeId = storeRuntime.storeCount;
return {
content,
set,
watch: () => radioActiveContent({ content, subscribe }),
watch: () => radioActiveContent(storeId, { content, subscribe }),
subscribe,

@@ -341,2 +345,2 @@ update,

}
export { BatchingEffectError, MissingEffectError, NestedEffectError, ReactiveRootDisposeError, batchEffects, makeDerivedStore, makeReactiveRoot, makeReadonlyStore, makeStore };
export { BatchingEffectError, NestedEffectError, ReactiveRootDisposeError, batchEffects, makeDerivedStore, makeReactiveRoot, makeReadonlyStore, makeStore, storeRuntime };

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

var x=Object.defineProperty;var w=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable;var k=(o,b,e)=>b in o?x(o,b,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[b]=e,M=(o,b)=>{for(var e in b||(b={}))D.call(b,e)&&k(o,e,b[e]);if(w)for(var e of w(b))S.call(b,e)&&k(o,e,b[e]);return o};(function(o,b){typeof exports=="object"&&typeof module!="undefined"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(o=typeof globalThis!="undefined"?globalThis:o||self,b(o.universalStores={}))})(this,function(o){"use strict";function b(){const t=[];function c(n){if(t.length!==0)for(const h of t.slice())h(n)}function i(n){const h=t.indexOf(n);h!==-1&&t.splice(h,1)}function s(n){return t.indexOf(n)===-1&&t.push(n),()=>i(n)}function f(n){const h=s(r=>{h(),n(r)});return h}return{emit:c,subscribe:s,subscribeOnce:f,nOfSubscriptions(){return t.length}}}const e={instantiatingEffectId:void 0,effectCount:0,isBatching:0,pendingEffectBatch:new Map,effectById:new Map,reactiveRootCount:0,rootByEffectId:new Map,rootUnsubscribes:new Map};class v extends Error{}class I extends Error{constructor(c){super("some of the registered cleanup functions threw an exception");this.errors=c}}class m extends Error{constructor(c){super("some of the batched effects threw an exception");this.errors=c}}class y extends Error{constructor(){super("makeEffect called inside an effect")}}function A(){e.reactiveRootCount++;const t=e.reactiveRootCount,c=new Set;function i(s){if(e.instantiatingEffectId!==void 0)throw new y;try{e.effectCount++;const f=e.effectCount;c.add(f);const n={effectFn:s};e.effectById.set(f,n),e.rootByEffectId.set(f,t),e.instantiatingEffectId=f,n.cleanupFn=n.effectFn()}finally{e.instantiatingEffectId=void 0}}return{makeEffect:i,dispose(){var f,n,h;(f=e.rootUnsubscribes.get(t))==null||f.forEach(r=>r()),e.rootUnsubscribes.delete(t);const s=[];for(const r of c){try{(h=(n=e.effectById.get(r))==null?void 0:n.cleanupFn)==null||h.call(n)}catch(u){s.push(u)}e.effectById.delete(r),e.rootByEffectId.delete(r)}if(s.length>0)throw new I(s)}}}function F(t){e.isBatching++;const c=[];try{t()}catch(i){c.push(i)}if(e.isBatching--,e.isBatching===0){const i=Array.from(e.pendingEffectBatch.values());e.pendingEffectBatch.clear();for(const s of i)try{s()}catch(f){c.push(f)}}if(c.length>0)throw new m(c)}function U(t){if(e.instantiatingEffectId!==void 0&&e.instantiatingEffectId===e.effectCount){let c;const i=e.instantiatingEffectId;let s=!0;const f=e.rootByEffectId.get(i);let n=e.rootUnsubscribes.get(f);n||(n=[],e.rootUnsubscribes.set(f,n));const h=t.subscribe(r=>{if(c=r,s){s=!1;return}const u=e.effectById.get(i);if(u){const a=()=>{var p;const g=e.instantiatingEffectId;e.instantiatingEffectId=void 0;try{(p=u.cleanupFn)==null||p.call(u),u.cleanupFn=u.effectFn()}finally{e.instantiatingEffectId=g}};e.isBatching>0?e.pendingEffectBatch.set(i,a):a()}else throw new v(`effect with id "${i}" not registered`)});return n.push(h),c}return t.content()}/**
var x=Object.defineProperty;var w=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable;var k=(f,b,e)=>b in f?x(f,b,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[b]=e,A=(f,b)=>{for(var e in b||(b={}))S.call(b,e)&&k(f,e,b[e]);if(w)for(var e of w(b))T.call(b,e)&&k(f,e,b[e]);return f};(function(f,b){typeof exports=="object"&&typeof module!="undefined"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(f=typeof globalThis!="undefined"?globalThis:f||self,b(f.universalStores={}))})(this,function(f){"use strict";function b(){const n=[];function c(t){if(n.length!==0)for(const a of n.slice())a(t)}function s(t){const a=n.indexOf(t);a!==-1&&n.splice(a,1)}function i(t){return n.indexOf(t)===-1&&n.push(t),()=>s(t)}function o(t){const a=i(r=>{a(),t(r)});return a}return{emit:c,subscribe:i,subscribeOnce:o,nOfSubscriptions(){return n.length}}}const e={instantiatingEffect:void 0,effectCount:0,isBatching:0,pendingEffectBatch:new Map,effectById:new Map,reactiveRootCount:0,rootByEffectId:new Map,rootUnsubscribes:new Map};class g extends Error{constructor(c){super("some of the registered cleanup functions threw an exception");this.errors=c}}class y extends Error{constructor(c){super("some of the batched effects threw an exception");this.errors=c}}class R extends Error{constructor(){super("makeEffect called inside an effect")}}function F(){e.reactiveRootCount++;const n=e.reactiveRootCount,c=new Set;function s(i){if(e.instantiatingEffect!==void 0)throw new R;try{e.effectCount++;const o=e.effectCount;c.add(o);const t={id:o,effectFn:i,dependencies:[]};e.effectById.set(o,t),e.rootByEffectId.set(o,n),e.instantiatingEffect=t,t.cleanupFn=t.effectFn()}finally{e.instantiatingEffect=void 0}}return{makeEffect:s,dispose(){var o,t,a;(o=e.rootUnsubscribes.get(n))==null||o.forEach(r=>r()),e.rootUnsubscribes.delete(n);const i=[];for(const r of c){try{(a=(t=e.effectById.get(r))==null?void 0:t.cleanupFn)==null||a.call(t)}catch(p){i.push(p)}e.effectById.delete(r),e.rootByEffectId.delete(r)}if(i.length>0)throw new g(i)}}}function M(n){e.isBatching++;const c=[];try{n()}catch(s){c.push(s)}if(e.isBatching--,e.isBatching===0){const s=Array.from(e.pendingEffectBatch.values());e.pendingEffectBatch.clear();for(const i of s)try{i()}catch(o){c.push(o)}}if(c.length>0)throw new y(c)}function U(n,c){if(e.instantiatingEffect!==void 0){const s=e.instantiatingEffect,i=s.id;if(!s.dependencies.includes(n)){s.dependencies.push(n);const o=e.rootByEffectId.get(i);let t=e.rootUnsubscribes.get(o);t||(t=[],e.rootUnsubscribes.set(o,t));let a=!0,r;const p=c.subscribe(d=>{if(r=d,a){a=!1;return}const v=()=>{var E;const h=e.instantiatingEffect;e.instantiatingEffect=void 0;try{(E=s.cleanupFn)==null||E.call(s),s.cleanupFn=s.effectFn()}finally{e.instantiatingEffect=h}};e.isBatching>0?e.pendingEffectBatch.set(i,v):v()});return t.push(p),r}}return c.content()}/**
* @license

@@ -10,3 +10,3 @@ * Copyright (c) 2016-22 [these people](https://github.com/sveltejs/svelte/graphs/contributors)

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/function B(t,c){var p;let i=t;const s=b();let f;const n=typeof c=="function"?c:c==null?void 0:c.start,h=(p=typeof c=="function"||c==null?void 0:c.comparator)!=null?p:(d,E)=>d===E,r=()=>{if(s.nOfSubscriptions()>0)return i;let d;return a(l=>d=l)(),d},u=d=>{i!==void 0&&h(i,d)||(i=d,s.emit(i))},a=d=>{s.nOfSubscriptions()===0&&(f=n==null?void 0:n(u));const E=s.subscribe(d);return d(i),()=>{E(),s.nOfSubscriptions()===0&&(f==null||f(),f=void 0)}};return{content:r,set:u,watch:()=>U({content:r,subscribe:a}),subscribe:a,update:d=>{u(d(r()))},nOfSubscriptions:s.nOfSubscriptions}}function R(t,c){const{content:i,nOfSubscriptions:s,subscribe:f,watch:n}=B(t,c);return{content:i,nOfSubscriptions:s,subscribe:f,watch:n}}/**
*/const m={storeCount:0};function B(n,c){var E;let s=n;const i=b();let o;const t=typeof c=="function"?c:c==null?void 0:c.start,a=(E=typeof c=="function"||c==null?void 0:c.comparator)!=null?E:(u,l)=>u===l,r=()=>{if(i.nOfSubscriptions()>0)return s;let u;return d(D=>u=D)(),u},p=u=>{s!==void 0&&a(s,u)||(s=u,i.emit(s))},d=u=>{i.nOfSubscriptions()===0&&(o=t==null?void 0:t(p));const l=i.subscribe(u);return u(s),()=>{l(),i.nOfSubscriptions()===0&&(o==null||o(),o=void 0)}},v=u=>{p(u(r()))};m.storeCount++;const h=m.storeCount;return{content:r,set:p,watch:()=>U(h,{content:r,subscribe:d}),subscribe:d,update:v,nOfSubscriptions:i.nOfSubscriptions}}function I(n,c){const{content:s,nOfSubscriptions:i,subscribe:o,watch:t}=B(n,c);return{content:s,nOfSubscriptions:i,subscribe:o,watch:t}}/**
* @license

@@ -20,2 +20,2 @@ * Copyright (c) 2016-22 [these people](https://github.com/sveltejs/svelte/graphs/contributors)

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/function j(t,c,i){const s=Array.isArray(t),f=!s&&"subscribe"in t&&"nOfSubscriptions"in t&&"content"in t,n=f?1:s?t.length:Object.keys(t).length;return R(void 0,{comparator:i==null?void 0:i.comparator,start:n===0?r=>{r(c(s?[]:{}))}:f?r=>t.subscribe(a=>r(c(a))):s?r=>{let u=new Array(t.length),a=0;const g=t.map((p,d)=>p.subscribe(E=>{if(a<n&&(u[d]=E,a++),a===n){const l=[...u];l[d]=E,r(c(l)),u=l}}));return()=>{for(const p of g)p();a=0}}:r=>{let u={},a=0;const g=Object.entries(t).map(([p,d])=>d.subscribe(E=>{if(a<n&&(u[p]=E,a++),a===n){const l=M({},u);l[p]=E,r(c(l)),u=l}}));return()=>{for(const p of g)p();a=0}}})}o.BatchingEffectError=m,o.MissingEffectError=v,o.NestedEffectError=y,o.ReactiveRootDisposeError=I,o.batchEffects=F,o.makeDerivedStore=j,o.makeReactiveRoot=A,o.makeReadonlyStore=R,o.makeStore=B,Object.defineProperty(o,"__esModule",{value:!0}),o[Symbol.toStringTag]="Module"});
*/function j(n,c,s){const i=Array.isArray(n),o=!i&&"subscribe"in n&&"nOfSubscriptions"in n&&"content"in n,t=o?1:i?n.length:Object.keys(n).length;return I(void 0,{comparator:s==null?void 0:s.comparator,start:t===0?r=>{r(c(i?[]:{}))}:o?r=>n.subscribe(d=>r(c(d))):i?r=>{let p=new Array(n.length),d=0;const v=n.map((h,E)=>h.subscribe(u=>{if(d<t&&(p[E]=u,d++),d===t){const l=[...p];l[E]=u,r(c(l)),p=l}}));return()=>{for(const h of v)h();d=0}}:r=>{let p={},d=0;const v=Object.entries(n).map(([h,E])=>E.subscribe(u=>{if(d<t&&(p[h]=u,d++),d===t){const l=A({},p);l[h]=u,r(c(l)),p=l}}));return()=>{for(const h of v)h();d=0}}})}f.BatchingEffectError=y,f.NestedEffectError=R,f.ReactiveRootDisposeError=g,f.batchEffects=M,f.makeDerivedStore=j,f.makeReactiveRoot=F,f.makeReadonlyStore=I,f.makeStore=B,f.storeRuntime=m,Object.defineProperty(f,"__esModule",{value:!0}),f[Symbol.toStringTag]="Module"});

@@ -27,2 +27,5 @@ /**

export declare type StartHandler<T> = (set: Setter<T>) => StopHandler | void;
export declare const storeRuntime: {
storeCount: number;
};
/**

@@ -29,0 +32,0 @@ * A store that can have subscribers and emit values to them. It also

@@ -5,3 +5,3 @@ {

"description": "State management made simple",
"version": "2.4.2",
"version": "2.4.3",
"type": "module",

@@ -8,0 +8,0 @@ "types": "dist/index.d.ts",

Sorry, the diff of this file is not supported yet

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