Skip to content

Commit c095679

Browse files
crisbetoalxhub
authored andcommitted
fix(core): avoid breaking change with apps using rxjs 6.x (#58341)
The `rxResource` was using `firstValueFrom` which isn't supported in rxjs 6.x. `@angular/core` currently supports rxjs 6 so we need this to be backwards compatible. This came up when trying to deploy the Material docs site which is still on rxjs 6 ([see](https://github.com/angular/components/actions/runs/11487971079/job/31973721563)). PR Close #58341
1 parent aadcfda commit c095679

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

packages/core/rxjs-interop/src/rx_resource.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import {
1313
ResourceLoaderParams,
1414
ResourceRef,
1515
} from '@angular/core';
16-
import {firstValueFrom, Observable, Subject} from 'rxjs';
17-
import {takeUntil} from 'rxjs/operators';
16+
import {Observable, Subject} from 'rxjs';
17+
import {take, takeUntil} from 'rxjs/operators';
1818

1919
/**
2020
* Like `ResourceOptions` but uses an RxJS-based `loader`.
@@ -38,7 +38,19 @@ export function rxResource<T, R>(opts: RxResourceOptions<T, R>): ResourceRef<T>
3838
loader: (params) => {
3939
const cancelled = new Subject<void>();
4040
params.abortSignal.addEventListener('abort', () => cancelled.next());
41-
return firstValueFrom(opts.loader(params).pipe(takeUntil(cancelled)));
41+
42+
// Note: this is identical to `firstValueFrom` which we can't use,
43+
// because at the time of writing, `core` still supports rxjs 6.x.
44+
return new Promise<T>((resolve, reject) => {
45+
opts
46+
.loader(params)
47+
.pipe(take(1), takeUntil(cancelled))
48+
.subscribe({
49+
next: resolve,
50+
error: reject,
51+
complete: () => reject(new Error('Resource completed before producing a value')),
52+
});
53+
});
4254
},
4355
});
4456
}

0 commit comments

Comments
 (0)