Skip to content

Commit

Permalink
Allow synchronous event dispatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelhoral committed Feb 27, 2024
1 parent 882da8b commit e03187e
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 they have 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
$.when.apply($, dependencies).then(function () {
return config.processDescription.apply(this, [event].concat(_.toArray(arguments)));
});
} else {
config.processDescription(event);
}
});
};

Expand Down

0 comments on commit e03187e

Please sign in to comment.