Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Enabled to handle adding/removing fiv-gallery-image dynamically #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions projects/core/src/lib/gallery/gallery.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { Key } from './keycodes.enum';
import { DOCUMENT } from '@angular/common';
import { Navigateable } from '../interfaces';
import { FivGalleryImage } from './gallery-image/gallery-image.component';
import { from, Subject, zip, of } from 'rxjs';
import { from, Subject, zip, of, merge } from 'rxjs';
import { mergeMap, takeUntil, tap } from 'rxjs/operators';
import {
tween,
Expand Down Expand Up @@ -145,6 +145,7 @@ export class FivGallery implements AfterContentInit, OnDestroy, Navigateable {
@Output() backdropChange = new EventEmitter<FivGalleryImage>();

$onDestroy = new Subject();
$onImagesChanged = new Subject<any>();

constructor(
private domCtrl: DomController,
Expand All @@ -160,6 +161,11 @@ export class FivGallery implements AfterContentInit, OnDestroy, Navigateable {
this.updateImagesIndex();
this.setupToolbars();
this.subscribeToImageEvents();
this.images.changes.subscribe(_ => {
this.$onImagesChanged.next();
this.updateImagesIndex();
this.subscribeToImageEvents();
});
}

ngOnDestroy(): void {
Expand All @@ -170,7 +176,7 @@ export class FivGallery implements AfterContentInit, OnDestroy, Navigateable {
from(this.images.map(image => image.click))
.pipe(
mergeMap((value: EventEmitter<FivGalleryImage>) => value),
takeUntil<FivGalleryImage>(this.$onDestroy)
takeUntil<FivGalleryImage>(merge(this.$onDestroy, this.$onImagesChanged))
)
.subscribe(image => {
this.open(image);
Expand Down