Skip to content

Commit

Permalink
feat: implement onNonBranchLink
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 7dc2eff commit 5168de0
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions www.es6/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ var Branch = function() {

};

var disableGlobalListenersWarnings = false;

/**
* Don't emit warnings regarding use of global listeners.
*/
Branch.prototype.disableGlobalListenersWarnings = function() {
disableGlobalListenersWarnings = true;
};
/**
* Initialize the Branch instance.
*
Expand All @@ -71,6 +79,33 @@ Branch.prototype.initSession = function() {

};


var nonBranchLinkListener = null;
function onNonBranchLinkStub(data) {
nonBranchLinkListener(data);
}

/**
* Register listener for non branch links.
*/
Branch.prototype.onNonBranchLink = function(newHook) {
if(!hook) {
throw new Error('non branch link hook is falsy, expected a function, not: "' + hook + '"');
}

var currentHook = window.NonBranchLinkHandler;
if(currentHook !== undefined && currentHook !== onNonBranchLinkStub) {
if(!disableGlobalListenersWarnings) {
console.log('WARNING: you are calling onNonBranchLink when an ' +
'existing global NonBranchLinkHandler is defined. The global ' +
'NonBranchLinkHandler will be overwritten. See https://goo.gl/GijGKP ' +
'for details.');
}
}
nonBranchLinkListener = newHook;
window.NonBranchLinkHandler = onNonBranchLinkStub;
}

/**
* Get Mixpanel tolen/assisstance.
* NOTE: This must be called before initSession
Expand Down

0 comments on commit 5168de0

Please sign in to comment.