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

@cdellacqua/signals

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cdellacqua/signals - npm Package Compare versions

Comparing version 4.1.2 to 5.0.0

2

dist/index.d.ts

@@ -25,3 +25,3 @@ /** A generic subscriber that takes a value emitted by a signal as its only parameter. */

*/
get nOfSubscriptions(): number;
nOfSubscriptions(): number;
};

@@ -28,0 +28,0 @@ /** A signal that can have subscribers and emit values to them. */

@@ -7,3 +7,3 @@ function deriveSignal(signal$, transform) {

const handleUnsubscribe = () => {
if (unsubscribeOriginal && base$.nOfSubscriptions === 0) {
if (unsubscribeOriginal && base$.nOfSubscriptions() === 0) {
unsubscribeOriginal();

@@ -15,5 +15,3 @@ unsubscribeOriginal = null;

return {
get nOfSubscriptions() {
return base$.nOfSubscriptions;
},
nOfSubscriptions: base$.nOfSubscriptions,
subscribe: (s) => {

@@ -50,3 +48,3 @@ const unsubscribe = base$.subscribe(s);

const handleUnsubscribe = () => {
if (unsubscribeOriginals && base$.nOfSubscriptions === 0) {
if (unsubscribeOriginals && base$.nOfSubscriptions() === 0) {
unsubscribeOriginals.forEach((unsub) => unsub());

@@ -58,5 +56,3 @@ unsubscribeOriginals = null;

return {
get nOfSubscriptions() {
return base$.nOfSubscriptions;
},
nOfSubscriptions: base$.nOfSubscriptions,
subscribe: (s) => {

@@ -118,3 +114,3 @@ const unsubscribe = base$.subscribe(s);

subscribeOnce,
get nOfSubscriptions() {
nOfSubscriptions() {
return subscribers.length;

@@ -121,0 +117,0 @@ }

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

(function(r,o){typeof exports=="object"&&typeof module!="undefined"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(r=typeof globalThis!="undefined"?globalThis:r||self,o(r.signals={}))})(this,function(r){"use strict";function o(i,t){const c=f(),b=e=>{c.emit(t(e))},s=()=>{n&&c.nOfSubscriptions===0&&(n(),n=null)};let n=null;return{get nOfSubscriptions(){return c.nOfSubscriptions},subscribe:e=>{const u=c.subscribe(e);return n||(n=i.subscribe(b)),()=>{u(),s()}},subscribeOnce:e=>{const u=c.subscribeOnce(d=>{e(d),s()});return n||(n=i.subscribe(b)),()=>{u(),s()}}}}function l(i){const t=f(),c=n=>{t.emit(n)},b=()=>{s&&t.nOfSubscriptions===0&&(s.forEach(n=>n()),s=null)};let s=null;return{get nOfSubscriptions(){return t.nOfSubscriptions},subscribe:n=>{const e=t.subscribe(n);return s||(s=i.map(u=>u.subscribe(c))),()=>{e(),b()}},subscribeOnce:n=>{const e=t.subscribeOnce(u=>{n(u),b()});return s||(s=i.map(u=>u.subscribe(c))),()=>{e(),b()}}}}function f(){const i=[];function t(n){for(const e of[...i])e(n)}function c(n){const e=i.indexOf(n);e!==-1&&i.splice(e,1)}function b(n){return i.indexOf(n)===-1&&i.push(n),()=>c(n)}function s(n){const e=b(u=>{e(),n(u)});return e}return{emit:t,subscribe:b,subscribeOnce:s,get nOfSubscriptions(){return i.length}}}r.coalesceSignals=l,r.deriveSignal=o,r.makeSignal=f,Object.defineProperty(r,"__esModule",{value:!0}),r[Symbol.toStringTag]="Module"});
(function(r,o){typeof exports=="object"&&typeof module!="undefined"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(r=typeof globalThis!="undefined"?globalThis:r||self,o(r.signals={}))})(this,function(r){"use strict";function o(i,b){const c=f(),t=e=>{c.emit(b(e))},s=()=>{n&&c.nOfSubscriptions()===0&&(n(),n=null)};let n=null;return{nOfSubscriptions:c.nOfSubscriptions,subscribe:e=>{const u=c.subscribe(e);return n||(n=i.subscribe(t)),()=>{u(),s()}},subscribeOnce:e=>{const u=c.subscribeOnce(d=>{e(d),s()});return n||(n=i.subscribe(t)),()=>{u(),s()}}}}function l(i){const b=f(),c=n=>{b.emit(n)},t=()=>{s&&b.nOfSubscriptions()===0&&(s.forEach(n=>n()),s=null)};let s=null;return{nOfSubscriptions:b.nOfSubscriptions,subscribe:n=>{const e=b.subscribe(n);return s||(s=i.map(u=>u.subscribe(c))),()=>{e(),t()}},subscribeOnce:n=>{const e=b.subscribeOnce(u=>{n(u),t()});return s||(s=i.map(u=>u.subscribe(c))),()=>{e(),t()}}}}function f(){const i=[];function b(n){for(const e of[...i])e(n)}function c(n){const e=i.indexOf(n);e!==-1&&i.splice(e,1)}function t(n){return i.indexOf(n)===-1&&i.push(n),()=>c(n)}function s(n){const e=t(u=>{e(),n(u)});return e}return{emit:b,subscribe:t,subscribeOnce:s,nOfSubscriptions(){return i.length}}}r.coalesceSignals=l,r.deriveSignal=o,r.makeSignal=f,Object.defineProperty(r,"__esModule",{value:!0}),r[Symbol.toStringTag]="Module"});

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

"description": "A simple signal pattern implementation that enables reactive programming",
"version": "4.1.2",
"version": "5.0.0",
"type": "module",

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

@@ -26,2 +26,18 @@ # @cdellacqua/signals

## Migrating to V5
TL;DR: replace nOfSubscriptions to nOfSubscriptions().
The only major change is the refactoring of nOfSubscriptions.
In V1 it was a getter property, in V2 it's a function.
This change is meant to prevent common pitfalls that occur when composing signals in custom objects. As an example, when using {...signal$, myCustomExtension() { /* my code */ } }, the
object spread syntax would previously capture the current value returned by the
getter, making the field a regular object property that couldn't update on its own.
It's now possible to use the spread syntax, because it will capture the function
instead of the current value.
A positive side effect of this change is the reduced number of function calls necessary to reach the value hidden behind the getter (i.e. nOfSubscriptions doesn't need to be redefined as a getter in every composite object, it just needs to be a reference to the original function).
## Highlights

@@ -63,7 +79,7 @@

const signal$ = makeSignal<number>();
console.log(signal$.nOfSubscriptions); // 0
console.log(signal$.nOfSubscriptions()); // 0
const unsubscribe = signal$.subscribe(() => undefined); // empty subscriber
console.log(signal$.nOfSubscriptions); // 1
console.log(signal$.nOfSubscriptions()); // 1
unsubscribe();
console.log(signal$.nOfSubscriptions); // 0
console.log(signal$.nOfSubscriptions()); // 0
```

@@ -79,11 +95,11 @@

const subscriber = (v: number) => console.log(v);
console.log(signal$.nOfSubscriptions); // 0
console.log(signal$.nOfSubscriptions()); // 0
const unsubscribe1 = signal$.subscribe(subscriber);
const unsubscribe2 = signal$.subscribe(subscriber);
const unsubscribe3 = signal$.subscribe(subscriber);
console.log(signal$.nOfSubscriptions); // 1
console.log(signal$.nOfSubscriptions()); // 1
unsubscribe3(); // will remove "subscriber"
unsubscribe2(); // won't do anything, "subscriber" has already been removed
unsubscribe1(); // won't do anything, "subscriber" has already been removed
console.log(signal$.nOfSubscriptions); // 0
console.log(signal$.nOfSubscriptions()); // 0
```

@@ -98,11 +114,11 @@

const subscriber = (v: number) => console.log(v);
console.log(signal$.nOfSubscriptions); // 0
console.log(signal$.nOfSubscriptions()); // 0
const unsubscribe1 = signal$.subscribe(subscriber);
console.log(signal$.nOfSubscriptions); // 1
console.log(signal$.nOfSubscriptions()); // 1
const unsubscribe2 = signal$.subscribe((v) => subscriber(v));
console.log(signal$.nOfSubscriptions); // 2
console.log(signal$.nOfSubscriptions()); // 2
unsubscribe2();
console.log(signal$.nOfSubscriptions); // 1
console.log(signal$.nOfSubscriptions()); // 1
unsubscribe1();
console.log(signal$.nOfSubscriptions); // 0
console.log(signal$.nOfSubscriptions()); // 0
```

@@ -109,0 +125,0 @@

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