@@ -15,13 +15,28 @@ var fbCallbackManager = null;
1515var GOOGLE_SIGNIN_INTENT_ID = 123 ;
1616var REQUEST_INVITE_INTENT_ID = 48
1717
18- var gson = typeof ( com . google . gson ) === "undefined" ? null : new com . google . gson . Gson ( ) ;
18+ function lazy ( action ) {
19+ var _value ;
20+ var that = this ;
21+
22+ return function ( ) {
23+ return that . _value || ( that . _value = action ( ) ) ;
24+ }
25+ }
26+
27+ var gson = lazy ( function ( ) {
28+ return typeof ( com . google . gson ) === "undefined" ? null : new com . google . gson . Gson ( )
29+ } ) ;
30+
31+ var messagingEnabled = lazy ( function ( ) {
32+ return typeof ( com . google . firebase . messaging ) !== "undefined"
33+ } ) ;
1934
2035( function ( ) {
21- if ( typeof ( com . google . firebase . messaging ) === "undefined" ) {
22- return ;
23- }
2436 appModule . on ( "launch" , function ( args ) {
37+ if ( ! messagingEnabled ( ) ) {
38+ return ;
39+ }
2540
2641 var intent = args . android ;
2742
@@ -110,8 +125,8 @@ firebase.toValue = function(val){
110125} ;
111126
112127firebase . toJsObject = function ( javaObj ) {
113- if ( gson !== null ) {
114- return JSON . parse ( gson . toJson ( javaObj ) ) ;
128+ if ( gson ( ) !== null ) {
129+ return JSON . parse ( gson ( ) . toJson ( javaObj ) ) ;
115130 } else {
116131 // temp fallback for folks not having fetched gson yet in their build for some reason
117132 return firebase . toJsObjectLegacy ( javaObj ) ;
@@ -214,7 +229,7 @@ firebase.init = function (arg) {
214229 }
215230
216231 // Firebase notifications (FCM)
217- if ( typeof ( com . google . firebase . messaging ) !== "undefined" ) {
232+ if ( messagingEnabled ( ) ) {
218233 if ( arg . onMessageReceivedCallback !== undefined ) {
219234 firebase . addOnMessageReceivedCallback ( arg . onMessageReceivedCallback ) ;
220235 }
@@ -2065,4 +2080,4 @@ firebase.invites.getInvitation = function () {
20652080 } ) ;
20662081} ;
20672082
2068- module . exports = firebase ;
2083+ module . exports = firebase ;
0 commit comments