Adding Const defaultPlayerVars =

The addPlayers code is the last set of code to be investigated. It has a whole lot of things that it uses, including utils, spinner, manageCover, videoPlayer, and addPlayer.

The addPlayers code connects a lot of things together so it’s appropriate for it to reference a lot of things. However, that utils one doesn’t need to be there. It’s more appropriate for the videoPlayer code to take responsibility for showing the player instead.

video-player.js

    function show(videoWrapper) {
        utils.show(videoWrapper);
    }

add-players.js

    function showVideo(cover) {
        const videoWrapper = cover.nextElementSibling;
        videoPlayer.show(videoWrapper);
        videoPlayer.play(videoWrapper);
    }
...
    return {
        ...
        show
    };

The videoPlayer references in the addPlayers code are all suitable too, as the addPlayers code defines default settings for the players, and plays them the when the cover is clicked. Because of that it’s also appropriate for the addPlayers code to reference manageCover.

For the sake of consistency though, because the afterPlayerReady code is a function, I’ll also make the afterAddPlayer code a function too.

    addPlayer.init({
        afterAddPlayer: function (evt) {
            toggleSpinner(evt);
        },
        afterPlayerReady: function (evt) {
            toggleSpinner(evt);
            const cover = evt.detail.cover;
            manageCover.init(cover, showVideo);
        }
    });

The code at https://jsitor.com/1xqkXKIrsv has been updated, and now that the number of interactions between code has been reduced, it will be easier to make further progress with putting together tests for the code.