💡 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
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,
} );
📥 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,
});
const signalData = authSignalStore.getValue();
const token = authSignalStore.getValue(value => value.token);
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,
});
authSignalStore.setData(prev => ({ ...prev, token: "token example" }));
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,
});
const unsubscribe = authSignalStore.subscribe(value => {
console.log(value);
});
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,
});
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,
isAuthenticated: false
},
},
}
);
💾 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() {
},
setValue() {
},
deleteValue() {
},
},
},
}
);
✅ 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