@ngrx/signals 19.0.1 → 19.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.
Files changed (39) hide show
  1. package/entities/src/helpers.d.ts +4 -4
  2. package/entities/src/index.d.ts +4 -0
  3. package/entities/src/updaters/prepend-entities.d.ts +17 -0
  4. package/entities/src/updaters/prepend-entity.d.ts +17 -0
  5. package/entities/src/updaters/upsert-entities.d.ts +17 -0
  6. package/entities/src/updaters/upsert-entity.d.ts +17 -0
  7. package/events/index.d.ts +1 -0
  8. package/events/src/case-reducer.d.ts +20 -0
  9. package/events/src/dispatcher.d.ts +33 -0
  10. package/events/src/event-creator-group.d.ts +33 -0
  11. package/events/src/event-creator.d.ts +9 -0
  12. package/events/src/event-instance.d.ts +8 -0
  13. package/events/src/events-service.d.ts +47 -0
  14. package/events/src/index.d.ts +9 -0
  15. package/events/src/inject-dispatch.d.ts +46 -0
  16. package/events/src/with-effects.d.ts +28 -0
  17. package/events/src/with-reducer.d.ts +30 -0
  18. package/fesm2022/ngrx-signals-entities.mjs +68 -10
  19. package/fesm2022/ngrx-signals-entities.mjs.map +1 -1
  20. package/fesm2022/ngrx-signals-events.mjs +320 -0
  21. package/fesm2022/ngrx-signals-events.mjs.map +1 -0
  22. package/fesm2022/ngrx-signals-rxjs-interop.mjs +9 -2
  23. package/fesm2022/ngrx-signals-rxjs-interop.mjs.map +1 -1
  24. package/fesm2022/ngrx-signals-testing.mjs +15 -0
  25. package/fesm2022/ngrx-signals-testing.mjs.map +1 -0
  26. package/fesm2022/ngrx-signals.mjs +53 -7
  27. package/fesm2022/ngrx-signals.mjs.map +1 -1
  28. package/package.json +9 -1
  29. package/rxjs-interop/src/index.d.ts +1 -1
  30. package/rxjs-interop/src/rx-method.d.ts +1 -1
  31. package/schematics-core/utility/libs-version.js +1 -1
  32. package/schematics-core/utility/libs-version.js.map +1 -1
  33. package/src/index.d.ts +3 -2
  34. package/src/signal-method.d.ts +1 -2
  35. package/src/state-source.d.ts +1 -0
  36. package/src/with-feature.d.ts +25 -0
  37. package/testing/index.d.ts +1 -0
  38. package/testing/src/index.d.ts +1 -0
  39. package/testing/src/unprotected.d.ts +4 -0
