Skip to content

Commit

Permalink
refactor state and config
Browse files Browse the repository at this point in the history
  • Loading branch information
MurhafSousli committed Oct 4, 2018
1 parent 8de515b commit 1e4fd06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions projects/core/src/lib/components/gallery.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { IframeItem, ImageItem, VideoItem, YoutubeItem } from './templates';
changeDetection: ChangeDetectionStrategy.OnPush,
styleUrls: ['../styles/gallery.scss'],
template: `
<gallery-core [state]="galleryRef.state$ | async"
[config]="galleryRef.config$ | async"
<gallery-core [state]="galleryRef.state | async"
[config]="galleryRef.config | async"
(action)="onAction($event)"
(itemClick)="onItemClick($event)"
(thumbClick)="onThumbClick($event)"
Expand Down
18 changes: 9 additions & 9 deletions projects/core/src/lib/services/gallery-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,41 @@ export class GalleryRef {
/** Gallery Events */

/** Stream that emits gallery state */
readonly state$: Observable<GalleryState>;
readonly state: Observable<GalleryState>;

/** Stream that emits gallery config */
readonly config$: Observable<GalleryConfig>;
readonly config: Observable<GalleryConfig>;

/** Stream that emits when gallery is initialized/reset */
get initialized(): Observable<GalleryState> {
return this.state$.pipe(filterActions([GalleryAction.INITIALIZED]));
return this.state.pipe(filterActions([GalleryAction.INITIALIZED]));
}

/** Stream that emits when items is changed (items loaded, item added, item removed) */
get itemsChanged(): Observable<GalleryState> {
return this.state$.pipe(filterActions([GalleryAction.ITEMS_CHANGED]));
return this.state.pipe(filterActions([GalleryAction.ITEMS_CHANGED]));
}

/** Stream that emits when current item is changed */
get indexChanged(): Observable<GalleryState> {
return this.state$.pipe(filterActions([GalleryAction.INDEX_CHANGED]));
return this.state.pipe(filterActions([GalleryAction.INDEX_CHANGED]));
}

/** Stream that emits when the player should start or stop */
get playingChanged(): Observable<GalleryState> {
return this.state$.pipe(filterActions([GalleryAction.PLAY, GalleryAction.STOP]));
return this.state.pipe(filterActions([GalleryAction.PLAY, GalleryAction.STOP]));
}

/** Stream that emits when the player should start or stop */
private get playerActions(): Observable<GalleryState> {
return this.state$.pipe(filterActions([GalleryAction.PLAY, GalleryAction.STOP, GalleryAction.INDEX_CHANGED]));
return this.state.pipe(filterActions([GalleryAction.PLAY, GalleryAction.STOP, GalleryAction.INDEX_CHANGED]));
}

constructor(config: GalleryConfig = defaultConfig, private deleteInstance: Function) {
this._state = new BehaviorSubject<GalleryState>(defaultState);
this._config = new BehaviorSubject<GalleryConfig>(defaultConfig);
this.state$ = this._state.asObservable();
this.config$ = this._config.asObservable();
this.state = this._state.asObservable();
this.config = this._config.asObservable();
this.setConfig(config);
}

Expand Down

0 comments on commit 1e4fd06

Please sign in to comment.