Remove manageCover from the managePlayer code

Step 1: Change needed private functions to be public

In the above code, I’ll use the terms private methods and public methods to talk about functions that can’t and can be accessed from outside of the module.

The private methods used by the above functions are show(), createPlayer(), and createCoverClickHandler(). We need to make those private methods public, so that the functions will still work when we move them out.

It is at the end of the managePlayer code where the public methods are managed:

    return {
        add: addPlayer
    };

Currently the add method is the only public method (which uses the private method called addPlayer). We need to add show, createPlayer, and createCoverClickHandler to that list of public methods.

Of the key value pair, where add is the key and addPlayer is the value, looking like add: addPlayer, when both the key and the value are both the same, only the value is needed to be used. That is a property shorthand that helps to avoid annoying createPlayer: createPlayer duplications in the objet properties.

Some people prefer to move out the functions first and use the errors to help inform them about what needs to be done to fix things from there. You though have expressed a desire to avoid errors while doing this work, which means extra overhead and thinking ahead to avoid any potential errors that may occur.

After the public methods have been added for show, createPlayer, and createCoverClickHandler, we need to update those functions so that the public methods are used instead. That should only mean updating function calls in those functions such as show, so that managePlayer.show is used instead.

That is the preparation that needs to be done for Step 1, before Step 2 can be achieved without error.

1 Like