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


TypeScript Observable.create方法代码示例

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


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

示例1: firebaseObjectObservableFactory

export function firebaseObjectObservableFactory(ref: firebase.database.Reference): Observable<FirebaseRecord> {
    return Observable.create((subscriber: Subscriber<any>) => {
        let listenFn = ref.on('value', (snap: firebase.database.DataSnapshot) => {
            let value = firebaseRecordFactory(snap);
            subscriber.next(value);
        }, err => {
              if (err) {
                  subscriber.error(err);
                  subscriber.complete();
              }
        });
        return () => {
            ref.off('value', listenFn);
        };
    });
}
开发者ID:nowzoo,项目名称:fb3-ng2,代码行数:16,代码来源:data.service.ts

示例2: randomWalk

  randomWalk(startStep, minChange, maxChange) {
    return Observable.create((observer) => {
      let running = true;
      let step = startStep;
      let next = () => {
        if (running) {
          step += this.nextInt(minChange, maxChange);
          observer.next();
          setTimeout(next, step);
        }
      };
      next();

      return () => running = false;
    });
  }
开发者ID:jitsmaster,项目名称:IgxUserConf2016_Fun,代码行数:16,代码来源:random.service.ts

示例3: loadFormUrl

    loadFormUrl() {
        return Observable.create((observer) => {
            this.http.get('form-url.txt')
    			.map((res) => res.text())
    			.subscribe((data) => {

                    const results = /\/d\/(.*)\//.exec(data);

                    if (results) {
                        const url = results[1];
                        observer.next(url);
                        return;
                    }
    			});
        });
    }
开发者ID:dodishes,项目名称:glenwoodapt12,代码行数:16,代码来源:txt-file-data.service.ts

示例4: salvar

  public salvar(usuario, userType) {
    usuario = JSON.parse(JSON.stringify(usuario));;

    if (userType == 'pf') usuario.empresa = null;
    else usuario.pessoa = null;

    return Observable.create(observer => {
      this.apiService.post('/usuarios', usuario)
        .map(res => res.json())
        .subscribe(
          data => observer.next(true),
          err => observer.next(false),
          () => observer.complete()
        );
    });
  }
开发者ID:eduardorost,项目名称:meutransporte,代码行数:16,代码来源:usuario-service.ts

示例5: constructor

  constructor(public title: string, public createdOn: Date, public items: any[]) {
    this.title = title;
    this.createdOn = createdOn;
    this.items = items;
    this.completed = 0;

    this.items.forEach((item) => {
      if (item.checked) {
        this.completed++;
      }
    });

    this.checklist = Observable.create(observer => {
      this.checklistObserver = observer;
    });
  }
开发者ID:digitaldrummerj,项目名称:ionic2-book-quicklist,代码行数:16,代码来源:checklist-model.ts

示例6: getAllTracktors

  getAllTracktors(): Observable<Tracktor> {
    return Observable.create(observer => {
      let listener = this.tracktorsQuery.on('child_added', snapshot => {
        let data = snapshot.val();
        observer.next(new Tracktor(
          snapshot.key,
          data.hours, 
          data.name
        ));
      }, observer.error);

      return () => {
        this.tracktorsQuery.off('child_added', listener);
      };
    });
  }
开发者ID:carmelneta,项目名称:nirim,代码行数:16,代码来源:user-data.ts

示例7: constrainedRandomWalk

 constrainedRandomWalk(startStep, minStep, maxStep, minChange, maxChange) {
   return Observable.create((observer) => {
     let running = true;
     let step = startStep;
     (async () => {
       while (running) {
         step += this.nextInt(minChange, maxChange);
         step = Math.min(step, maxStep);
         step = Math.max(step, minStep);
         observer.next();
         await this.sleep(step);
       }
     })();
     return () => running = false;
   });
 }
开发者ID:jitsmaster,项目名称:IgxUserConf2016_Fun,代码行数:16,代码来源:random.service.ts

示例8: beforeEach

    beforeEach(function () {
        mockActionService = {
            getActions: function () {}
        };
        formBuilder = new FormBuilder();

        getActionsSpy = spyOn(mockActionService, 'getActions').and.returnValue(
            Observable.create(observer => {
                observer.next([
                        new Action({
                            id: 1, 
                            boardId: 1, 
                            description: "I'm a message", 
                            owner: 'Owner1', 
                            creationDate: "2016-01-01T21:30:00Z",
                            lastModifiedDate: "2016-01-01T21:30:00Z"
                        }),
                        new Action({
                            id: 2, 
                            boardId: 1,
                            description: "I'm another message", 
                            owner: 'ACTIVE', 
                            creationDate: "2016-01-01T21:30:00Z", 
                            lastModifiedDate: "2016-01-01T21:30:00Z"
                        }),
                        new Action({
                            id: 3,
                            boardId: 1,
                            description: "I'm a different message",
                            owner: 'ACTIVE',
                            creationDate: "2016-01-01T21:32:00Z",
                            lastModifiedDate: "2016-01-01T21:32:00Z"
                        }),
                        new Action({
                            id: 4,
                            boardId: 1,
                            description: "I'm a different message",
                            owner: 'ARCHIVED',
                            creationDate: "2016-01-01T21:32:00Z",
                            lastModifiedDate: "2016-01-01T21:32:00Z"
                        })
                    ]
                );
                observer.complete();
            })
        );
    });