@@ -0,0 +1,15 @@
1
+ import { isWritableStateSource } from '@ngrx/signals';
2
+
3
+ function unprotected(source) {
4
+ if (isWritableStateSource(source)) {
5
+ return source;
6
+ }
7
+ throw new Error('@ngrx/signals: The provided source is not writable.');
8
+ }
9
+
10
+ /**
11
+ * Generated bundle index. Do not edit.
12
+ */
13
+
14
+ export { unprotected };
15
+ //# sourceMappingURL=ngrx-signals-testing.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ngrx-signals-testing.mjs","sources":["../../../../modules/signals/testing/src/unprotected.ts","../../../../modules/signals/testing/ngrx-signals-testing.ts"],"sourcesContent":["import {\n isWritableStateSource,\n Prettify,\n StateSource,\n WritableStateSource,\n} from '@ngrx/signals';\n\ntype UnprotectedSource<Source extends StateSource<object>> =\n Source extends StateSource<infer State>\n ? Prettify<\n Omit<Source, keyof StateSource<State>> & WritableStateSource<State>\n >\n : never;\n\nexport function unprotected<Source extends StateSource<object>>(\n source: Source\n): UnprotectedSource<Source> {\n if (isWritableStateSource(source)) {\n return source as UnprotectedSource<Source>;\n }\n\n throw new Error('@ngrx/signals: The provided source is not writable.');\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AAcM,SAAU,WAAW,CACzB,MAAc,EAAA;AAEd,IAAA,IAAI,qBAAqB,CAAC,MAAM,CAAC,EAAE;AACjC,QAAA,OAAO,MAAmC;;AAG5C,IAAA,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC;AACxE;;ACtBA;;AAEG;;;;"}
@@ -64,7 +64,14 @@ function signalMethod(processingFn, config) {
64
64
  const sourceInjector = config?.injector ?? inject(Injector);
65
65
  const signalMethodFn = (input, config) => {
66
66
  if (isSignal(input)) {
67
- const instanceInjector = config?.injector ?? getCallerInjector() ?? sourceInjector;
67
+ const callerInjector = getCallerInjector();
68
+ if (typeof ngDevMode !== 'undefined' &&
69
+ ngDevMode &&
70
+ config?.injector === undefined &&
71
+ callerInjector === undefined) {
72
+ console.warn('@ngrx/signals: The function returned by signalMethod was called', 'outside the injection context with a signal. This may lead to', 'a memory leak. Make sure to call it within the injection context', '(e.g. in a constructor or field initializer) or pass an injector', 'explicitly via the config parameter.\n\nFor more information, see:', 'https://ngrx.io/guide/signals/signal-method#automatic-cleanup');
73
+ }
74
+ const instanceInjector = config?.injector ?? callerInjector ?? sourceInjector;
68
75
  const watcher = effect(() => {
69
76
  const value = input();
70
77
  untracked(() => processingFn(value));
@@ -91,12 +98,18 @@ function getCallerInjector() {
91
98
  return inject(Injector);
92
99
  }
93
100
  catch {
94
- return null;
101
+ return undefined;
95
102
  }
96
103
  }
97
104
 
98
105
  const STATE_WATCHERS = new WeakMap();
99
106
  const STATE_SOURCE = Symbol('STATE_SOURCE');
107
+ function isWritableStateSource(stateSource) {
108
+ return ('set' in stateSource[STATE_SOURCE] &&
109
+ 'update' in stateSource[STATE_SOURCE] &&
110
+ typeof stateSource[STATE_SOURCE].set === 'function' &&
111
+ typeof stateSource[STATE_SOURCE].update === 'function');
112
+ }
100
113
  function patchState(stateSource, ...updaters) {
101
114
  stateSource[STATE_SOURCE].update((currentState) => updaters.reduce((nextState, updater) => ({
102
115
  ...nextState,
@@ -174,10 +187,10 @@ function signalStore(...args) {
174
187
  inject(DestroyRef).onDestroy(onDestroy);
175
188
  }
176
189
  }
177
- /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: SignalStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
178
- /** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: SignalStore, providedIn: config.providedIn || null });
190
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: SignalStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
191
+ /** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: SignalStore, providedIn: config.providedIn || null });
179
192
  }
180
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: SignalStore, decorators: [{
193
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: SignalStore, decorators: [{
181
194
  type: Injectable,
182
195
  args: [{ providedIn: config.providedIn || null }]
183
196
  }], ctorParameters: () => [] });
@@ -204,7 +217,7 @@ function type() {
204
217
  }
205
218
 
206
219
  function assertUniqueStoreMembers(store, newMemberKeys) {
207
- if (!ngDevMode) {
220
+ if (typeof ngDevMode === 'undefined' || !ngDevMode) {
208
221
  return;
209
222
  }
210
223
  const storeMembers = {
@@ -238,6 +251,39 @@ function withComputed(signalsFactory) {
238
251
  return withProps(signalsFactory);
239
252
  }
240
253
 
254
+ /**
255
+ * @description
256
+ * Allows passing properties, methods, or signals from a SignalStore
257
+ * to a feature.
258
+ *
259
+ * @usageNotes
260
+ * ```typescript
261
+ * signalStore(
262
+ * withMethods((store) => ({
263
+ * load(id: number): Observable<Entity> {
264
+ * return of({ id, name: 'John' });
265
+ * },
266
+ * })),
267
+ * withFeature(
268
+ * // 👇 has full access to the store
269
+ * (store) => withEntityLoader((id) => firstValueFrom(store.load(id)))
270
+ * )
271
+ * );
272
+ * ```
273
+ *
274
+ * @param featureFactory function returning the actual feature
275
+ */
276
+ function withFeature(featureFactory) {
277
+ return (store) => {
278
+ const storeForFactory = {
279
+ ...store['stateSignals'],
280
+ ...store['props'],
281
+ ...store['methods'],
282
+ };
283
+ return featureFactory(storeForFactory)(store);
284
+ };
285
+ }
286
+
241
287
  function withHooks(hooksOrFactory) {
242
288
  return (store) => {
243
289
  const storeMembers = {
@@ -311,5 +357,5 @@ function withState(stateOrFactory) {
311
357
  * Generated bundle index. Do not edit.
312
358
  */
313
359
 
314
- export { deepComputed, getState, patchState, signalMethod, signalState, signalStore, signalStoreFeature, type, watchState, withComputed, withHooks, withMethods, withProps, withState };
360
+ export { deepComputed, getState, isWritableStateSource, patchState, signalMethod, signalState, signalStore, signalStoreFeature, type, watchState, withComputed, withFeature, withHooks, withMethods, withProps, withState };
315
361
  //# sourceMappingURL=ngrx-signals.mjs.map