bgstaal / multipleWindow3dScene

A quick example of how one can "synchronize" a 3d scene across multiple windows using three.js and localStorage
MIT License
16.44k stars 2.56k forks source link

Function to call another function #9

Open 100backslash001 opened 9 months ago

100backslash001 commented 9 months ago

What is the point of the function windowsUpdated? All the function do is just call another function. It seems like it could be removed from the code.

jaki729 commented 8 months ago

The windowsUpdated function in your code seems redundant as it's merely calling another function, updateNumberOfCubes(), without performing any additional logic. As it stands, removing windowsUpdated and directly calling updateNumberOfCubes() wherever windowsUpdated() is called would likely simplify the code without losing any functionality.

Sometimes, developers create intermediate functions like windowsUpdated for potential future expansion or to maintain a consistent structure across the codebase. However, if it doesn't serve any clear purpose beyond calling another function and there are no plans for extending its functionality in the future, removing it could indeed streamline the code. Always remember to ensure that removing such functions won't impact other parts of the codebase before doing so.

    function setupWindowManager ()
    {
        windowManager = new WindowManager();
        windowManager.setWinShapeChangeCallback(updateWindowShape);
        windowManager.setWinChangeCallback(windowsUpdated);

        // here you can add your custom metadata to each windows instance
        let metaData = {foo: "bar"};

        // this will init the windowmanager and add this window to the centralised pool of windows
        windowManager.init(metaData);

        // call update windows initially (it will later be called by the win change callback)
        windowsUpdated();
    }

    function windowsUpdated ()
    {
        updateNumberOfCubes();
    }
jiangjiang2754 commented 8 months ago

The windowsUpdated function in your code seems redundant as it's merely calling another function, updateNumberOfCubes(), without performing any additional logic. As it stands, removing windowsUpdated and directly calling updateNumberOfCubes() wherever windowsUpdated() is called would likely simplify the code without losing any functionality.

Sometimes, developers create intermediate functions like windowsUpdated for potential future expansion or to maintain a consistent structure across the codebase. However, if it doesn't serve any clear purpose beyond calling another function and there are no plans for extending its functionality in the future, removing it could indeed streamline the code. Always remember to ensure that removing such functions won't impact other parts of the codebase before doing so.

function setupWindowManager ()
{
    windowManager = new WindowManager();
    windowManager.setWinShapeChangeCallback(updateWindowShape);
    windowManager.setWinChangeCallback(windowsUpdated);

    // here you can add your custom metadata to each windows instance
    let metaData = {foo: "bar"};

    // this will init the windowmanager and add this window to the centralised pool of windows
    windowManager.init(metaData);

    // call update windows initially (it will later be called by the win change callback)
    windowsUpdated();
}

function windowsUpdated ()
{
    updateNumberOfCubes();
}