Socket
Book a DemoInstallSign in
Socket

signalrx

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

signalrx

A lightweight library for managing signals as global reactive stores.

latest
Source
npmnpm
Version
1.0.33
Version published
Weekly downloads
33
-98.06%
Maintainers
1
Weekly downloads
 
Created
Source

💡 SignalRX

SignalRX is a lightweight and highly optimized library for managing signals as global reactive stores in a simple, efficient, and intuitive way.

🚀 Installation

npm install signalrx
# or
yarn add signalrx

🧩 Example Usage

🧱 Create a Signal Store

import { Signal } from "signalrx";

interface AuthSignalState {
  isAuthenticated: boolean;
  token: string | null;
}

export const authSignalStore: Signal<AuthSignalState> = new Signal<AuthSignalState>({
  isAuthenticated: false,
  token: null,
} /* Initial State */);

📥 Get Data

import { Signal } from "signalrx";

interface AuthSignalState {
  isAuthenticated: boolean;
  token: string | null;
}

export const authSignalStore: Signal<AuthSignalState> = new Signal<AuthSignalState>({
  isAuthenticated: false,
  token: null,
});

/* Get the full store state */
const signalData = authSignalStore.getValue();

/* Get a partial value */
const token = authSignalStore.getValue(value => value.token);

/* Map to a custom object */
const newData = authSignalStore.getValue(value => ({
  valueToken: value.token,
  authenticated: value.isAuthenticated,
}));

⚙️ Update Data

import { Signal } from "signalrx";

interface AuthSignalState {
  isAuthenticated: boolean;
  token: string | null;
}

const authSignalStore: Signal<AuthSignalState> = new Signal<AuthSignalState>({
  isAuthenticated: false,
  token: null,
});

/* Method 1: Update partially using a callback */
authSignalStore.setData(prev => ({ ...prev, token: "token example" }));

/* Method 2: Replace the entire store */
authSignalStore.setData({ isAuthenticated: true, token: "token example" });

📡 Subscribe to the Signal

import { Signal } from "signalrx";

interface AuthSignalState {
  isAuthenticated: boolean;
  token: string | null;
}

const authSignalStore: Signal<AuthSignalState> = new Signal<AuthSignalState>({
  isAuthenticated: false,
  token: null,
});

/* Subscribe to changes */
const unsubscribe = authSignalStore.subscribe(value => {
  console.log(value); // { isAuthenticated: false, token: null }
});

The subscribe callback is automatically triggered whenever the signal value is updated through signal.setData().

🧽 Clear All Subscriptions

import { Signal } from "signalrx";

interface AuthSignalState {
  isAuthenticated: boolean;
  token: string | null;
}

const authSignalStore: Signal<AuthSignalState> = new Signal<AuthSignalState>({
  isAuthenticated: false,
  token: null,
});

/* Clear all active subscriptions */
authSignalStore.clearSubscriptions();

⚙️ Signal Configuration

💾 Built-in Storage Configuration

import { Signal } from "signalrx";

interface AuthSignalState {
  isAuthenticated: boolean;
  token: string | null;
}

const authSignalStore: Signal<AuthSignalState> = new Signal<AuthSignalState>(
  {
    isAuthenticated: false,
    token: null,
  },
  {
    storage: {
      name: "<your-storage-key>",
      storageType: "localstorage" | "sessionstorage" | "custom",
      values: {
        token: true,           // Save this property to storage
        isAuthenticated: false // Do not save this property
      },
    },
  } /* Signal config */
);

💾 Custom Storage Configuration

import { Signal } from "signalrx";

interface AuthSignalState {
  isAuthenticated: boolean;
  token: string | null;
}

const authSignalStore: Signal<AuthSignalState> = new Signal<AuthSignalState>(
  {
    isAuthenticated: false,
    token: null,
  },
  {
    storage: {
      name: "<your-storage-key>",
      storageType: "custom",
      customStorage: {
        getValue() {
          // Your custom implementation
        },
        setValue() {
          // Your custom implementation
        },
        deleteValue() {
          // Your custom implementation
        },
      },
    },
  } /* Signal config */
);

/* You can use the `CustomSignalConfigStorage<T>` interface to type your custom storage */

✅ Summary

  • getValue() → Retrieve the full or partial signal state.
  • setData() → Update or replace the current signal data.
  • subscribe() → Listen to signal changes in real-time.
  • clearSubscriptions() → Remove all active signal subscriptions.
  • storage → Persist specific values using localStorage, sessionStorage, or a custom storage engine.

💡 Key Features

  • Reactive — Signals update all subscribers automatically.
  • 💾 Persistent — Store values in browser storage easily.
  • 🧠 Type-safe — Fully typed with TypeScript generics.
  • 🧩 Modular — Works seamlessly in any frontend or backend environment.
  • 🪶 Lightweight — Zero dependencies, minimal footprint.

Contributing

If you want to contribute, please fork this repository and create a pull request. Direct pushes to main are not allowed.

📜 License

MIT © 2025 — Created with ❤️ by Joaquin Feola

Keywords

signal

FAQs

Package last updated on 26 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts