From 3143dbf756d90a4feb233843db97a59326e8e834 Mon Sep 17 00:00:00 2001 From: Amit Bansil Date: Thu, 10 Nov 2016 14:35:51 -0500 Subject: [PATCH] feat: implement onBranchLinkHook parameter to initSession --- www.es6/branch.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/www.es6/branch.js b/www.es6/branch.js index ca9e576d..2964d0de 100644 --- a/www.es6/branch.js +++ b/www.es6/branch.js @@ -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'); - };