Created
October 17, 2018 15:38
-
-
Save lWeRl/9f63115bbd04409f6c252657b2cc0354 to your computer and use it in GitHub Desktop.
rxjs trable
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
// Установка картинок | |
set images(images: ImagePosition[]) { | |
let loadObservables: Observable<ImagePosition>[] = []; | |
images.forEach(image => { | |
// Создаем нативнй элемент для оригинальных размеров картинки. | |
image.nativeImage = new Image(); | |
// Создаем объект подписки на загрузку картинки. | |
let observable = fromEvent(image.nativeImage, "load").pipe(map(() => image)); | |
//todo on error | |
observable.subscribe((image) => this.proceedImage(image)); | |
loadObservables.push(observable); | |
}); | |
// Подписываемся на момент когда все картинки загрузились. Порядок ответов такой же как во входящем массиве. | |
zip(loadObservables).subscribe( (response) => { | |
console.log(response); // <--- не происходит. | |
this.privateImages = response; | |
this.changeDetector.detectChanges(); | |
}); | |
// Запускаем загрузку(картинка все равно закешируется) | |
images.forEach(image => image.nativeImage.src = image.imageUrl); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment