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

runOutsideAngular for Universal compatibility and allow advanced configuration with DI #1454

Merged
merged 21 commits into from
Mar 20, 2018

Conversation

jamesdaniels
Copy link
Member

@jamesdaniels jamesdaniels commented Feb 2, 2018

Checklist

Description

Doing some bulldozing in preparation for 5.0 final.

  • Components can now configure their own Firebase apps w/the FirebaseAppConfig and FirebaseAppName Injection Tokens
  • Support storage multi-bucket with the StorageBucket Injection Token
  • Support multi-database with the RealtimeDatabaseURL Injection Token
  • Wrap our observables in NgZone runOutsideAngular to allow operation in Angular Universal
  • Drop some of our bespoke typings in favor of those provided by Firebase now
  • Cleanup

Code sample

Coming soon...

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 really good! My only objection is the removing of the AngularFireModule. It feels a little rough to make users do their own providers and we move away from mirroring the Firebase API.

I also think we need to go carefully through the runOutsideAngular calls. There are sprinkled here and there throughout the code and it would be nice to find a cleaner way of including them. But I don't have a great yet.

import { FirebaseFirestore } from '@firebase/firestore-types';

export const FirebaseAppConfigToken = new InjectionToken<FirebaseAppConfig>('FirebaseAppConfigToken');

Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of removing theAngularFireModule in place of making people do their own providers. I also like having the FirebaseApp as an injectable.

AngularFireAuthModule,
AngularFireDatabaseModule,
AngularFirestoreModule
],
providers: [],
providers: [
Copy link
Member

Choose a reason for hiding this comment

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

Seeing this in action, I feel like it increases the "getting started" complexity. We should continue to mirror the Firebase API rather.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I was thinking this too. I'll bring AngularFireModule back in and allow users to use both whichever fits their use case best. Say in a specific module they need to call out to another app/database/whatnot.

@patrickmichalina
Copy link

Do you intend to bring in a mechanism for Auth between server and client? I currently use cookies in a working project. I didn't see code related to cookies in this branch.

@jamesdaniels
Copy link
Member Author

@patrickmichalina I've been considering this. I don't think I'll tackle in this PR however; just want to get the basics working first + see how adoption goes.

@jamesdaniels
Copy link
Member Author

@davideast yeah I tried to pull all the zone wrapping into a FirebaseZoneScheduler static function but was getting some binding issues all the way down in the minified grpc stuff. Only on the server too, so probably webpack doing something weird. I'll think on a cleaner pattern here BUT it works ;)

jamesdaniels added a commit that referenced this pull request Feb 6, 2018
Added WS and xmlhttprequest as dependencies, as they are required to allow normal functions of the Firebase JS SDK in Universal. Created a new `angularfire/firebase-node` module, which includes these + will include any additional fixes for Universal in the future.

The rest of the SSR work is taking place in #1454.
@jamesdaniels jamesdaniels changed the title (WIP) SSR, providers for config, DI, and cleanup Use NgZone to allow expected operation in Universal and use providers/dependency-injection for configuration Feb 6, 2018
@jamesdaniels jamesdaniels changed the title Use NgZone to allow expected operation in Universal and use providers/dependency-injection for configuration runOutsideAngular for Universal compatibility and allow advanced configuration with DI Feb 6, 2018
@hiepxanh
Copy link
Contributor

hiepxanh commented Feb 6, 2018

thanks for your work, I'm looking to this, what was both of you did so amazing!!! 💯


export const FirebaseAppConfigToken = new InjectionToken<FirebaseAppConfig>('FirebaseAppConfigToken');

export class FirebaseApp implements FBApp {
Copy link
Member

Choose a reason for hiding this comment

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

I would still like for us to provide the FirebaseApp token for DI. It does conflict with the SDK but this would be a breaking change to remove it.

@hiepxanh
Copy link
Contributor

hello sir, is that any experiment api that I can test? I love to do something to help you :)

@jamesdaniels
Copy link
Member Author

jamesdaniels commented Mar 20, 2018

@davideast working example up FYI https://onsnapshot-flex.appspot.com/

curl https://onsnapshot-flex.appspot.com
curl https://onsnapshot-flex.appspot.com/articles/kidpCvq4bYVf5ZYVO24Y

@davideast davideast merged commit e343f13 into master Mar 20, 2018
myspivey pushed a commit to myspivey/angularfire2 that referenced this pull request Apr 10, 2018
Added WS and xmlhttprequest as dependencies, as they are required to allow normal functions of the Firebase JS SDK in Universal. Created a new `angularfire/firebase-node` module, which includes these + will include any additional fixes for Universal in the future.

The rest of the SSR work is taking place in angular#1454.
myspivey pushed a commit to myspivey/angularfire2 that referenced this pull request Apr 10, 2018
…iguration with DI (angular#1454)

* First.

* SSR work

* StorageBucket is a string...

* Add AngularFireModule back in

* Fix up storage and the tests

* Adding StorageBucket and DatabaseURL DI tests

* Adding specs for DI in auth + firestore

* More complete tests + fixed the storage test config

* Adding app.module back in and writing tests for app injection

* Export RealtimeDatabaseURL from database-deprecated

* Export FirebaseApp

* Working, needs wrapper

* More

* State changes and auditlog

* Wrap auth

* Reverted database-depricated a bit

* More cleanup

* Cleanup unused imports
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.

5 participants