Skip to content

Commit

Permalink
polyfill window add, removeEventListener in fastboot for firebase sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
ampatspell committed Jun 5, 2019
1 parent 62392e5 commit cb3d439
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions addon/-private/firebase/initializer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import firebase from 'firebase';
import { resolve } from 'rsvp';
import { isFastBoot } from '../util/fastboot';
import prepare from './prepare';

let _id = 0;

Expand Down Expand Up @@ -32,6 +33,8 @@ export default class FirebaseInitializer {
_prepare() {
let { identifier, id, opts } = this;

prepare(this.sender);

this.app = firebase.initializeApp(opts.firebase, `${identifier}-${id}`);

let firestore = this.app.firestore();
Expand Down
18 changes: 18 additions & 0 deletions addon/-private/firebase/prepare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isFastBoot } from '../util/fastboot';

const noop = () => {};

const workaroundWindowEventListenersInFastBoot = () => {
if(!window.addEventListener) {
window.addEventListener = noop;
}
if(!window.removeEventListener) {
window.removeEventListener = noop;
}
}

export default sender => {
if(isFastBoot(sender)) {
workaroundWindowEventListenersInFastBoot();
}
}

0 comments on commit cb3d439

Please sign in to comment.