@ngrx/signals 17.1.1 → 18.0.0-beta.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 (31) hide show
  1. package/entities/src/models.d.ts +2 -4
  2. package/esm2022/entities/src/helpers.mjs +1 -1
  3. package/esm2022/entities/src/models.mjs +1 -1
  4. package/esm2022/rxjs-interop/src/rx-method.mjs +1 -1
  5. package/esm2022/src/deep-signal.mjs +1 -1
  6. package/esm2022/src/helpers.mjs +1 -1
  7. package/esm2022/src/patch-state.mjs +1 -1
  8. package/esm2022/src/signal-store.mjs +4 -4
  9. package/esm2022/src/with-hooks.mjs +1 -1
  10. package/fesm2022/ngrx-signals-entities.mjs +191 -174
  11. package/fesm2022/ngrx-signals-entities.mjs.map +7 -1
  12. package/fesm2022/ngrx-signals-rxjs-interop.mjs +33 -36
  13. package/fesm2022/ngrx-signals-rxjs-interop.mjs.map +7 -1
  14. package/fesm2022/ngrx-signals.mjs +176 -162
  15. package/fesm2022/ngrx-signals.mjs.map +7 -1
  16. package/package.json +2 -2
  17. package/schematics-core/utility/ast-utils.js.map +1 -1
  18. package/schematics-core/utility/change.js.map +1 -1
  19. package/schematics-core/utility/config.js.map +1 -1
  20. package/schematics-core/utility/find-component.js.map +1 -1
  21. package/schematics-core/utility/find-module.js.map +1 -1
  22. package/schematics-core/utility/json-utilts.js.map +1 -1
  23. package/schematics-core/utility/libs-version.js +1 -1
  24. package/schematics-core/utility/libs-version.js.map +1 -1
  25. package/schematics-core/utility/ngrx-utils.js.map +1 -1
  26. package/schematics-core/utility/package.js.map +1 -1
  27. package/schematics-core/utility/project.js.map +1 -1
  28. package/schematics-core/utility/strings.js.map +1 -1
  29. package/schematics-core/utility/update.js.map +1 -1
  30. package/schematics-core/utility/visitors.js.map +1 -1
  31. package/src/patch-state.d.ts +2 -1
