Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typeof function check #1074

Merged
merged 1 commit into from
Jan 24, 2024

Conversation

RobAndrewHurst
Copy link
Contributor

TypeOf 'Function' PR Summary 馃摉

Changes Made

This pull request introduces improvements to our codebase by incorporating the typeof check to ensure that certain properties are functions before attempting to execute them in the layer decorate and in the default view's javascript.

  1. Handling Layer and Plugin Methods

    • In the code responsible for handling layer and plugin methods, we have added typeof checks to verify whether the properties are functions before attempting to execute them. This enhancement aims to prevent potential errors when invoking methods that might not be functions.
    Object.keys(layer).forEach((key) => {
            // Check if mapp.layer[key] is a function before executing it
            typeof mapp.layer[key] === 'function' && mapp.layer[key](layer);
    
            // Or plugin method and provide the layer object as an argument.
            typeof mapp.plugins[key] === 'function' && mapp.plugins[key](layer);
    
            // It is possible to have a plugin method of the same name as a layer method.
        }
    });

Motivation

The motivation behind these changes is to enhance the robustness of the code by explicitly checking the types of properties before executing them. By ensuring that methods are functions, we reduce the risk of potential runtime errors in the codebase and other custom views.

@RobAndrewHurst RobAndrewHurst added the Bug A genuine bug. There must be some form of error exception to work with. label Jan 24, 2024
Copy link

sonarcloud bot commented Jan 24, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

@simon-leech simon-leech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one @RobAndrewHurst - looking good to me! 馃帀

Copy link
Member

@dbauszus-glx dbauszus-glx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@dbauszus-glx dbauszus-glx merged commit 62d4532 into GEOLYTIX:main Jan 24, 2024
5 checks passed
@RobAndrewHurst RobAndrewHurst deleted the typeof_function_check branch January 25, 2024 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A genuine bug. There must be some form of error exception to work with.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants