Skip to content

Commit fa712ae

Browse files
JeanMecheAndrewKushnir
authored andcommitted
docs(docs-infra): temporary removal of core/rxjs-interop dependency (#60234)
To work around the limitation of #54858, this commit removes temporarly the dependency to `core/rxjs-interop` to allow the removal of the microtask effect which was pulled by that entry. This commit is intented to be reverted once the next patch/next is released. PR Close #60234
1 parent 02cb7e0 commit fa712ae

6 files changed

Lines changed: 107 additions & 6 deletions

File tree

‎adev/shared-docs/components/search-dialog/search-dialog.component.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ import {TextField} from '../text-field/text-field.component';
3030
import {FormsModule} from '@angular/forms';
3131
import {ActiveDescendantKeyManager} from '@angular/cdk/a11y';
3232
import {SearchItem} from '../../directives/search-item/search-item.directive';
33-
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
3433
import {Router, RouterLink} from '@angular/router';
35-
import {filter, fromEvent} from 'rxjs';
34+
import {fromEvent} from 'rxjs';
3635
import {AlgoliaIcon} from '../algolia-icon/algolia-icon.component';
3736
import {RelativeLink} from '../../pipes/relative-link.pipe';
3837
import {SearchResult, SnippetResult} from '../../interfaces';
38+
import {takeUntilDestroyed} from '../../services/rxjs-interop';
3939

4040
@Component({
4141
selector: 'docs-search-dialog',

‎adev/shared-docs/components/viewers/docs-viewer/docs-viewer.component.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
ɵPendingTasksInternal as PendingTasks,
2929
output,
3030
} from '@angular/core';
31-
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
3231
import {TOC_SKIP_CONTENT_MARKER, NavigationState} from '../../../services/index';
3332
import {TableOfContents} from '../../table-of-contents/table-of-contents.component';
3433
import {IconComponent} from '../../icon/icon.component';
@@ -40,6 +39,7 @@ import {fromEvent} from 'rxjs';
4039
import {Breadcrumb} from '../../breadcrumb/breadcrumb.component';
4140
import {CopySourceCodeButton} from '../../copy-source-code-button/copy-source-code-button.component';
4241
import {ExampleViewer} from '../example-viewer/example-viewer.component';
42+
import {takeUntilDestroyed} from '../../../services/rxjs-interop';
4343

4444
/// <reference types="@types/dom-view-transitions" />
4545

‎adev/shared-docs/components/viewers/example-viewer/example-viewer.component.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import {Clipboard} from '@angular/cdk/clipboard';
2929
import {CopySourceCodeButton} from '../../copy-source-code-button/copy-source-code-button.component';
3030
import {ExampleMetadata, Snippet} from '../../../interfaces/index';
3131
import {EXAMPLE_VIEWER_CONTENT_LOADER} from '../../../providers/index';
32-
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
3332
import {DocViewer} from '../docs-viewer/docs-viewer.component';
33+
import {takeUntilDestroyed} from '../../../services/rxjs-interop';
3434

3535
export enum CodeExampleViewMode {
3636
SNIPPET = 'snippet',

‎adev/shared-docs/services/BUILD.bazel‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ ng_module(
3030
"//adev/shared-docs/utils",
3131
"//packages/common",
3232
"//packages/core",
33-
"//packages/core/rxjs-interop",
3433
"//packages/router",
3534
"@npm//algoliasearch",
3635
"@npm//rxjs",
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import {
10+
assertInInjectionContext,
11+
DestroyRef,
12+
effect,
13+
inject,
14+
Injector,
15+
Signal,
16+
untracked,
17+
} from '@angular/core';
18+
import {Observable, ReplaySubject, MonoTypeOperatorFunction, takeUntil} from 'rxjs';
19+
20+
// *******************************
21+
22+
// TODO: Remove the file and revert the commit it belonged to in https://github.com/angular/angular/pull/60234
23+
// Once the next version of core package has been released
24+
25+
// *******************************
26+
27+
/**
28+
* Operator which completes the Observable when the calling context (component, directive, service,
29+
* etc) is destroyed.
30+
*
31+
* @param destroyRef optionally, the `DestroyRef` representing the current context. This can be
32+
* passed explicitly to use `takeUntilDestroyed` outside of an [injection
33+
* context](guide/di/dependency-injection-context). Otherwise, the current `DestroyRef` is injected.
34+
*
35+
* @publicApi
36+
*/
37+
export function takeUntilDestroyed<T>(destroyRef?: DestroyRef): MonoTypeOperatorFunction<T> {
38+
if (!destroyRef) {
39+
assertInInjectionContext(takeUntilDestroyed);
40+
destroyRef = inject(DestroyRef);
41+
}
42+
43+
const destroyed$ = new Observable<void>((observer) => {
44+
const unregisterFn = destroyRef!.onDestroy(observer.next.bind(observer));
45+
return unregisterFn;
46+
});
47+
48+
return <T>(source: Observable<T>) => {
49+
return source.pipe(takeUntil(destroyed$));
50+
};
51+
}
52+
53+
/**
54+
* Options for `toObservable`.
55+
*
56+
* @developerPreview
57+
*/
58+
export interface ToObservableOptions {
59+
/**
60+
* The `Injector` to use when creating the underlying `effect` which watches the signal.
61+
*
62+
* If this isn't specified, the current [injection context](guide/di/dependency-injection-context)
63+
* will be used.
64+
*/
65+
injector?: Injector;
66+
}
67+
68+
/**
69+
* Exposes the value of an Angular `Signal` as an RxJS `Observable`.
70+
*
71+
* The signal's value will be propagated into the `Observable`'s subscribers using an `effect`.
72+
*
73+
* `toObservable` must be called in an injection context unless an injector is provided via options.
74+
*
75+
* @developerPreview
76+
*/
77+
export function toObservable<T>(source: Signal<T>, options?: ToObservableOptions): Observable<T> {
78+
!options?.injector && assertInInjectionContext(toObservable);
79+
const injector = options?.injector ?? inject(Injector);
80+
const subject = new ReplaySubject<T>(1);
81+
82+
const watcher = effect(
83+
() => {
84+
let value: T;
85+
try {
86+
value = source();
87+
} catch (err) {
88+
untracked(() => subject.error(err));
89+
return;
90+
}
91+
untracked(() => subject.next(value));
92+
},
93+
{injector, manualCleanup: true},
94+
);
95+
96+
injector.get(DestroyRef).onDestroy(() => {
97+
watcher.destroy();
98+
subject.complete();
99+
});
100+
101+
return subject.asObservable();
102+
}

‎adev/shared-docs/services/search.service.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import {Injectable, afterNextRender, inject, signal} from '@angular/core';
1010
import {ENVIRONMENT} from '../providers/index';
1111
import {SearchResult} from '../interfaces/index';
12-
import {toObservable} from '@angular/core/rxjs-interop';
1312
import {debounceTime, filter, from, of, switchMap} from 'rxjs';
1413
import {liteClient as algoliasearch} from 'algoliasearch/lite';
1514
import {NavigationEnd, Router} from '@angular/router';
15+
import {toObservable} from './rxjs-interop';
1616

1717
export const SEARCH_DELAY = 200;
1818
// Maximum number of facet values to return for each facet during a regular search.

0 commit comments

Comments
 (0)