@@ -1,40 +1,37 @@
1
- import { assertInInjectionContext, Injector, inject, DestroyRef, isSignal, untracked, effect } from '@angular/core';
2
- import { Subject, isObservable, noop } from 'rxjs';
3
-
1
+ // src/rx-method.mjs
2
+ import { assertInInjectionContext, DestroyRef, effect, inject, Injector, isSignal, untracked } from "@angular/core";
3
+ import { isObservable, noop, Subject } from "rxjs";
4
4
  function rxMethod(generator, config) {
5
- if (!config?.injector) {
6
- assertInInjectionContext(rxMethod);
5
+ if (!config?.injector) {
6
+ assertInInjectionContext(rxMethod);
7
+ }
8
+ const injector = config?.injector ?? inject(Injector);
9
+ const destroyRef = injector.get(DestroyRef);
10
+ const source$ = new Subject();
11
+ const sourceSub = generator(source$).subscribe();
12
+ destroyRef.onDestroy(() => sourceSub.unsubscribe());
13
+ const rxMethodFn = (input) => {
14
+ if (isSignal(input)) {
15
+ const watcher = effect(() => {
16
+ const value = input();
17
+ untracked(() => source$.next(value));
18
+ }, { injector });
19
+ const instanceSub = { unsubscribe: () => watcher.destroy() };
20
+ sourceSub.add(instanceSub);
21
+ return instanceSub;
7
22
  }
8
- const injector = config?.injector ?? inject(Injector);
9
- const destroyRef = injector.get(DestroyRef);
10
- const source$ = new Subject();
11
- const sourceSub = generator(source$).subscribe();
12
- destroyRef.onDestroy(() => sourceSub.unsubscribe());
13
- const rxMethodFn = (input) => {
14
- if (isSignal(input)) {
15
- const watcher = effect(() => {
16
- const value = input();
17
- untracked(() => source$.next(value));
18
- }, { injector });
19
- const instanceSub = { unsubscribe: () => watcher.destroy() };
20
- sourceSub.add(instanceSub);
21
- return instanceSub;
22
- }
23
- if (isObservable(input)) {
24
- const instanceSub = input.subscribe((value) => source$.next(value));
25
- sourceSub.add(instanceSub);
26
- return instanceSub;
27
- }
28
- source$.next(input);
29
- return { unsubscribe: noop };
30
- };
31
- rxMethodFn.unsubscribe = sourceSub.unsubscribe.bind(sourceSub);
32
- return rxMethodFn;
23
+ if (isObservable(input)) {
24
+ const instanceSub = input.subscribe((value) => source$.next(value));
25
+ sourceSub.add(instanceSub);
26
+ return instanceSub;
27
+ }
28
+ source$.next(input);
29
+ return { unsubscribe: noop };
30
+ };
31
+ rxMethodFn.unsubscribe = sourceSub.unsubscribe.bind(sourceSub);
32
+ return rxMethodFn;
33
33
  }
34
-
35
- /**
36
- * Generated bundle index. Do not edit.
37
- */
38
-
39
- export { rxMethod };
34
+ export {
35
+ rxMethod
36
+ };
40
37
  //# sourceMappingURL=ngrx-signals-rxjs-interop.mjs.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"ngrx-signals-rxjs-interop.mjs","sources":["../../../../modules/signals/rxjs-interop/src/rx-method.ts","../../../../modules/signals/rxjs-interop/ngrx-signals-rxjs-interop.ts"],"sourcesContent":["import {\n assertInInjectionContext,\n DestroyRef,\n effect,\n inject,\n Injector,\n isSignal,\n Signal,\n untracked,\n} from '@angular/core';\nimport { isObservable, noop, Observable, Subject, Unsubscribable } from 'rxjs';\n\ntype RxMethodInput<Input> = Input | Observable<Input> | Signal<Input>;\n\ntype RxMethod<Input> = ((input: RxMethodInput<Input>) => Unsubscribable) &\n Unsubscribable;\n\nexport function rxMethod<Input>(\n generator: (source$: Observable<Input>) => Observable<unknown>,\n config?: { injector?: Injector }\n): RxMethod<Input> {\n if (!config?.injector) {\n assertInInjectionContext(rxMethod);\n }\n\n const injector = config?.injector ?? inject(Injector);\n const destroyRef = injector.get(DestroyRef);\n const source$ = new Subject<Input>();\n\n const sourceSub = generator(source$).subscribe();\n destroyRef.onDestroy(() => sourceSub.unsubscribe());\n\n const rxMethodFn = (input: RxMethodInput<Input>) => {\n if (isSignal(input)) {\n const watcher = effect(\n () => {\n const value = input();\n untracked(() => source$.next(value));\n },\n { injector }\n );\n const instanceSub = { unsubscribe: () => watcher.destroy() };\n sourceSub.add(instanceSub);\n\n return instanceSub;\n }\n\n if (isObservable(input)) {\n const instanceSub = input.subscribe((value) => source$.next(value));\n sourceSub.add(instanceSub);\n\n return instanceSub;\n }\n\n source$.next(input);\n return { unsubscribe: noop };\n };\n rxMethodFn.unsubscribe = sourceSub.unsubscribe.bind(sourceSub);\n\n return rxMethodFn;\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAiBgB,SAAA,QAAQ,CACtB,SAA8D,EAC9D,MAAgC,EAAA;AAEhC,IAAA,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE;QACrB,wBAAwB,CAAC,QAAQ,CAAC,CAAC;AACpC,KAAA;IAED,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC;IACtD,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC5C,IAAA,MAAM,OAAO,GAAG,IAAI,OAAO,EAAS,CAAC;IAErC,MAAM,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC;IACjD,UAAU,CAAC,SAAS,CAAC,MAAM,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC;AAEpD,IAAA,MAAM,UAAU,GAAG,CAAC,KAA2B,KAAI;AACjD,QAAA,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE;AACnB,YAAA,MAAM,OAAO,GAAG,MAAM,CACpB,MAAK;AACH,gBAAA,MAAM,KAAK,GAAG,KAAK,EAAE,CAAC;gBACtB,SAAS,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AACvC,aAAC,EACD,EAAE,QAAQ,EAAE,CACb,CAAC;AACF,YAAA,MAAM,WAAW,GAAG,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;AAC7D,YAAA,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAE3B,YAAA,OAAO,WAAW,CAAC;AACpB,SAAA;AAED,QAAA,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE;AACvB,YAAA,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AACpE,YAAA,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAE3B,YAAA,OAAO,WAAW,CAAC;AACpB,SAAA;AAED,QAAA,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACpB,QAAA,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AAC/B,KAAC,CAAC;IACF,UAAU,CAAC,WAAW,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAE/D,IAAA,OAAO,UAAU,CAAC;AACpB;;AC5DA;;AAEG;;;;"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../modules/signals/rxjs-interop/src/rx-method.ts"],
4
+ "sourcesContent": ["import {\n assertInInjectionContext,\n DestroyRef,\n effect,\n inject,\n Injector,\n isSignal,\n Signal,\n untracked,\n} from '@angular/core';\nimport { isObservable, noop, Observable, Subject, Unsubscribable } from 'rxjs';\n\ntype RxMethodInput<Input> = Input | Observable<Input> | Signal<Input>;\n\ntype RxMethod<Input> = ((input: RxMethodInput<Input>) => Unsubscribable) &\n Unsubscribable;\n\nexport function rxMethod<Input>(\n generator: (source$: Observable<Input>) => Observable<unknown>,\n config?: { injector?: Injector }\n): RxMethod<Input> {\n if (!config?.injector) {\n assertInInjectionContext(rxMethod);\n }\n\n const injector = config?.injector ?? inject(Injector);\n const destroyRef = injector.get(DestroyRef);\n const source$ = new Subject<Input>();\n\n const sourceSub = generator(source$).subscribe();\n destroyRef.onDestroy(() => sourceSub.unsubscribe());\n\n const rxMethodFn = (input: RxMethodInput<Input>) => {\n if (isSignal(input)) {\n const watcher = effect(\n () => {\n const value = input();\n untracked(() => source$.next(value));\n },\n { injector }\n );\n const instanceSub = { unsubscribe: () => watcher.destroy() };\n sourceSub.add(instanceSub);\n\n return instanceSub;\n }\n\n if (isObservable(input)) {\n const instanceSub = input.subscribe((value) => source$.next(value));\n sourceSub.add(instanceSub);\n\n return instanceSub;\n }\n\n source$.next(input);\n return { unsubscribe: noop };\n };\n rxMethodFn.unsubscribe = sourceSub.unsubscribe.bind(sourceSub);\n\n return rxMethodFn;\n}\n"],
5
+ "mappings": ";AAAA,SACE,0BACA,YACA,QACA,QACA,UACA,UAEA,iBACK;AACP,SAAS,cAAc,MAAkB,eAA+B;AAOlE,SAAU,SACd,WACA,QAAgC;AAEhC,MAAI,CAAC,QAAQ,UAAU;AACrB,6BAAyB,QAAQ;EACnC;AAEA,QAAM,WAAW,QAAQ,YAAY,OAAO,QAAQ;AACpD,QAAM,aAAa,SAAS,IAAI,UAAU;AAC1C,QAAM,UAAU,IAAI,QAAO;AAE3B,QAAM,YAAY,UAAU,OAAO,EAAE,UAAS;AAC9C,aAAW,UAAU,MAAM,UAAU,YAAW,CAAE;AAElD,QAAM,aAAa,CAAC,UAA+B;AACjD,QAAI,SAAS,KAAK,GAAG;AACnB,YAAM,UAAU,OACd,MAAK;AACH,cAAM,QAAQ,MAAK;AACnB,kBAAU,MAAM,QAAQ,KAAK,KAAK,CAAC;MACrC,GACA,EAAE,SAAQ,CAAE;AAEd,YAAM,cAAc,EAAE,aAAa,MAAM,QAAQ,QAAO,EAAE;AAC1D,gBAAU,IAAI,WAAW;AAEzB,aAAO;IACT;AAEA,QAAI,aAAa,KAAK,GAAG;AACvB,YAAM,cAAc,MAAM,UAAU,CAAC,UAAU,QAAQ,KAAK,KAAK,CAAC;AAClE,gBAAU,IAAI,WAAW;AAEzB,aAAO;IACT;AAEA,YAAQ,KAAK,KAAK;AAClB,WAAO,EAAE,aAAa,KAAI;EAC5B;AACA,aAAW,cAAc,UAAU,YAAY,KAAK,SAAS;AAE7D,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -1,207 +1,221 @@
1
- import * as i0 from '@angular/core';
2
- import { untracked, isSignal, computed, signal, DestroyRef, inject, Injectable } from '@angular/core';
3
-
4
- const STATE_SIGNAL = Symbol('STATE_SIGNAL');
1
+ // src/state-signal.mjs
2
+ var STATE_SIGNAL = Symbol("STATE_SIGNAL");
5
3
 
4
+ // src/get-state.mjs
6
5
  function getState(stateSignal) {
7
- return stateSignal[STATE_SIGNAL]();
6
+ return stateSignal[STATE_SIGNAL]();
8
7
  }
9
8
 
9
+ // src/patch-state.mjs
10
10
  function patchState(stateSignal, ...updaters) {
11
- stateSignal[STATE_SIGNAL].update((currentState) => updaters.reduce((nextState, updater) => ({
12
- ...nextState,
13
- ...(typeof updater === 'function' ? updater(nextState) : updater),
14
- }), currentState));
11
+ stateSignal[STATE_SIGNAL].update((currentState) => updaters.reduce((nextState, updater) => ({
12
+ ...nextState,
13
+ ...typeof updater === "function" ? updater(nextState) : updater
14
+ }), currentState));
15
15
  }
16
16
 
17
- function toDeepSignal(signal) {
18
- const value = untracked(() => signal());
19
- if (!isRecord(value)) {
20
- return signal;
17
+ // src/deep-signal.mjs
18
+ import { computed, isSignal, untracked } from "@angular/core";
19
+ function toDeepSignal(signal3) {
20
+ const value = untracked(() => signal3());
21
+ if (!isRecord(value)) {
22
+ return signal3;
23
+ }
24
+ return new Proxy(signal3, {
25
+ get(target, prop) {
26
+ if (!(prop in value)) {
27
+ return target[prop];
28
+ }
29
+ if (!isSignal(target[prop])) {
30
+ Object.defineProperty(target, prop, {
31
+ value: computed(() => target()[prop]),
32
+ configurable: true
33
+ });
34
+ }
35
+ return toDeepSignal(target[prop]);
21
36
  }
22
- return new Proxy(signal, {
23
- get(target, prop) {
24
- if (!(prop in value)) {
25
- return target[prop];
26
- }
27
- if (!isSignal(target[prop])) {
28
- Object.defineProperty(target, prop, {
29
- value: computed(() => target()[prop]),
30
- configurable: true,
31
- });
32
- }
33
- return toDeepSignal(target[prop]);
34
- },
35
- });
37
+ });
36
38
  }
37
39
  function isRecord(value) {
38
- return value?.constructor === Object;
40
+ return value?.constructor === Object;
39
41
  }
40
42
 
43
+ // src/signal-state.mjs
44
+ import { signal } from "@angular/core";
41
45
  function signalState(initialState) {
42
- const stateSignal = signal(initialState);
43
- const deepSignal = toDeepSignal(stateSignal.asReadonly());
44
- Object.defineProperty(deepSignal, STATE_SIGNAL, {
45
- value: stateSignal,
46
- });
47
- return deepSignal;
46
+ const stateSignal = signal(initialState);
47
+ const deepSignal = toDeepSignal(stateSignal.asReadonly());
48
+ Object.defineProperty(deepSignal, STATE_SIGNAL, {
49
+ value: stateSignal
50
+ });
51
+ return deepSignal;
48
52
  }
49
53
 
54
+ // src/signal-store.mjs
55
+ import { DestroyRef, inject, Injectable, signal as signal2 } from "@angular/core";
56
+ import * as i0 from "@angular/core";
50
57
  function signalStore(...args) {
51
- const signalStoreArgs = [...args];
52
- const config = 'providedIn' in signalStoreArgs[0]
53
- ? signalStoreArgs.shift()
54
- : {};
55
- const features = signalStoreArgs;
56
- class SignalStore {
57
- constructor() {
58
- const innerStore = features.reduce((store, feature) => feature(store), getInitialInnerStore());
59
- const { slices, signals, methods, hooks } = innerStore;
60
- const props = { ...slices, ...signals, ...methods };
61
- this[STATE_SIGNAL] = innerStore[STATE_SIGNAL];
62
- for (const key in props) {
63
- this[key] = props[key];
64
- }
65
- const { onInit, onDestroy } = hooks;
66
- if (onInit) {
67
- onInit();
68
- }
69
- if (onDestroy) {
70
- inject(DestroyRef).onDestroy(onDestroy);
71
- }
72
- }
73
- /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: SignalStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
74
- /** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: SignalStore, providedIn: config.providedIn || null });
58
+ const signalStoreArgs = [...args];
59
+ const config = "providedIn" in signalStoreArgs[0] ? signalStoreArgs.shift() : {};
60
+ const features = signalStoreArgs;
61
+ class SignalStore {
62
+ constructor() {
63
+ const innerStore = features.reduce((store, feature) => feature(store), getInitialInnerStore());
64
+ const { slices, signals, methods, hooks } = innerStore;
65
+ const props = { ...slices, ...signals, ...methods };
66
+ this[STATE_SIGNAL] = innerStore[STATE_SIGNAL];
67
+ for (const key in props) {
68
+ this[key] = props[key];
69
+ }
70
+ const { onInit, onDestroy } = hooks;
71
+ if (onInit) {
72
+ onInit();
73
+ }
74
+ if (onDestroy) {
75
+ inject(DestroyRef).onDestroy(onDestroy);
76
+ }
75
77
  }
76
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: SignalStore, decorators: [{
77
- type: Injectable,
78
- args: [{ providedIn: config.providedIn || null }]
79
- }], ctorParameters: () => [] });
80
- return SignalStore;
78
+ /** @nocollapse */
79
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: SignalStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
80
+ /** @nocollapse */
81
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: SignalStore, providedIn: config.providedIn || null });
82
+ }
83
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: SignalStore, decorators: [{
84
+ type: Injectable,
85
+ args: [{ providedIn: config.providedIn || null }]
86
+ }], ctorParameters: () => [] });
87
+ return SignalStore;
81
88
  }
