當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Observable.map方法代碼示例

本文整理匯總了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();
    });
  }
開發者ID:lokeshjain2008,項目名稱:angular2-redux-starter,代碼行數:33,代碼來源:sample-app.ts

示例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);
    }
開發者ID:vakrilov,項目名稱:ns-ngrx-tic-tac-toe,代碼行數:9,代碼來源:app.component.ts

示例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$);
  }
開發者ID:danielrose28,項目名稱:elmsln,代碼行數:30,代碼來源:submission.component.ts

示例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;
	}
開發者ID:dsebastien,項目名稱:midnightLightV2,代碼行數:29,代碼來源:pages.service.ts

示例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
    }
  });
};
開發者ID:MarcelWaldvogel,項目名稱:angular-meteor-docs,代碼行數:32,代碼來源:improve-code-resolver.ts

示例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;
            })
      }})
開發者ID:heyMP,項目名稱:elmsln,代碼行數:29,代碼來源:submission.component.ts

示例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;
	}
開發者ID:dsebastien,項目名稱:midnightLightV2,代碼行數:33,代碼來源:posts.service.ts

示例8: constructor

 constructor(public af: AngularFire) {
   let {
     auth
   } = af;
   
   this.isLoggedIn = auth.map((a)=>!!a);
   this.auth = auth.asObservable();
 }
開發者ID:bryanerayner,項目名稱:WorldWideBudget,代碼行數:8,代碼來源:account.component.ts

示例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);
   })
 }
開發者ID:nelo112,項目名稱:UnicornMaker,代碼行數:12,代碼來源:option-service.ts

示例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);
  });
}
開發者ID:DcsMarcRemolt,項目名稱:dcs-store,代碼行數:11,代碼來源:utils.ts


注:本文中的rxjs.Observable.map方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。