Skip to content

Instantly share code, notes, and snippets.

@barteksekula
Created August 1, 2019 09:10
Show Gist options
  • Save barteksekula/fc5bcdbbd7a18f4f67e31704254a782d to your computer and use it in GitHub Desktop.
Save barteksekula/fc5bcdbbd7a18f4f67e31704254a782d to your computer and use it in GitHub Desktop.
Prevent executing the same command twice
define([
"dojo/_base/declare",
"epi/_Module",
"dojo/when",
"epi-cms/contentediting/command/Publish"
], function (
declare,
_Module,
when,
PublishCommand
) {
return declare([_Module], {
initialize: function () {
var originalExecute = PublishCommand.prototype._execute;
PublishCommand.prototype._execute = function () {
if (this.get("isRunning")) {
return;
}
this.set("isRunning", true);
when(originalExecute.apply(this, arguments)).then(function () {
this.set("isRunning", false);
}.bind(this))
}
}
});
});
<?xml version="1.0" encoding="utf-8"?>
<module clientResourceRelativePath="1.0.0">
<clientModule initializer="my-addon.initializer">
<moduleDependencies>
<add dependency="CMS" type="RunAfter" />
</moduleDependencies>
</clientModule>
<dojo>
<paths>
<add name="my-addon" path="Scripts" />
</paths>
</dojo>
</module>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment