本文整理汇总了TypeScript中rxjs.Observable.map方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.map方法的具体用法?TypeScript Observable.map怎么用?TypeScript Observable.map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs.Observable
的用法示例。
在下文中一共展示了Observable.map方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(
private ngRedux: NgRedux<IAppState>,
applicationRef: ApplicationRef,
private sessionActions: SessionActions) {
const session$: Observable<Map<string, any>>
= ngRedux.select<Map<string, any>>('session');
this.hasError$ = session$.map(s => !!s.get('hasError'));
this.isLoading$ = session$.map(s => !!s.get('isLoading'));
this.loggedIn$ = session$.map(s => !!s.get('token'));
this.loggedOut$ = this.loggedIn$.map(loggedIn => !loggedIn);
this.userName$ = session$.map(s => {
return [
s.getIn(['user', 'firstName'], ''),
s.getIn(['user', 'lastName'], '')
].join(' ');
});
ngRedux.mapDispatchToTarget((dispatch) => {
return {
login: (credentials) => dispatch(
this.sessionActions.loginUser(credentials)),
logout: () => dispatch(
this.sessionActions.logoutUser())
};
})(this);
this.unsubscribe = ngRedux.subscribe(() => {
applicationRef.tick();
});
}
示例2: constructor
constructor(public store: Store<AppState>) {
this.board$ = store.select(s => s.board);
this.board$.map(b => b.reduce((a, b) => a + b, 0) <= 0)
.subscribe((val) => this.currentPlayer = val);
this.board$.map(checkWinner)
.subscribe((val) => this.winner = val);
}
示例3: ngOnInit
ngOnInit() {
this.route.params
.subscribe((params:Params) => {
if (params['submissionId']) {
this.submissionId = Number(params['submissionId']);
}})
// get the submission
this.submission$ = this.store.select(fromRoot.getAllSubmissions)
.map(s => s.find((i) => i.id === this.submissionId))
// get the assignmentId
this.submission$
.filter(s => typeof s !== 'undefined')
.subscribe(s => this.assignmentId = s.assignment);
// check if the user can edit the submission
this.userCanEdit$ = this.submission$
.map((state:any) => {
if (state) {
if (typeof state.metadata !== 'undefined') {
if (typeof state.metadata.canUpdate !== 'undefined') {
return state.metadata.canUpdate;
}
}
}
return false;
})
// get the submission type
this.submissionType$ = this.submissionService.getSubmissionType(this.submission$);
}
示例4: fetchPages
/**
* Fetch all blog pages (always issues a request & caches the results).
* @returns {Observable<Page>}
*/
fetchPages(): Observable<Page> {
let retVal: Subject<Page> = new ReplaySubject<Page>();
let observable: Observable<Response> = this.http.get(Configuration.applicationUrlWpApi + "/pages?filter[type]=page"); // todo filter the post contents in the WS call (not possible now)
observable.map(
(response: Response) => response.json()
).subscribe(
(pagesJson: any) => {
for (let i = 0; i < pagesJson.length; i++) {
let obj = pagesJson[i];
let page: Page = new Page();
page.id = obj.ID;
page.title = obj.title;
page.content = obj.content; // TODO remove once filtered
retVal.next(page);
}
console.debug(`Found ${pagesJson.length} pages`);
retVal.complete();
}
);
return retVal;
}
示例5: RegExp
export let improveThisCodeResolver = (markdownUrlBase: string, tutorial: TutorialDefinition, patchDetails: ParsedPatchDefinition, filename: string, stepNumber: string, revision: string, http: any) => {
const parentStep = stepNumber.split(".")[0];
const filePath = 'https://github.com/' + tutorial.gitHub + '/edit' + '/' + revision + markdownUrlBase + 'views/step' + parentStep + '.md';
const generatedMd = 'https://raw.githubusercontent.com/' + tutorial.gitHub + '/' + revision + markdownUrlBase + 'views/step' + parentStep + '.md';
let obs: Observable<any>;
if (cache[generatedMd]) {
obs = cache[generatedMd];
}
else {
obs = cache[generatedMd] = http.get(generatedMd).map(res => res.text()).cache(1);
}
return obs.map(generatedMarkdown => {
let lineAppend = '';
try {
const rgx = new RegExp("\\[\\{]: <helper> \\(diffStep " + stepNumber + "\\).*?[\\s\\S]*?(.*?" + filename.replace(".", "\\.") + ".*?)[\\s\\S]*?\\]", "gi");
const match = rgx.exec(generatedMarkdown);
lineAppend = "#L" + (generatedMarkdown.substr(0, match.index).split("\n").length + 6);
}
catch (e) {
lineAppend = '';
}
return {
url: filePath + lineAppend
}
});
};
示例6: Number
.subscribe((params:Params) => {
if (params['submissionId']) {
this.submissionId = Number(params['submissionId']);
// get the submission
this.submission$ = this.store.select('submissions')
.map((state:any) => state.submissions.find((sub:Submission) => {
if (sub.id === this.submissionId) {
this.assignmentId = sub.assignment;
return true;
}
else {
return false;
}
}))
// check if the user can edit the submission
this.userCanEdit$ = this.submission$
.map((state:any) => {
if (state) {
if (typeof state.metadata !== 'undefined') {
if (typeof state.metadata.canUpdate !== 'undefined') {
return state.metadata.canUpdate;
}
}
}
return false;
})
}})
示例7: fetchPosts
/**
* Fetch the most recent blog posts.
* @returns {Rx.Observable<Post>}
*/
fetchPosts(): Observable<Post> {
// example Rx.Observable usage: https://jsbin.com/dosumoqexe/edit?js,console
// reference about subject: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/subjects/subject.md
let retVal:Subject<Post> = new ReplaySubject<Post>();
// TODO configure API calls (posts to retrieve etc)
// needs WP rest api update (currently doesn't allow for partial posts data retrieval)
let observable:Observable<Response> = this.http.get(Configuration.applicationUrlWpApi + "/posts?filter[posts_per_page]=2&withoutcomments");
observable.map(
(response:Response) => response.json()
).subscribe(
(postsJson:any) => {
for (let i = 0 ; i < postsJson.length ; i++) {
let obj = postsJson[i];
let post:Post = new Post();
post.title = obj.title;
post.author = obj.author.nickname;
post.authorUrl = obj.author.URL;
post.content = obj.content;
retVal.next(post);
}
console.debug(`Found ${postsJson.length} posts`);
retVal.complete();
}
);
return retVal;
}
示例8: constructor
constructor(public af: AngularFire) {
let {
auth
} = af;
this.isLoggedIn = auth.map((a)=>!!a);
this.auth = auth.asObservable();
}
示例9: getShoesUrlForId
/**
* Returns the image URL for the ID with the given option if such an option is known
* Or an empty string if there is no option
*/
getShoesUrlForId (id : number) : Observable<string> {
if (!this.shoesCache) {
this.getShoes();
}
return this.shoesCache.map((options : Option[]) => {
return this.getOptionByIdFromArray(options, id);
})
}
示例10: createActionFromFunction
export function createActionFromFunction(fn: Function, type: string, args?: Array<any>, id?: string): Observable<IAction> {
let result: Observable<any> = ensureObservable(fn.apply(this, args));
return result.map(data => {
if (data && data.type) {
return data;
}
return createAction(type, data, id);
});
}