Skip to content

Commit

Permalink
feat: implement onBranchLinkHook parameter to initSession
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-bansil authored and ethanneff committed Nov 16, 2016
1 parent 5168de0 commit 3143dbf
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions www.es6/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,38 @@ var disableGlobalListenersWarnings = false;
Branch.prototype.disableGlobalListenersWarnings = function() {
disableGlobalListenersWarnings = true;
};

var branchLinkListener = null;
function onBranchLinkStub(data) {
branchLinkListener(data);
}

/**
* Initialize the Branch instance.
*
* @param (Function) onBranchLinkHook. listener to trigger on deep links.
* @return (Promise)
*/
Branch.prototype.initSession = function() {
Branch.prototype.initSession = function(onBranchLinkHook) {
if(!onBranchLinkHook && !disableGlobalListenersWarnings) {
console.log('WARNING: branch link hook is not being passed to initSession. ' +
'Falling back to global DeepLinkHandler method. See https://goo.gl/GijGKP for details.');
} else {
var currentHook = window.DeepLinkHandler;
if(currentHook !== undefined && currentHook !== onBranchLinkStub) {
if(!disableGlobalListenersWarnings) {
console.log('WARNING: you are calling initSession with a branch link hook when an ' +
'existing global DeepLinkHandler is defined. The global ' +
'DeepLinkHandler will be overwritten. See https://goo.gl/GijGKP ' +
'for details.');
}
}
if(onBranchLinkHook) {
branchLinkListener = onBranchLinkHook;
window.DeepLinkHandler = onBranchLinkStub;
}
}

return execute('initSession');

};


Expand Down

0 comments on commit 3143dbf

Please sign in to comment.