-
-
Notifications
You must be signed in to change notification settings - Fork 335
[factory] Allow to build settings using a custom function #2526
Copy link
Copy link
Open
Labels
type/featAny feature requests or improvementsAny feature requests or improvements
Description
Feature Request
Currently it is not easily possible to patch/override module params/settings.
In atk4/ui we currently override some global defaults like:
const fomanticServicesMap = {
api: apiService,
form: formService,
modal: modalService,
popup: popupService,
accordion: accordionService,
};
$.extend = $.fn.extend = new Proxy($.fn.extend, { // eslint-disable-line no-multi-assign
apply: function (target, thisArg, args) {
// https://github.com/fomantic/Fomantic-UI/blob/c30ed51ca12fc1762b04c2fd1a83d087c0124d07/src/definitions/behaviors/api.js#L48
const firstIndex = args[0] === true ? 1 : 0;
const secondIndex = args[0] === true ? 2 : 1;
if (args.length === (args[0] === true ? 4 : 2)
&& $.isPlainObject(args[firstIndex]) && $.isEmptyObject(args[firstIndex])
&& $.isPlainObject(args[secondIndex])
) {
let name = null;
Object.keys(fomanticServicesMap).forEach((n) => {
if (args[secondIndex] === $.fn[n].settings) {
name = n;
}
});
if (name !== null) {
return fomanticServicesMap[name].buildFomanticSettings(args[firstIndex + 1]);
}
}
return target.call(thisArg, ...args);
},
});
at the app start relying on
| ? $.extend(true, {}, $.fn.api.settings, parameters) |
$.extend({}, $.fn.xxx.settings) usage.
This is a feature request to add function like to each $.fn.xxx:
`$.fn.xxx.createSettings = function (settings, parameters) { return $.extend(true, {}, $.fn.api.settings, parameters); }`
which can be replaced globally much more easier than patching jQuery extend function.
It would be great if module functions/methods would be possible to patch globally as well.
The module like in
| module = { |
$.fn.xxx.createModule = function (module) { return module; }
would allow customization/patching released versions like:
$.fn.modal.createModule = function (element, module) {
module.save.focus = (function () { /* replace completely or tweak slightly and call module.save.focus() here */ }).bind(element);
return module;
}
I am not sure if this is reasonably feasible as all functions need to be called with correct/element's scope (in code above I used element param for it and bind), maybe the module itself can carry these the scope like module.element...
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type/featAny feature requests or improvementsAny feature requests or improvements