82
89
  function getInitialInnerStore() {
83
- return {
84
- [STATE_SIGNAL]: signal({}),
85
- slices: {},
86
- signals: {},
87
- methods: {},
88
- hooks: {},
89
- };
90
+ return {
91
+ [STATE_SIGNAL]: signal2({}),
92
+ slices: {},
93
+ signals: {},
94
+ methods: {},
95
+ hooks: {}
96
+ };
90
97
  }
91
98
 
99
+ // src/signal-store-feature.mjs
92
100
  function signalStoreFeature(featureOrInput, ...restFeatures) {
93
- const features = typeof featureOrInput === 'function'
94
- ? [featureOrInput, ...restFeatures]
95
- : restFeatures;
96
- return (inputStore) => features.reduce((store, feature) => feature(store), inputStore);
101
+ const features = typeof featureOrInput === "function" ? [featureOrInput, ...restFeatures] : restFeatures;
102
+ return (inputStore) => features.reduce((store, feature) => feature(store), inputStore);
97
103
  }
98
104
  function type() {
99
- return undefined;
105
+ return void 0;
100
106
  }
101
107
 
108
+ // src/helpers.mjs
102
109
  function excludeKeys(obj, keys) {
103
- return Object.keys(obj).reduce((acc, key) => {
104
- if (!keys.includes(key)) {
105
- acc[key] = obj[key];
106
- }
107
- return acc;
108
- }, {});
110
+ return Object.keys(obj).reduce((acc, key) => {
111
+ if (!keys.includes(key)) {
112
+ acc[key] = obj[key];
113
+ }
114
+ return acc;
115
+ }, {});
109
116
  }
