Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split core player from embed script (#2156)
Split the controller and all it's dependencies from the api and it's dependencies. Remove babelrc JW8-106
- Loading branch information
1 parent
5bbbc8f
commit 99914e1
Showing
45 changed files
with
1,281 additions
and
1,104 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,50 @@ | ||
|
||
export default function ApiQueueDecorator(instance, queuedCommands, predicate) { | ||
const commandQueue = []; | ||
const undecoratedMethods = {}; | ||
|
||
queuedCommands.forEach((command) => { | ||
const method = instance[command]; | ||
undecoratedMethods[command] = method; | ||
|
||
instance[command] = function() { | ||
const args = Array.prototype.slice.call(arguments, 0); | ||
|
||
if (predicate()) { | ||
commandQueue.push({ command, args }); | ||
} else { | ||
executeQueuedCommands(); | ||
if (method) { | ||
method.apply(this, args); | ||
} | ||
} | ||
}; | ||
}); | ||
|
||
function executeQueuedCommands() { | ||
while (commandQueue.length > 0) { | ||
const { command, args } = commandQueue.shift(); | ||
(undecoratedMethods[command] || instance[command]).apply(instance, args); | ||
} | ||
} | ||
|
||
Object.defineProperty(this, 'queue', { | ||
enumerable: true, | ||
get: function() { | ||
return commandQueue; | ||
} | ||
}); | ||
|
||
this.flush = executeQueuedCommands; | ||
|
||
this.destroy = function() { | ||
commandQueue.forEach(({ command }) => { | ||
const method = undecoratedMethods[command]; | ||
if (method) { | ||
instance[command] = method; | ||
delete undecoratedMethods[command]; | ||
} | ||
}); | ||
commandQueue.length = 0; | ||
}; | ||
} |
Oops, something went wrong.