本文整理汇总了TypeScript中rxjs/Rx.Observable.empty方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.empty方法的具体用法?TypeScript Observable.empty怎么用?TypeScript Observable.empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Rx.Observable
的用法示例。
在下文中一共展示了Observable.empty方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
return observable.catch((err: any): any => {
console.log(err);
if (err.status === 400 || err.status === 401 || err.status === 422) {
console.log("Notifying...");
console.log(err.json());
this.growlMessageService.notifyError(err.json());
return Observable.empty();
}
else {
console.log("Redirecting...");
this.router.navigate(['/error-page']);
return Observable.empty();
}
})
示例2: createLesson
createLesson(name, context){
if(!name || !context){
let empty_observable = Observable.empty();
console.log("no name or no context");
return empty_observable;
}
let lesson_json = {name: name, context: context};
let lesson_str = JSON.stringify(lesson_json);
let headers = new Headers({'Content-Type': 'application/json'});
let options = new RequestOptions({headers: headers})
const network$ = this.http.post('http://cxense.webdemo.dac.co.jp:3000/test/lesson', lesson_json, options)
.cache(1);
/*
ここで、network$は、serviceとcomponentの二ヶ所でsubscribeしているので、
二回PostRequesstが呼ばれてしまう。
cache オペレータを用いると、二度の無駄なPostRequestは実行されず、一回になる。
ただし、Subscribe後に実行されるnextとcompleteは両方ともよばれる。
*/
network$.subscribe(
() =>{console.log("create lesson succeed : service")},
(error) => {console.log("create lesson error" + error)},
()=>{console.log("create lesson complete: service")}
)
return network$;
}
示例3: handleResponse
private handleResponse( res: Response ) {
console.log( "handleResponse: " );
// console.log( "handleResponse: " + res.toString() );
var json = res.json();
// console.log( "jsonResponse: " + JSON.stringify( json ) );
// console.log( "Checking errors" );
if ( json.actionErrors && Object.keys( json.actionErrors ).length > 0 ) {
console.log( "has Errors!!!" );
throw res;
}
// console.log( "Checking login" );
if ( json.responseCode && json.responseCode == "login" ) {
console.log( "Needs login!!!" );
this.router.navigate( ['/login'] );
return Observable.empty();
}
// console.log( "All OK" );
return res;
}
示例4:
.map((params: Params): Observable<PypiPackage[]> => {
const queryPackages = params['packages'];
if (queryPackages) {
return this._packageService.getPackages(queryPackages);
} else {
return Observable.empty();
}
})
示例5:
.catch((err: any): any => {
if (err.status === 400 || err.status === 422) {
return Observable.throw(err);
} else {
//this.errorService.notifyError(err);
return Observable.empty();
}
})
示例6: walkHelper
.concatMap(obj =>
obj.stats.isDirectory()
? (
dirBlacklist.has(obj.name)
? Observable.empty()
: walkHelper(obj.path, dirBlacklist)
)
: Observable.of(obj)
示例7:
return observable.catch((err, source) => {
if (err.status === 401 && !_.endsWith(err.url, '/login')) {
this._router.navigate(['login']);
return Observable.empty(null);
} else {
return Observable.throw(err);
}
});
示例8:
}).catch(err => {
if (err.status == 401) { // Unauthorized i.e. not logged in
console.info('No valid token, redirecting to login', err.json());
} else {
console.error('resume error', err);
}
this.router.navigate(['login']);
return Observable.empty();
}).finally(resolveDone);
示例9: it
it('should mirror source if durations are Observable.empty()', () => {
const e1 = hot('abcdefabcdefabcdefabcdefa|');
const e1subs = '^ !';
const e2 = Rx.Observable.empty();
const expected = 'abcdefabcdefabcdefabcdefa|';
const result = e1.audit(() => e2);
expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
示例10: deleteLesson
deleteLesson(name_arr : string[]){
if(!Array.isArray(name_arr) || name_arr.length == 0){
let empty_observable = Observable.empty();
console.log("no item to delete");
return empty_observable;
}
let delete_lesson_str = JSON.stringify(name_arr);
let headers = new Headers({'Content-Type': 'application/json'});
let options = new RequestOptions({headers: headers});
let req_url = "http://cxense.webdemo.dac.co.jp:3000/test/lesson?name_arr=" + delete_lesson_str;
const network$ = this.http.delete(req_url, options).cache(1);;
network$.subscribe(
() =>{console.log("delete lesson succeed : service")},
(error)=>{console.log("delete lesson error", error)},
()=>{console.log("delete lesson complete: service")}
)
return network$;
}