Skip to content

Commit

Permalink
Merge pull request #36 from pavelhoral/fix-event-dispatch
Browse files Browse the repository at this point in the history
Allow synchronous event dispatch
  • Loading branch information
pavelhoral authored Feb 27, 2024
2 parents 882da8b + aa2f996 commit a903502
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Upgrade Guide

## 23.0.x -> 23.1.x

* ProcessConfiguration allows defining synchronous event handler when there are no dependencies.
Downstream projects should prefer using synchronous event handlers as the legacy behavior might
be removed in later releases.


## 22.1.x -> 23.x

* Library files no longer contain version number in their name. Adding content hash or version
Expand Down
22 changes: 7 additions & 15 deletions packages/base/src/scripts/config/process/CommonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ define([
"jquery",
"lodash",
"org/forgerock/commons/ui/common/util/Constants",
"org/forgerock/commons/ui/common/main/EventManager"
], function($, _, Constants, EventManager) {
"org/forgerock/commons/ui/common/main/EventManager",
"org/forgerock/commons/ui/common/main/SpinnerManager",
"org/forgerock/commons/ui/common/main/ErrorsHandler"
], function($, _, Constants, EventManager, spinner, errorsHandler) {
var obj = [
{
startEvent: Constants.EVENT_APP_INITIALIZED,
Expand Down Expand Up @@ -158,22 +160,15 @@ define([
{
startEvent: Constants.EVENT_REST_CALL_ERROR,
description: "",
dependencies: [
"org/forgerock/commons/ui/common/main/SpinnerManager",
"org/forgerock/commons/ui/common/main/ErrorsHandler"
],
processDescription: function(event, spinner, errorsHandler) {
processDescription: function(event) {
errorsHandler.handleError(event.data, event.errorsHandlers);
spinner.hideSpinner();
}
},
{
startEvent: Constants.EVENT_START_REST_CALL,
description: "",
dependencies: [
"org/forgerock/commons/ui/common/main/SpinnerManager"
],
processDescription: function(event, spinner) {
processDescription: function(event) {
if (!event.suppressSpinner) {
spinner.showSpinner();
}
Expand All @@ -182,10 +177,7 @@ define([
{
startEvent: Constants.EVENT_END_REST_CALL,
description: "",
dependencies: [
"org/forgerock/commons/ui/common/main/SpinnerManager"
],
processDescription: function(event, spinner) {
processDescription: function() {
spinner.hideSpinner();
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ define([
});

obj.callRegisterListenerFromConfig = function (config) {
var dependencies = _.map(config.dependencies, function (dep) {
return ModuleLoader.load(dep);
});
eventManager.registerListener(config.startEvent, function (event) {
return $.when.apply($, _.map(config.dependencies, function (dep) {
return ModuleLoader.load(dep);
})).then(function () {
return config.processDescription.apply(this, [event].concat(_.toArray(arguments)));
});
if (dependencies.length) {
// legacy async processing
return $.when.apply($, dependencies).then(function () {
return config.processDescription.apply(this, [event].concat(_.toArray(arguments)));
});
} else {
return config.processDescription(event);
}
});
};

Expand Down

0 comments on commit a903502

Please sign in to comment.