Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(functions): Adding AngularFireFunctions with httpCallable #1532

Merged
merged 10 commits into from
May 16, 2018

Conversation

jamesdaniels
Copy link
Member

Checklist

  • Issue number for this PR: #nnn (required)
  • Docs included?: (yes/no; required for all API/functional changes)
  • Test units included?: (yes/no; required)
  • In a clean directory, yarn install, yarn test run successfully? (yes/no; required)

Description

Code sample

@jamesdaniels
Copy link
Member Author

Copy link
Member

@davideast davideast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @jamesdaniels! Just a few comments about new RxJS import paths and using pipeable operators.


import { FirebaseAppConfig, FirebaseAppName, _firebaseAppFactory, FirebaseZoneScheduler } from 'angularfire2';

import 'rxjs/add/observable/fromPromise';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to use pipeable operators.

const callable = this.functions.httpsCallable(name);
return (data: T) => {
return this.scheduler.runOutsideAngular(
Observable.fromPromise(callable(data))
Copy link
Member

@davideast davideast Mar 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use import { from } from 'rxjs/observable/from';. It also works with promises. Then use the rxjs/operators specifier to import the pipeable operators.

import { from } from 'rxjs/observable/from';
import { map } from 'rxjs/operators';

from(promise).pipe(
  map(() => {})
);

}
}

constructor(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. Bring the constructor above the method above.

import { FirebaseFunctions, HttpsCallableResult } from '@firebase/functions-types';
import { FirebaseOptions } from '@firebase/app-types';
import { Injectable, Inject, Optional, NgZone } from '@angular/core';
import { Observable } from 'rxjs/Observable';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can now just do

import { Observable } from 'rxjs';

return (data: T) => {
return this.scheduler.runOutsideAngular(
Observable.fromPromise(callable(data))
.map(r => r.data as R)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davideast what do you think about mapping .data here? This is the only thing I'm on the fence about. It's nice ergo buuut what if the CF3 team decides to pass more than .data back at some point? That would force an API break.

@jamesdaniels
Copy link
Member Author

Appreciate the review, I'll jump on these after addressing the Firebase SDK stuff.

@jamesdaniels jamesdaniels changed the title WIP Functions feat(functions): Adding AngularFireFunctionsModule with httpCallable May 14, 2018
@jamesdaniels jamesdaniels changed the title feat(functions): Adding AngularFireFunctionsModule with httpCallable feat(functions): Adding AngularFireFunctions with httpCallable May 14, 2018
@jamesdaniels
Copy link
Member Author

@davideast addressed your review and updated against master.

@jamesdaniels jamesdaniels merged commit 26f3f5f into angular:master May 16, 2018
@jamesdaniels jamesdaniels deleted the functions branch May 16, 2018 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants