Skip to content

Commit 4e8b02d

Browse files
GeoriftTim Cochrane
authored and
Tim Cochrane
committed
Fix validation of Observable from different context
Changes the instanceof check for rxjs to a duck-typing isObservable method to fix mistakenly rejecting Observables from other contexts. Window context issue: ReactiveX/rxjs#2628
1 parent 92e21d2 commit 4e8b02d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/angular-cesium/components/ac-layer/ac-layer.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,21 @@ export class AcLayerComponent implements OnInit, OnChanges, AfterContentInit, On
252252
const acForArr = this.acFor.split(' ');
253253
this.observable = this.context[acForArr[3]];
254254
this.entityName = acForArr[1];
255-
if (!this.observable || !(this.observable instanceof Observable)) {
255+
if (!this.isObservable(this.observable)) {
256256
throw new Error('ac-layer: must initailize [acFor] with rx observable, instead received: ' + this.observable);
257257
}
258258

259259
this.layerService.context = this.context;
260260
this.layerService.setEntityName(this.entityName);
261261
}
262262

263+
/** Test for a rxjs Observable */
264+
private isObservable(obj: any): boolean {
265+
/* check via duck-typing rather than instance of
266+
* to allow passing between window contexts */
267+
return obj && typeof obj.subscribe === 'function'
268+
}
269+
263270
ngAfterContentInit(): void {
264271
this.init();
265272
}

0 commit comments

Comments
 (0)