ngx-signal-plus 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/fesm2022/ngx-signal-plus.mjs +62 -1
- package/fesm2022/ngx-signal-plus.mjs.map +1 -1
- package/index.d.ts +28 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -382,6 +382,31 @@ const darkMode = spPresets.toggle({
|
|
|
382
382
|
});
|
|
383
383
|
```
|
|
384
384
|
|
|
385
|
+
### Middleware/Plugin System
|
|
386
|
+
|
|
387
|
+
Intercept signal operations for logging, analytics, and error tracking:
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
390
|
+
import { spUseMiddleware, spLoggerMiddleware, spAnalyticsMiddleware } from "ngx-signal-plus";
|
|
391
|
+
|
|
392
|
+
// Built-in logger middleware
|
|
393
|
+
spUseMiddleware(spLoggerMiddleware("[DEBUG]"));
|
|
394
|
+
|
|
395
|
+
// Custom analytics middleware
|
|
396
|
+
spUseMiddleware(
|
|
397
|
+
spAnalyticsMiddleware((event) => {
|
|
398
|
+
analytics.track("signal_change", event);
|
|
399
|
+
}),
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
// Custom middleware
|
|
403
|
+
spUseMiddleware({
|
|
404
|
+
name: "error-tracker",
|
|
405
|
+
onSet: (ctx) => console.log(`${ctx.signalName}: ${ctx.oldValue} -> ${ctx.newValue}`),
|
|
406
|
+
onError: (error) => Sentry.captureException(error),
|
|
407
|
+
});
|
|
408
|
+
```
|
|
409
|
+
|
|
385
410
|
### State Management
|
|
386
411
|
|
|
387
412
|
```typescript
|
|
@@ -509,6 +534,7 @@ What happens during SSR:
|
|
|
509
534
|
| **Collection Management** | `spCollection` - Manage arrays of entities with ID-based CRUD, queries, transforms, and history |
|
|
510
535
|
| **Transactions & Batching** | `spTransaction`, `spBatch`, `spIsTransactionActive`, `spIsInTransaction`, `spIsInBatch`, `spGetModifiedSignals` |
|
|
511
536
|
| **Utilities** | `spValidators`, `spPresets` |
|
|
537
|
+
| **Middleware/Plugins** | `spUseMiddleware`, `spRemoveMiddleware`, `spLoggerMiddleware`, `spAnalyticsMiddleware` |
|
|
512
538
|
| **State Management** | `spHistoryManager`, `spStorageManager` |
|
|
513
539
|
| **Components** | `spSignalPlusComponent`, `spSignalPlusService`, `spSignalBuilder` |
|
|
514
540
|
|
|
@@ -4362,6 +4362,67 @@ function spFormGroup(config, options) {
|
|
|
4362
4362
|
};
|
|
4363
4363
|
}
|
|
4364
4364
|
|
|
4365
|
+
/**
|
|
4366
|
+
* Middleware system for intercepting signal operations.
|
|
4367
|
+
*/
|
|
4368
|
+
const middlewareRegistry = [];
|
|
4369
|
+
function spUseMiddleware(middleware) {
|
|
4370
|
+
if (!middlewareRegistry.some((m) => m.name === middleware.name)) {
|
|
4371
|
+
middlewareRegistry.push(middleware);
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
function spRemoveMiddleware(name) {
|
|
4375
|
+
const index = middlewareRegistry.findIndex((m) => m.name === name);
|
|
4376
|
+
if (index === -1)
|
|
4377
|
+
return false;
|
|
4378
|
+
middlewareRegistry.splice(index, 1);
|
|
4379
|
+
return true;
|
|
4380
|
+
}
|
|
4381
|
+
function spClearMiddleware() {
|
|
4382
|
+
middlewareRegistry.length = 0;
|
|
4383
|
+
}
|
|
4384
|
+
function spGetMiddlewareCount() {
|
|
4385
|
+
return middlewareRegistry.length;
|
|
4386
|
+
}
|
|
4387
|
+
function spRunMiddleware(context) {
|
|
4388
|
+
for (const m of middlewareRegistry) {
|
|
4389
|
+
try {
|
|
4390
|
+
m.onSet?.(context);
|
|
4391
|
+
}
|
|
4392
|
+
catch {
|
|
4393
|
+
/* ignore */
|
|
4394
|
+
}
|
|
4395
|
+
}
|
|
4396
|
+
}
|
|
4397
|
+
function spRunMiddlewareError(error, context) {
|
|
4398
|
+
for (const m of middlewareRegistry) {
|
|
4399
|
+
try {
|
|
4400
|
+
m.onError?.(error, context);
|
|
4401
|
+
}
|
|
4402
|
+
catch {
|
|
4403
|
+
/* ignore */
|
|
4404
|
+
}
|
|
4405
|
+
}
|
|
4406
|
+
}
|
|
4407
|
+
function spLoggerMiddleware(prefix = '[Signal]') {
|
|
4408
|
+
return {
|
|
4409
|
+
name: 'sp-logger',
|
|
4410
|
+
onSet: (ctx) => console.log(`${prefix} ${ctx.signalName || 'signal'}: ${JSON.stringify(ctx.oldValue)} -> ${JSON.stringify(ctx.newValue)}`),
|
|
4411
|
+
onError: (error, ctx) => console.error(`${prefix} Error in ${ctx.signalName || 'signal'}:`, error.message),
|
|
4412
|
+
};
|
|
4413
|
+
}
|
|
4414
|
+
function spAnalyticsMiddleware(tracker) {
|
|
4415
|
+
return {
|
|
4416
|
+
name: 'sp-analytics',
|
|
4417
|
+
onSet: (ctx) => tracker({
|
|
4418
|
+
name: ctx.signalName || 'unknown',
|
|
4419
|
+
oldValue: ctx.oldValue,
|
|
4420
|
+
newValue: ctx.newValue,
|
|
4421
|
+
timestamp: ctx.timestamp,
|
|
4422
|
+
}),
|
|
4423
|
+
};
|
|
4424
|
+
}
|
|
4425
|
+
|
|
4365
4426
|
/**
|
|
4366
4427
|
* @fileoverview Transaction and batching utilities for ngx-signal-plus
|
|
4367
4428
|
* @description Provides functionality for atomic operations and batched updates
|
|
@@ -5748,5 +5809,5 @@ function createQuery(queryKey, queryFn, options) {
|
|
|
5748
5809
|
* Generated bundle index. Do not edit.
|
|
5749
5810
|
*/
|
|
5750
5811
|
|
|
5751
|
-
export { QueryClient, createMutation, createQuery, enhance, getGlobalQueryClient, setGlobalQueryClient, sp, spAsync, spBatch, spCollection, combineLatest as spCombineLatest, spComputed, spCounter, debounceTime as spDebounceTime, delay$1 as spDelay, distinctUntilChanged as spDistinctUntilChanged, filter as spFilter, spForm, spFormGroup, spGetModifiedSignals, HistoryManager as spHistoryManager, spIsInBatch, spIsInTransaction, spIsTransactionActive, map as spMap, merge as spMerge, spMutation, presets as spPresets, spQuery, SignalBuilder as spSignalBuilder, SignalPlusComponent as spSignalPlusComponent, SignalPlusService as spSignalPlusService, skip as spSkip, StorageManager as spStorageManager, take as spTake, throttleTime as spThrottleTime, spToggle, spTransaction, validators as spValidators };
|
|
5812
|
+
export { QueryClient, createMutation, createQuery, enhance, getGlobalQueryClient, setGlobalQueryClient, sp, spAnalyticsMiddleware, spAsync, spBatch, spClearMiddleware, spCollection, combineLatest as spCombineLatest, spComputed, spCounter, debounceTime as spDebounceTime, delay$1 as spDelay, distinctUntilChanged as spDistinctUntilChanged, filter as spFilter, spForm, spFormGroup, spGetMiddlewareCount, spGetModifiedSignals, HistoryManager as spHistoryManager, spIsInBatch, spIsInTransaction, spIsTransactionActive, spLoggerMiddleware, map as spMap, merge as spMerge, spMutation, presets as spPresets, spQuery, spRemoveMiddleware, SignalBuilder as spSignalBuilder, SignalPlusComponent as spSignalPlusComponent, SignalPlusService as spSignalPlusService, skip as spSkip, StorageManager as spStorageManager, take as spTake, throttleTime as spThrottleTime, spToggle, spTransaction, spUseMiddleware, validators as spValidators };
|
|
5752
5813
|
//# sourceMappingURL=ngx-signal-plus.mjs.map
|