skortchmark9 / reselect-tools

Debugging Tools for Reselect
MIT License
426 stars 24 forks source link

Instrument on Demand #20

Closed skortchmark9 closed 5 years ago

skortchmark9 commented 5 years ago

I was hoping to avoid a way to depend on the library for my own application bundle - this seems like it gets us most of the way there. Of course, it requires that you expose your selectors and state on the global object.

(function() {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = "https://unpkg.com/reselect-tools/dist/reselect-tools.js";
    document.head.appendChild(script);

    script.onload = () => {
        ReselectTools.registerSelectors(window.Selectors);
        ReselectTools.getStateWith(() => window.store.getState());
    };
})();