本文整理汇总了TypeScript中rxjs/Rx.Observable.map方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.map方法的具体用法?TypeScript Observable.map怎么用?TypeScript Observable.map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Rx.Observable
的用法示例。
在下文中一共展示了Observable.map方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(public store: Store<any[]>) {
this.filteredTodos = Observable.combineLatest(store.select('todos'), store.select('visibility'), (todos: any, visibilityFilter: any) => todos.filter(visibilityFilter.filter));
this.todos = store.select('todos');
this.visibilityFilter = store.select('visibility');
this.completedCount = this.todos.map((todos: any) => todos.reduce((count, todo) => todo.completed ? count + 1 : count, 0));
this.activeCount = this.todos.map((todos: any) => todos.length - (todos.reduce((count, todo) => todo.completed ? count + 1 : count, 0)));
}
示例2: ngOnInit
ngOnInit() {
this.codeList = this.tagList.tags$
.map(tags => tags.map(tag => tag.id))
.switchMap(tagIds => this.codeService.getAllCodes(tagIds));
this.showList = this.codeList.map(codes => codes.length > 0);
this.showEmptyMessage = this.showList.map(showList => !showList);
}
示例3: handleResponse
protected handleResponse(entity: Observable<Response>): Observable<T> {
return entity.map(this.extractData)
.catch((err: any, caught: Observable<T>) => {
if (this.config.handleError) this.config.handleError(err, caught);
return Observable.throw(err);
});
}
示例4: request
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
const tokenPromise: Promise<string> = this._keycloakService.getToken();
const tokenObservable: Observable<string> = Observable.fromPromise(tokenPromise);
if (typeof url === 'string') {
return tokenObservable.map(token => {
const authOptions = new RequestOptions({headers: new Headers({'Authorization': 'Bearer ' + token})});
return new RequestOptions().merge(options).merge(authOptions);
}).concatMap(opts => super.request(url, opts));
} else if (url instanceof Request) {
return tokenObservable.map(token => {
url.headers.set('Authorization', 'Bearer ' + token);
return url;
}).concatMap(request => super.request(request));
}
}
示例5: createRequest
private createRequest(type: string,data ?: Object) : Observable<any> {
let _url : string = this.buildUrl(data);
let _request : Observable<any>
let stringParam : string = '';
let _jsonBuild : any = {}
if(_url.split('?')[1] && _url.split('?')[1].length) {
(_url.split('?')[1].split('&')).forEach( _paramPart => {
_jsonBuild[_paramPart.split('=')[0]] = _paramPart.split('=')[1];
});
stringParam = JSON.stringify(_jsonBuild);
}
switch (type) {
case "post":
_request = this._http.post(_url.split('?')[0], stringParam);
break;
case "patch":
_request = this._http.patch(_url.split('?')[0], stringParam);
break;
case "put":
_request = this._http.put(_url.split('?')[0], stringParam);
break;
case "delete":
_request = this._http.delete(_url);
break;
case "head":
_request = this._http.head(_url);
break;
default:
_request = this._http.get(_url);
break;
}
this._request = _request.map((response: Response) => response.json());
return this._request;
}
示例6:
export function invokeCommand<TObj extends ReactiveObject, TArg, TResult>(source: Observable<TArg>, obj: TObj, command: string | ReactiveCommand<TArg, TResult>): Observable<TResult> {
var commandObservable: Observable<ReactiveCommand<TArg, TResult>>;
var canExecute: Observable<boolean>;
var isExecuting: Observable<boolean>;
if (typeof command === "string") {
// Make sure that the current command is observed
commandObservable = obj.whenSingle(command, true).map(e => e.newPropertyValue);
canExecute = commandObservable.map(c => c.canExecute).switch();
} else {
commandObservable = Observable.of(command);
canExecute = command.canExecute;
}
var results = source
.withLatestFrom(commandObservable, canExecute, (v1, command, canExecute) => {
return {
canExecute,
command,
observedValue: v1
};
})
.filter(o => o.canExecute && o.command != null)
.distinctUntilChanged()
.flatMap(o => {
return o.command.execute(o.observedValue);
});
return results;
}
示例7: ngOnInit
ngOnInit() {
const peopleSignal: Observable<{}> = Observable.create(observer => {
this.addNewPerson = () => observer.next();
}).share();
const startForm = [];
for (let i = 0; i < 10000; i++){
startForm[i] = new Form();
}
this.forms = peopleSignal.map(() => [new Form()])
.startWith(startForm)
.scan((acc: Form[], value) => acc.concat(value));
this.numberOfPeople = this.forms.map(forms => forms.length);
}
示例8: getUserLists
// TODO There has to be a better way.
/**
*
* @returns {Observable<R>}
*/
public getUserLists(): Observable<Observable<FirebaseObjectObservable<any>[]>> {
let userIdObservable: Observable<string> = this.authenticationService.observableUserId;
return userIdObservable.map((uuid) => {
return this.angularFire.database.list('users/' + uuid + '/task_lists').map((taskLists) => {
return taskLists.map((taskList) => {
return this.angularFire.database.object(TASK_LIST_METADATA_PATH + '/' + taskList['$key']);
});
});
});
}
示例9: constructor
constructor(fb: FormBuilder) {
const peopleSignal: Observable<{}> = Observable.create(observer => {
this.addNewPerson = () => observer.next();
});
this.people = peopleSignal.map(() => [new Person()])
.startWith([new Person()])
.scan((acc: Person[], value) => acc.concat(value));
}
示例10: constructor
constructor(
private _http: Http,
private _notes: NotificationsService,
private _trackService: TrackService,
private _configService: ConfigService
) {
// Api base
this._apiBase = _configService._baseApi + 'projects/';
// Local datastore
this._dataStore = {
credits: [],
trackCredits: [],
selectedTrack: undefined
};
// Credits stream
this.credits$ = new Observable(observer => this._creditsObserver = observer).share();
// Update track credits when a new track is selected
this._trackService.selectedTrack$.subscribe(selectedTrack => {
this._dataStore.selectedTrack = selectedTrack;
// Update track credits when a new track is selected
this._creditsObserver.next(this._dataStore.credits);
});
// Track credits stream
this.trackCredits$ = this.credits$.map(credits => this.getTrackCredits(credits));
// Unique credits stream
this.uniqCredits$ = this.credits$.map(credits => this.getUniqueCredits(credits));
// Unused credits stream
this.unusedCredits$ = this.credits$.map(credits => {
let uniq = this.getUniqueCredits(credits);
let trackCreds = this.getTrackCredits(credits);
return uniq.filter(x =>
trackCreds.filter(z => z.partyrealid === x.partyrealid && z.instrumentcode === x.instrumentcode).length === 0);
});
}