本文整理汇总了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);
};
});
}
示例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;
});
}
示例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;
}
});
});
}
示例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()
);
});
}
示例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;
});
}
示例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);
};
});
}
示例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;
});
}
示例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();
})
);
});
示例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);
};
});
}
示例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);
}
}
示例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);
}
});
});
}
示例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);
}
示例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()
})
}
示例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();
}
});
}
示例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);
}