开发者ID:PivotalSharedIreland,项目名称:Retrobox-angular,代码行数:47,代码来源:action.component.spec.ts

示例9: getAllFields

  getAllFields(): Observable<Field> {
    return Observable.create(observer => {
      let listener = this.fieldsQuery.on('child_added', snapshot => {
        let data = snapshot.val();
        observer.next(new Field(
          snapshot.key,
          data.name,
          data.prop,
          data.color
        ));
      }, observer.error);

      return () => {
        this.fieldsQuery.off('child_added', listener);
      };
    });
  }
开发者ID:carmelneta,项目名称:nirim,代码行数:17,代码来源:user-data.ts

示例10: getPatient

 getPatient(id: number) : Observable<IPatientReview> {
     if (this.patients) {
         //filter using cached data
         return this.findPatientObservable(id);
     } else {
         //Query the existing Patients to find the target Patient
         return Observable.create((observer: Observer<IPatientReview>) => {
             this.getPatients().subscribe((patients: IPatientReview[]) => {
                 this.patients = patients;
                 const patient = this.filterPatients(id);
                 observer.next(patient);
                 observer.complete();
             })
         })
             .catch(this.handleError);
     }
 }
开发者ID:idotnetsri,项目名称:myh,代码行数:17,代码来源:data.service.ts

示例11: getHttp

 getHttp(uri:string){
     console.log("buildedUIR: "+uri);
     return Observable.create(observer => {
         DZ.api(uri, function(response){
             try {
                 if (response.hasOwnProperty('error')) {
                     console.error(response.error);
                     observer.error(response.error);
                 } else {
                     observer.next(response);
                 }
             } catch (e) {
                 observer.error(e);
             }
         });
     });
 }
开发者ID:NicolasCayet,项目名称:dz-dl,代码行数:17,代码来源:deezer-API.service.ts

示例12: getTrackedStockSymbols

	// returns a list of the tracked stock symbols via FireBase.
	getTrackedStockSymbols() {
		var myFirebaseRef = new Firebase(fireBaseUrl);
		return Observable.create((observer) => {
		    myFirebaseRef.on("value", function (snapshot) {
		    	// want to extract all of the symbols and then put it in the observer.next()
		    	var symbols = [];
		    	// https://www.firebase.com/docs/web/api/datasnapshot/foreach.html
		    	snapshot.forEach(function(childSnapshot){
		    		var trackedStock = childSnapshot.val();
		    		symbols.push(trackedStock.symbol);
		    	})
		        observer.next(symbols);
		    });
		  });
		// var symbols = [] = ["AAPL", "GOOG","NFLX","DIS","TWTR","GPRO"];
		// return Promise.resolve(symbols);
	}
开发者ID:rbarman,项目名称:Fund-Manager,代码行数:18,代码来源:stock.service.ts

示例13: getAds

	public getAds(adIds: string): Observable<any> {
		return Observable.create((observer) => {
			let adIdsArray = lo_.uniq(adIds.split(','))
			const next = () => {
				const adId = parseInt(adIdsArray.shift(), 10)
				if (!adId) {
					adIdsArray.length > 0 && next() || observer.complete()
					return
				}
				this.getAd(adId).subscribe((data) => {
					observer.next(data.result)
					next()
				})
			}
			next()
		})
	}
开发者ID:marsojane,项目名称:sasutil,代码行数:17,代码来源:sas-api-client.service.ts

示例14: getSettings

    getSettings(): Observable<Settings>{
        return Observable.create((observer) => {
            if (this.settings == null) {
                let settings = Settings();
                this.storage.get("settings").then((data) => {
                    settings.load(data);
                    this.settings = settings;
                    observer.onNext(this.settings);
                    observer.onComplete();
                })
            } else {
                observer.onNext(this.settings);
                observer.onComplete();
            }

        });
    }
开发者ID:ornoone,项目名称:t411ToTransmissions,代码行数:17,代码来源:settings.services.ts

示例15: getPreview

  public getPreview(id: Guid, revision: number): Observable<QuestionnairePreview> {
    if (!this.previews) {
      return Observable.create((o: Observer<QuestionnairePreview>) => {
        this.getPreviews().subscribe(previews => {
          this.getPreview(id, revision).subscribe(p => o.next(p));
        });
      });
    }

    let preview: QuestionnairePreview = null;
    this.previews.forEach(_ => {
      if (_.id === id && _.revision === revision) {
        preview = _;
      }
    });
    return Observable.of(preview);
  }
开发者ID:BinaryTENSHi,项目名称:qv-abu,代码行数:17,代码来源:questionnaires.service.ts


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