-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Move ready queue processing after identity request
- Loading branch information
1 parent
d5f9701
commit 8b5ffb4
Showing
4 changed files
with
54 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { isEmpty, isFunction } from './utils'; | ||
|
||
export const processReadyQueue = (readyQueue): Function[] => { | ||
// debugger; | ||
console.log('processReadyQueue', readyQueue); | ||
if (!isEmpty(readyQueue)) { | ||
readyQueue.forEach(readyQueueItem => { | ||
if (isFunction(readyQueueItem)) { | ||
// debugger; | ||
readyQueueItem(); | ||
} else if (Array.isArray(readyQueueItem)) { | ||
// debugger; | ||
processPreloadedItem(readyQueueItem); | ||
} | ||
}); | ||
} | ||
return []; | ||
}; | ||
|
||
const processPreloadedItem = (readyQueueItem): void => { | ||
// debugger; | ||
const args = readyQueueItem; | ||
const method = args.splice(0, 1)[0]; | ||
|
||
// TODO: We should check to make sure window.mParticle is not undefined | ||
// or possibly add it as an argument in the constructor | ||
// if the first argument is a method on the base mParticle object, run it | ||
if (window.mParticle[args[0]]) { | ||
window.mParticle[method].apply(this, args); | ||
// otherwise, the method is on either eCommerce or Identity objects, ie. "eCommerce.setCurrencyCode", "Identity.login" | ||
} else { | ||
const methodArray = method.split('.'); | ||
try { | ||
var computedMPFunction = window.mParticle; | ||
for (let i = 0; i < methodArray.length; i++) { | ||
const currentMethod = methodArray[i]; | ||
computedMPFunction = computedMPFunction[currentMethod]; | ||
} | ||
((computedMPFunction as unknown) as Function).apply(this, args); | ||
} catch (e) { | ||
throw new Error('Unable to compute proper mParticle function ' + e); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters