Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! feat: add a rewrite of client angular rendering
- Loading branch information
Showing
1 changed file
with
25 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
import { InjectionToken, Provider } from '@angular/core'; | ||
import { Subject } from 'rxjs'; | ||
import { InjectionToken, NgZone, Provider } from '@angular/core'; | ||
import { Observable, Subject, Subscriber } from 'rxjs'; | ||
import { ICollection } from '../types'; | ||
|
||
export const STORY_PROPS = new InjectionToken<Subject<ICollection | undefined>>('STORY_PROPS'); | ||
|
||
export const storyPropsProvider = (storyProps$: Subject<ICollection | undefined>): Provider => ({ | ||
provide: STORY_PROPS, | ||
useValue: storyProps$, | ||
useFactory: storyDataFactory(storyProps$.asObservable()), | ||
deps: [NgZone], | ||
}); | ||
|
||
function storyDataFactory<T>(data: Observable<T>) { | ||
return (ngZone: NgZone) => | ||
new Observable((subscriber: Subscriber<T>) => { | ||
const sub = data.subscribe( | ||
(v: T) => { | ||
ngZone.run(() => subscriber.next(v)); | ||
}, | ||
(err) => { | ||
ngZone.run(() => subscriber.error(err)); | ||
}, | ||
() => { | ||
ngZone.run(() => subscriber.complete()); | ||
} | ||
); | ||
|
||
return () => { | ||
sub.unsubscribe(); | ||
}; | ||
}); | ||
} |