|
1 | 1 | import { |
2 | 2 | ChangeDetectorRef, |
3 | 3 | Directive, |
| 4 | + effect, |
4 | 5 | ErrorHandler, |
5 | 6 | Input, |
| 7 | + isSignal, |
6 | 8 | NgZone, |
7 | 9 | OnChanges, |
8 | 10 | OnDestroy, |
9 | 11 | OnInit, |
10 | 12 | Output, |
| 13 | + Signal, |
11 | 14 | SimpleChanges, |
12 | 15 | TemplateRef, |
13 | 16 | ViewContainerRef, |
@@ -73,10 +76,11 @@ export interface RxLetViewContext<T> extends RxViewContext<T> { |
73 | 76 | * |
74 | 77 | * **Conclusion - Structural directives** |
75 | 78 | * |
76 | | - * In contrast to global change detection, structural directives allow fine-grained control of change detection on a per directive basis. |
77 | | - * The `LetDirective` comes with its own way to handle change detection in templates in a very efficient way. |
78 | | - * However, the change detection behavior is configurable on a per directive or global basis. |
79 | | - * This makes it possible to implement your own strategies, and also provides a migration path from large existing apps running with Angulars default change detection. |
| 79 | + * In contrast to global change detection, structural directives allow fine-grained control of change detection on a |
| 80 | + * per directive basis. The `LetDirective` comes with its own way to handle change detection in templates in a very |
| 81 | + * efficient way. However, the change detection behavior is configurable on a per directive or global basis. This |
| 82 | + * makes it possible to implement your own strategies, and also provides a migration path from large existing apps |
| 83 | + * running with Angulars default change detection. |
80 | 84 | * |
81 | 85 | * This package helps to reduce code used to create composable action streams. |
82 | 86 | * It mostly is used in combination with state management libs to handle user interaction and backend communication. |
@@ -114,13 +118,19 @@ export class LetDirective<U> implements OnInit, OnDestroy, OnChanges { |
114 | 118 | * |
115 | 119 | * @param { ObservableInput<U> | U | null | undefined } rxLet |
116 | 120 | */ |
117 | | - @Input() rxLet: ObservableInput<U> | U | null | undefined; |
| 121 | + @Input() rxLet: |
| 122 | + | ObservableInput<U> |
| 123 | + | Signal<U | null | undefined> |
| 124 | + | U |
| 125 | + | null |
| 126 | + | undefined; |
118 | 127 |
|
119 | 128 | /** |
120 | 129 | * @description |
121 | 130 | * |
122 | 131 | * You can change the used `RenderStrategy` by using the `strategy` input of the `*rxLet`. It accepts |
123 | | - * an `Observable<RxStrategyNames>` or [`RxStrategyNames`](https://github.com/rx-angular/rx-angular/blob/b0630f69017cc1871d093e976006066d5f2005b9/libs/cdk/render-strategies/src/lib/model.ts#L52). |
| 132 | + * an `Observable<RxStrategyNames>` or |
| 133 | + * [`RxStrategyNames`](https://github.com/rx-angular/rx-angular/blob/b0630f69017cc1871d093e976006066d5f2005b9/libs/cdk/render-strategies/src/lib/model.ts#L52). |
124 | 134 | * |
125 | 135 | * The default value for strategy is |
126 | 136 | * [`normal`](https://www.rx-angular.io/docs/template/cdk/render-strategies/strategies/concurrent-strategies). |
@@ -569,7 +579,11 @@ export class LetDirective<U> implements OnInit, OnDestroy, OnChanges { |
569 | 579 | } |
570 | 580 |
|
571 | 581 | if (changes.rxLet) { |
572 | | - this.observablesHandler.next(this.rxLet); |
| 582 | + this.observablesHandler.next( |
| 583 | + typeof this.rxLet === 'function' && isSignal(this.rxLet) |
| 584 | + ? toObservable(this.rxLet) |
| 585 | + : this.rxLet |
| 586 | + ); |
573 | 587 | } |
574 | 588 | } |
575 | 589 |
|
@@ -616,3 +630,14 @@ export class LetDirective<U> implements OnInit, OnDestroy, OnChanges { |
616 | 630 | this.templateManager.nextStrategy(this.strategyHandler.values$); |
617 | 631 | } |
618 | 632 | } |
| 633 | + |
| 634 | +function toObservable<T>(input: Signal<T>): Observable<T> { |
| 635 | + return new Observable<T>((observer) => { |
| 636 | + const _effect = effect(() => { |
| 637 | + observer.next(input()); |
| 638 | + }); |
| 639 | + return () => { |
| 640 | + _effect.destroy(); |
| 641 | + }; |
| 642 | + }); |
| 643 | +} |
0 commit comments