110
117
 
118
+ // src/with-computed.mjs
111
119
  function withComputed(signalsFactory) {
112
- return (store) => {
113
- const signals = signalsFactory({ ...store.slices, ...store.signals });
114
- const signalsKeys = Object.keys(signals);
115
- const slices = excludeKeys(store.slices, signalsKeys);
116
- const methods = excludeKeys(store.methods, signalsKeys);
117
- return {
118
- ...store,
119
- slices,
120
- signals: { ...store.signals, ...signals },
121
- methods,
122
- };
120
+ return (store) => {
121
+ const signals = signalsFactory({ ...store.slices, ...store.signals });
122
+ const signalsKeys = Object.keys(signals);
123
+ const slices = excludeKeys(store.slices, signalsKeys);
124
+ const methods = excludeKeys(store.methods, signalsKeys);
125
+ return {
126
+ ...store,
127
+ slices,
128
+ signals: { ...store.signals, ...signals },
129
+ methods
123
130
  };
131
+ };
124
132
  }
125
133
 
134
+ // src/with-hooks.mjs
126
135
  function withHooks(hooksOrFactory) {
127
- return (store) => {
128
- const storeProps = {
129
- [STATE_SIGNAL]: store[STATE_SIGNAL],
130
- ...store.slices,
131
- ...store.signals,
132
- ...store.methods,
133
- };
134
- const hooks = typeof hooksOrFactory === 'function'
135
- ? hooksOrFactory(storeProps)
136
- : hooksOrFactory;
137
- const createHook = (name) => {
138
- const hook = hooks[name];
139
- const currentHook = store.hooks[name];
140
- return hook
141
- ? () => {
142
- if (currentHook) {
143
- currentHook();
144
- }
145
- hook(storeProps);
146
- }
147
- : currentHook;
148
- };
149
- return {
150
- ...store,
151
- hooks: {
152
- onInit: createHook('onInit'),
153
- onDestroy: createHook('onDestroy'),
154
- },
155
- };
136
+ return (store) => {
137
+ const storeProps = {
138
+ [STATE_SIGNAL]: store[STATE_SIGNAL],
139
+ ...store.slices,
140
+ ...store.signals,
141
+ ...store.methods
156
142
  };
143
+ const hooks = typeof hooksOrFactory === "function" ? hooksOrFactory(storeProps) : hooksOrFactory;
144
+ const createHook = (name) => {
145
+ const hook = hooks[name];
146
+ const currentHook = store.hooks[name];
147
+ return hook ? () => {
148
+ if (currentHook) {
149
+ currentHook();
150
+ }
151
+ hook(storeProps);
152
+ } : currentHook;
153
+ };
154
+ return {
155
+ ...store,
156
+ hooks: {
157
+ onInit: createHook("onInit"),
158
+ onDestroy: createHook("onDestroy")
159
+ }
160
+ };
161
+ };
157
162
  }
158
163
 
164
+ // src/with-methods.mjs
159
165
  function withMethods(methodsFactory) {
160
- return (store) => {
161
- const methods = methodsFactory({
162
- [STATE_SIGNAL]: store[STATE_SIGNAL],
163
- ...store.slices,
164
- ...store.signals,
165
- ...store.methods,
166
- });
167
- const methodsKeys = Object.keys(methods);
168
- const slices = excludeKeys(store.slices, methodsKeys);
169
- const signals = excludeKeys(store.signals, methodsKeys);
170
- return {
171
- ...store,
172
- slices,
173
- signals,
174
- methods: { ...store.methods, ...methods },
175
- };
166
+ return (store) => {
167
+ const methods = methodsFactory({
168
+ [STATE_SIGNAL]: store[STATE_SIGNAL],
169
+ ...store.slices,
170
+ ...store.signals,
171
+ ...store.methods
172
+ });
173
+ const methodsKeys = Object.keys(methods);
174
+ const slices = excludeKeys(store.slices, methodsKeys);
175
+ const signals = excludeKeys(store.signals, methodsKeys);
176
+ return {
177
+ ...store,
178
+ slices,
179
+ signals,
180
+ methods: { ...store.methods, ...methods }
176
181
  };
182
+ };
177
183
  }
178
184
 
185
+ // src/with-state.mjs
186
+ import { computed as computed2 } from "@angular/core";
179
187
  function withState(stateOrFactory) {
180
- return (store) => {
181
- const state = typeof stateOrFactory === 'function' ? stateOrFactory() : stateOrFactory;
182
- const stateKeys = Object.keys(state);
183
- store[STATE_SIGNAL].update((currentState) => ({
184
- ...currentState,
185
- ...state,
186
- }));
187
- const slices = stateKeys.reduce((acc, key) => {
188
- const slice = computed(() => store[STATE_SIGNAL]()[key]);
189
- return { ...acc, [key]: toDeepSignal(slice) };
190
- }, {});
191
- const signals = excludeKeys(store.signals, stateKeys);
192
- const methods = excludeKeys(store.methods, stateKeys);
193
- return {
194
- ...store,
195
- slices: { ...store.slices, ...slices },
196
- signals,
197
- methods,
198
- };
188
+ return (store) => {
189
+ const state = typeof stateOrFactory === "function" ? stateOrFactory() : stateOrFactory;
190
+ const stateKeys = Object.keys(state);
191
+ store[STATE_SIGNAL].update((currentState) => ({
192
+ ...currentState,
193
+ ...state
194
+ }));
195
+ const slices = stateKeys.reduce((acc, key) => {
196
+ const slice = computed2(() => store[STATE_SIGNAL]()[key]);
197
+ return { ...acc, [key]: toDeepSignal(slice) };
198
+ }, {});
199
+ const signals = excludeKeys(store.signals, stateKeys);
200
+ const methods = excludeKeys(store.methods, stateKeys);
201
+ return {
202
+ ...store,
203
+ slices: { ...store.slices, ...slices },
204
+ signals,
205
+ methods
199
206
  };
207
+ };
200
208
  }
201
-
202
- /**
203
- * Generated bundle index. Do not edit.
204
- */
205
-
206
- export { getState, patchState, signalState, signalStore, signalStoreFeature, type, withComputed, withHooks, withMethods, withState };
209
+ export {
210
+ getState,
211
+ patchState,
212
+ signalState,
213
+ signalStore,
214
+ signalStoreFeature,
215
+ type,
216
+ withComputed,
217
+ withHooks,
218
+ withMethods,
219
+ withState
220
+ };
207
221
  //# sourceMappingURL=ngrx-signals.mjs.map