Skip to content

Commit 0b2ec01

Browse files
authored
revert: "refactor(store): drop ɵwrapObserverCalls (#2371)" (#2383)
This reverts commit 5a744a3.
1 parent 37cd3ad commit 0b2ec01

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ $ npm install @ngxs/store@dev
1212
- Fix(store): Stop contributing to stability once app is stable [#2379](https://github.com/ngxs/store/pull/2379)
1313
- Refactor(store): Clear `_states` on destroy to aid GC under high load [#2365](https://github.com/ngxs/store/pull/2365)
1414
- Refactor(store): Add `debugName` to `computed` signals in `selectSignal` [#2370](https://github.com/ngxs/store/pull/2370)
15-
- Refactor(store): Drop `ɵwrapObserverCalls` [#2371](https://github.com/ngxs/store/pull/2371)
1615
- Fix(storage-plugin): Guard against `engine` may be falsy [#2367](https://github.com/ngxs/store/pull/2367) [#2368](https://github.com/ngxs/store/pull/2368)
1716
- Peformance(storage-plugin): Replace closure-based action matcher with direct type comparison [#2369](https://github.com/ngxs/store/pull/2369)
1817
- Fix(router-plugin): Avoid redundant NGXS state updates for identical router snapshots [#2372](https://github.com/ngxs/store/pull/2372)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { type MonoTypeOperatorFunction, Observable } from 'rxjs';
2+
3+
export function ɵwrapObserverCalls<TValue>(
4+
invokeFn: (fn: () => void) => void
5+
): MonoTypeOperatorFunction<TValue> {
6+
return (source: Observable<TValue>) => {
7+
return new Observable<TValue>(subscriber => {
8+
return source.subscribe({
9+
next(value) {
10+
invokeFn(() => subscriber.next(value));
11+
},
12+
error(error) {
13+
invokeFn(() => subscriber.error(error));
14+
},
15+
complete() {
16+
invokeFn(() => subscriber.complete());
17+
}
18+
});
19+
});
20+
};
21+
}

packages/store/internals/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export { ɵINITIAL_STATE_TOKEN, ɵInitialState } from './initial-state';
66
export { ɵNgxsAppBootstrappedState } from './ngxs-app-bootstrapped-state';
77
export { ɵNGXS_STATE_CONTEXT_FACTORY, ɵNGXS_STATE_FACTORY } from './internal-tokens';
88
export { ɵOrderedSubject, ɵOrderedBehaviorSubject } from './custom-rxjs-subjects';
9+
export { ɵwrapObserverCalls } from './custom-rxjs-operators';
910
export { ɵStateStream } from './state-stream';
1011
export { ɵhasOwnProperty, ɵdefineProperty } from './object-utils';
1112
export { ɵNgxsActionRegistry } from './action-registry';

packages/store/internals/src/state-stream.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { DestroyRef, inject, Injectable, Signal, untracked } from '@angular/core
22
import { toSignal } from '@angular/core/rxjs-interop';
33
import { Observable } from 'rxjs';
44

5+
import { ɵwrapObserverCalls } from './custom-rxjs-operators';
56
import { ɵOrderedBehaviorSubject } from './custom-rxjs-subjects';
67
import { ɵPlainObject } from './symbols';
78

@@ -11,26 +12,10 @@ import { ɵPlainObject } from './symbols';
1112
*/
1213
@Injectable({ providedIn: 'root' })
1314
export class ɵStateStream extends ɵOrderedBehaviorSubject<ɵPlainObject> {
14-
readonly state: Signal<ɵPlainObject> = toSignal(
15-
this.pipe(
16-
source =>
17-
new Observable(subscriber =>
18-
source.subscribe({
19-
// Without `untracked()`, if some signal happened to be
20-
// read while computing the next state (e.g. reducers/selectors
21-
// reading other signals before calling `stateStream.next()`),
22-
// Angular would incorrectly record a dependency on that signal.
23-
next: value => untracked(() => subscriber.next(value)),
24-
error: error => untracked(() => subscriber.error(error)),
25-
complete: () => untracked(() => subscriber.complete())
26-
})
27-
)
28-
),
29-
{
30-
manualCleanup: true,
31-
requireSync: true
32-
}
33-
);
15+
readonly state: Signal<ɵPlainObject> = toSignal(this.pipe(ɵwrapObserverCalls(untracked)), {
16+
manualCleanup: true,
17+
requireSync: true
18+
});
3419

3520
constructor() {
3621
super({});
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
import { Observable } from 'rxjs';
1+
import { ɵwrapObserverCalls } from '@ngxs/store/internals';
2+
23
import { InternalNgxsExecutionStrategy } from '../execution/execution-strategy';
34

45
/**
56
* Returns operator that will run
67
* `subscribe` outside of the ngxs execution context
78
*/
89
export function leaveNgxs<T>(ngxsExecutionStrategy: InternalNgxsExecutionStrategy) {
9-
return (source: Observable<T>) =>
10-
new Observable<T>(subscriber =>
11-
source.subscribe({
12-
next: value => ngxsExecutionStrategy.leave(() => subscriber.next(value)),
13-
error: error => ngxsExecutionStrategy.leave(() => subscriber.error(error)),
14-
complete: () => ngxsExecutionStrategy.leave(() => subscriber.complete())
15-
})
16-
);
10+
return ɵwrapObserverCalls<T>(fn => ngxsExecutionStrategy.leave(fn));
1711
}

0 commit comments

Comments
 (0)