Merge pull request #3035 from dpalou/MOBILE-3953
MOBILE-3953 siteplugins: Fix override handler propertiesmain
commit
2bfa37daf6
|
@ -84,6 +84,7 @@ import { CoreSitePluginsWorkshopAssessmentStrategyHandler } from '../classes/han
|
|||
import { CoreContentLinksModuleIndexHandler } from '@features/contentlinks/classes/module-index-handler';
|
||||
import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate';
|
||||
import { CoreContentLinksModuleListHandler } from '@features/contentlinks/classes/module-list-handler';
|
||||
import { CoreObject } from '@singletons/object';
|
||||
|
||||
const HANDLER_DISABLED = 'core_site_plugins_helper_handler_disabled';
|
||||
|
||||
|
@ -615,9 +616,11 @@ export class CoreSitePluginsHelperProvider {
|
|||
if (result.jsResult) {
|
||||
// Override default handler functions with the result of the method JS.
|
||||
const jsResult = <Record<string, unknown>> result.jsResult;
|
||||
for (const property in handler) {
|
||||
if (property != 'constructor' && typeof handler[property] == 'function' &&
|
||||
typeof jsResult[property] == 'function') {
|
||||
const handlerProperties = CoreObject.getAllPropertyNames(handler);
|
||||
|
||||
for (const property of handlerProperties) {
|
||||
if (property !== 'constructor' && typeof handler[property] === 'function' &&
|
||||
typeof jsResult[property] === 'function') {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
handler[property] = (<Function> jsResult[property]).bind(handler);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,25 @@ export class CoreObject {
|
|||
return JSON.stringify(a) === JSON.stringify(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the properties names of an object, including the inherited ones except the ones from Object.prototype.
|
||||
*
|
||||
* @param object Object to get its properties.
|
||||
* @return Set of property names.
|
||||
*/
|
||||
static getAllPropertyNames(object: unknown): Set<string> {
|
||||
if (typeof object !== 'object' || object === null || object === Object.prototype) {
|
||||
// Not an object or we already reached root level.
|
||||
return new Set<string>([]);
|
||||
}
|
||||
|
||||
const properties = CoreObject.getAllPropertyNames(Object.getPrototypeOf(object));
|
||||
|
||||
Object.getOwnPropertyNames(object).forEach(property => properties.add(property));
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given object is empty.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue