Skip to content

Commit

Permalink
fixup! feat: add a rewrite of client angular rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaudAV committed Dec 1, 2020
1 parent 5e6e3d9 commit e81985c
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions app/angular/src/client/preview/angular-beta/app.token.ts
@@ -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();
};
});
}

0 comments on commit e81985c

Please sign in to comment.