Merge pull request #3035 from dpalou/MOBILE-3953

MOBILE-3953 siteplugins: Fix override handler properties
main
Noel De Martin 2021-12-22 09:54:19 +01:00 committed by GitHub
commit 2bfa37daf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View File

@ -84,6 +84,7 @@ import { CoreSitePluginsWorkshopAssessmentStrategyHandler } from '../classes/han
import { CoreContentLinksModuleIndexHandler } from '@features/contentlinks/classes/module-index-handler'; import { CoreContentLinksModuleIndexHandler } from '@features/contentlinks/classes/module-index-handler';
import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate';
import { CoreContentLinksModuleListHandler } from '@features/contentlinks/classes/module-list-handler'; import { CoreContentLinksModuleListHandler } from '@features/contentlinks/classes/module-list-handler';
import { CoreObject } from '@singletons/object';
const HANDLER_DISABLED = 'core_site_plugins_helper_handler_disabled'; const HANDLER_DISABLED = 'core_site_plugins_helper_handler_disabled';
@ -615,9 +616,11 @@ export class CoreSitePluginsHelperProvider {
if (result.jsResult) { if (result.jsResult) {
// Override default handler functions with the result of the method JS. // Override default handler functions with the result of the method JS.
const jsResult = <Record<string, unknown>> result.jsResult; const jsResult = <Record<string, unknown>> result.jsResult;
for (const property in handler) { const handlerProperties = CoreObject.getAllPropertyNames(handler);
if (property != 'constructor' && typeof handler[property] == 'function' &&
typeof jsResult[property] == 'function') { for (const property of handlerProperties) {
if (property !== 'constructor' && typeof handler[property] === 'function' &&
typeof jsResult[property] === 'function') {
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
handler[property] = (<Function> jsResult[property]).bind(handler); handler[property] = (<Function> jsResult[property]).bind(handler);
} }

View File

@ -36,6 +36,25 @@ export class CoreObject {
return JSON.stringify(a) === JSON.stringify(b); 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. * Check whether the given object is empty.
* *