当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Observable.create方法代码示例

本文整理汇总了TypeScript中rxjs/Rx.Observable.create方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.create方法的具体用法?TypeScript Observable.create怎么用?TypeScript Observable.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rxjs/Rx.Observable的用法示例。


在下文中一共展示了Observable.create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

 .flatMap(i => {
     let j1 = Observable.create(s => {
         $.get("http://localhost:8080/double?number=" + (i), d => s.next(d));
     });
     let j2 = Observable.create(s => {
         $.get("http://localhost:8080/double?number=" + (i + 100), d => s.next(d));
     });
     let j3 = Observable.create(s => {
         $.get("http://localhost:8080/double?number=" + (i + 1000000), d => s.next(d));
     });
     return Observable.merge(j1, j2, j3);
 })
开发者ID:romanroe,项目名称:angular2-rx-demo,代码行数:12,代码来源:intro.ts

示例2: count

    /**
     * 
     */
    count(db:IDBDatabase, storeName:string){
        return Observable.create( (observer:Subscriber<any>) => {
            let tnx: IDBTransaction = this.getTransaction(db, storeName, "readonly")
            let store: IDBObjectStore = this.getObjectStore(tnx, storeName)

            let countRequest: IDBRequest = store.count()
            
            let onSuccess = (ev:Event) => {
                this.logEvent("count", ev)
                observer.next(ev.target.result);
                observer.complete()
            }
            
            let onError = (ev:Event) => {
                this.logEvent("count", ev)
                observer.error(ev.target.error)
            }
            
            countRequest.addEventListener(IDB_EVENT_SUCCESS, onSuccess)
            countRequest.addEventListener(IDB_EVENT_ERROR, onError)
            
            return () => {
                countRequest.removeEventListener(IDB_EVENT_SUCCESS, onSuccess)
                countRequest.removeEventListener(IDB_EVENT_ERROR, onError)
            }
                
        })
    }
开发者ID:aheinrich,项目名称:ng2-web-storage,代码行数:31,代码来源:indexeddb.service.ts

示例3: fromEventSource

 export function fromEventSource(source: sse.IEventSourceStatic, event: string, openObserver:rx.Observer<Event> = undefined):rx.Observable<Event> {

    return rx.Observable.create(function (observer:rx.Observer<Event>) {
        function onOpen(e:Event) {
            openObserver.next(e);
            openObserver.complete();
            source.removeEventListener('open', onOpen, false);
        }

        function onError(e:any) {
            source.close();
            if (e.readyState === EventSource.CLOSED) {
                observer.complete();
            } else {
                observer.error(e);
            }
        }

        function onMessage(e:Event) {
            observer.next(e);
        }

        openObserver && source.addEventListener('open', onOpen, false);
        source.addEventListener('error', onError, false);
        source.addEventListener(event, onMessage, false);

        return function () {
            source.removeEventListener('error', onError, false);
            source.removeEventListener(event, onMessage, false);
        };
    });
}
开发者ID:RxHandsOn,项目名称:MarketData,代码行数:32,代码来源:rx-sse.ts

示例4: getPhoto

    public getPhoto(): Observable<string> {
        return Observable.create((observer: Observer<string>) => {
            let removeDomListener = () => {
                document.removeEventListener('deviceready', onCordovaDeviceReady);
            };

            let onCordovaDeviceReady = () => {
                const camera = window.navigator.camera;

                let options = {
                    quality: 50,
                    destinationType: camera.DestinationType.DATA_URL,
                    sourceType: camera.PictureSourceType.CAMERA,
                    encodingType: camera.EncodingType.PNG,
                    saveToPhotoAlbum: false,
                    correctOrientation: true
                };

                camera.getPicture(imageData => {
                    observer.next('data:image/png;base64,' + imageData);
                    removeDomListener();
                    observer.complete();
                }, error => {
                    observer.error(error);
                    removeDomListener();
                    observer.complete();
                }, options);
            };

            document.addEventListener('deviceready', onCordovaDeviceReady);
        });
    }
开发者ID:konstantindenerz,项目名称:boardz-cross-platform-sample,代码行数:32,代码来源:mobileCameraService.ts

示例5: runWorker

    public runWorker(): Observable<string> {
        var self = this;
        
        return Observable.create(observer => {
            observer.next("Starting worker...");

            self.feedTasks()
                .flatMap((task) => self.executeTask(task))
                .map((result: TaskResult) => {
                    console.log("calculated, posting result");
                    console.log(result);
                    return result;
                })
                .flatMap((taskResult) => this.taskService.postTaskResult(taskResult))
                .map((result: boolean) => {
                    console.log("post result: " + result);
                    return result;
                })
                .subscribe(
                    result => {
                        console.log("subscribed result:" + result);
                        self.isBusy = false;
                    },
                    error => {
                        console.log("error while executing task");
                        console.log(error);
                        self.isBusy = false;
                    }
                );
        });
    }
开发者ID:franklycoded,项目名称:Project-Krypton,代码行数:31,代码来源:taskrunner.ts

示例6: getValue

    /**
     * Read and return value from DB, given its key.
     * @param {string} key - the key of the vfalue we're reading
     */
    public getValue(key: string): any {
        let source: Observable<any> = Observable.create((observer) => {
            this.getStore(DICT_STORE, 'readonly').subscribe(
                (store: IDBObjectStore) => {
                    let index: IDBIndex = store.index('key'),
                        keyRange: IDBKeyRange = IDBKeyRange.only(key),
                        cursorRequest: IDBRequest = index.openCursor(keyRange);

                    cursorRequest.onsuccess = (event: ErrorEvent) => {
                        let cursor: IDBCursorWithValue = cursorRequest.result;
                        if (cursor) {
                            observer.next(cursor.value.value);
                            observer.complete();
                            // NB: don't call cursor.continue() because we
                            // expect only one value for key 'key'
                            // cursor.continue();
                        }
                        else {
                            observer.next(undefined);
                            observer.complete();
                        }
                    };
                    cursorRequest.onerror = (event: ErrorEvent) => {
                        observer.error('getValue():getStore(): cursor error');
                    };
                },
                (error) => {
                    observer.error('getValue(): ' + error);
                });
        });
        return source;
    }
开发者ID:zhu04303661,项目名称:ionic-recorder,代码行数:36,代码来源:idb-dict.ts

示例7: open

	open(el: ElementRef, text: string, align: string) {
		return Observable.create((observer: Observer<any>) => {
			// Resolve the TooltipComponent, and build it
			this._cr.resolveComponent(TooltipComponent).then((cmpFactory: ComponentFactory<TooltipComponent>) => {
				// Create reflective injector to provide an instance of TooltipData 
				let providers = ReflectiveInjector.resolve([
					{ provide: TooltipData, useValue: new TooltipData(el, text, align) },
				]);
				let injector = ReflectiveInjector.fromResolvedProviders(providers, this.viewContainer.parentInjector);

				// Create the component, outputs a promise...
				return this.viewContainer.createComponent(cmpFactory, this.viewContainer.length, injector);
			}).then((cmpRef: ComponentRef<TooltipComponent>) => {
				// Store reference to TooltipComponent
				this._toolTipCmp = cmpRef;

				// Append it to DOM
				this.viewContainer.element.nativeElement.appendChild(cmpRef.location.nativeElement);

				// Resolve the component
				observer.next(this._toolTipCmp);
				observer.complete();
			});
		});
	}
开发者ID:cviccaro,项目名称:jpa-admin,代码行数:25,代码来源:provider.ts

示例8: openDB

    /**
     * Open the DB and set it up for use.
     * @returns {Observable<IDBDatabase>} Observable that emits the database
     * when it's ready for use.
     */
    private openDB(config: IdbConfig): Observable<IDBDatabase> {
        let source: Observable<IDBDatabase> = Observable.create((observer) => {
            let openRequest: IDBOpenDBRequest = indexedDB.open(
                config.name, config.version);

            openRequest.onsuccess = (event: Event) => {
                // console.log('indexedDB.open():onsuccess()');
                this.initStoreKeys(config.storeConfigs, openRequest, observer);
            };

            openRequest.onerror = (event: ErrorEvent) => {
                observer.error('openRequest.onerror');
            };

            openRequest.onblocked = (event: ErrorEvent) => {
                observer.error('openRequest.onblocked');
            };

            // This function is called when the database doesn't exist
            openRequest.onupgradeneeded = (event: IDBVersionChangeEvent) => {
                console.log('indexedDB.open():onupgradeended()');
                try {
                    this.createStores(config.storeConfigs, openRequest);
                }
                catch (error) {
                    observer.error('openRequest.onupgradeended: ' + error);
                }
            }; // openRequest.onupgradeneeded = ..
        });
        return source;
    }
开发者ID:zhu04303661,项目名称:ionic-recorder,代码行数:36,代码来源:idb.ts

示例9: handleHighResImageLoad

	private handleHighResImageLoad(fullResImage){
		if (!fullResImage) {
			return;
		}

		const image = new Image();
		image.src = fullResImage;

		if (!image.complete) {
			const onLoadObservable = Observable.create(obs => {
				image.onload = () => {
					obs.next(image);
					obs.complete();
				}
			});

			// We want the animation to finish before replacing the pic
			// as the calculation has been done with the smaller image
			Observable.zip(onLoadObservable, this.didEnter)
				.subscribe(() => this.instance.updateImageSrcWithTransition(fullResImage));

		} else {
			this.instance.updateImageSrc(fullResImage)
		}
	}
开发者ID:pliablepixels,项目名称:ionic-img-viewer,代码行数:25,代码来源:image-viewer-impl.ts

示例10: stop

 /**
  * Stop recording
  * Precondition: called start() already
  * @returns {void}
  */
 public stop(): Observable<RecordingInfo> {
     console.log('WebAudioRecordWav:stop()');
     let obs: Observable<RecordingInfo> = Observable.create((observer) => {
         super.stop().subscribe(
             (recordingInfo: RecordingInfo) => {
                 const lastChunk: Int16Array = this.setter.activeBuffer
                     .subarray(0, this.setter.bufferIndex);
                 this.idb.createChunk(lastChunk).subscribe(
                     (key: number) => {
                         this.dbKeys.push(key);
                         console.log('saved final chunk: ' +
                             this.dbKeys.length + ', key: ' + key);
                         // update some essential components of data
                         // stored in db
                         recordingInfo.encoding = WAV_MIME_TYPE;
                         recordingInfo.size = recordingInfo.nSamples * 2;
                         recordingInfo.dbStartKey = this.dbKeys[0];
                         // reset db-keys, for the next recording
                         this.dbKeys = [];
                         // reset double buffer, for the next recording
                         this.setter.reset();
                         // return result now that db-save is done
                         observer.next(recordingInfo);
                         observer.complete();
                     });
             });
     });
     return obs;
 }
开发者ID:zhu04303661,项目名称:ionic-recorder,代码行数:34,代码来源:record-wav.ts


注:本文中的rxjs/Rx.Observable.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。