readthedocs-sphinx-search icon indicating copy to clipboard operation
readthedocs-sphinx-search copied to clipboard

Fix namespacing problem

Open dojutsu-user opened this issue 6 years ago • 13 comments

Every function is now under READTHEDOCS object. Users have flexibility to override any of them. (Tested)

dojutsu-user avatar Jul 20 '19 10:07 dojutsu-user

@ericholscher I have updated the minified files. I think we can upload it to pypi after this PR.

dojutsu-user avatar Jul 22 '19 18:07 dojutsu-user

I favor namespacing everything under READTHEDOCS. However, I think we should try to have at least that variable defined before users override it. Otherwise, they might override everything we put in there which is probably not what we want.

davidfischer avatar Jul 22 '19 22:07 davidfischer

@davidfischer can you expand a bit more on this? Is there a change to this PR needed?

ericholscher avatar Jul 26 '19 13:07 ericholscher

Screen Shot 2019-07-26 at 1 39 05 PM

This screenshot illustrates what I'm talking about. If we suggest people define a new READTHEDOCS object:

var READTHEDOCS = {
    getInputField: function() {
        var custom_search_bar = document.querySelector('.my-custom-search-bar');
        return custom_search_bar;    
    }
}

Rather than if the READTHEDOCS object was guaranteed to be present already and they only override the one part they want:

READTHEDOCS.getInputField: function() {
    var custom_search_bar = document.querySelector('.my-custom-search-bar');
    return custom_search_bar;    
}

This could open up a number of issues based on the order JS files are included.

davidfischer avatar Jul 26 '19 20:07 davidfischer

@dojutsu-user Any update here?

ericholscher avatar Aug 19 '19 18:08 ericholscher

@ericholscher Nothing here. I will make all the PRs ready to be merged in master so that they can go out this week.

dojutsu-user avatar Aug 19 '19 18:08 dojutsu-user

I will fix the conflicts and make this mergeable after merging of #42

dojutsu-user avatar Aug 28 '19 11:08 dojutsu-user

@davidfischer I have updated the PR to not include the private methods. but I'm not sure what should be the correct approach for your comment above.

Do you have anything in mind? I do tested this thing and I think that for normal use cases, order of the js files should be correct.

dojutsu-user avatar Aug 28 '19 21:08 dojutsu-user

@stsewd have you looked at this at all?

ericholscher avatar Aug 20 '20 18:08 ericholscher

I'm not sure to understand the use case for this. Also, currently a lot of these functions are in the global scope (and also variables), so they could easily collide with other functions defined by the user or other extensions.

For the example in the docs, allowing to override getInputField to have a custom search input, I think is better to just force the users to make use of the ARIA role [role='search'] input so we can capture it (we can document this).

For other customizations, I think we should provide classes/ids and document them so users can modify them using selectors in js/css. If we have a use case that can't be extended using that, I think we can consider allowing users to override some functionality.

stsewd avatar Aug 20 '20 22:08 stsewd

Also, currently a lot of these functions are in the global scope (and also variables), so they could easily collide with other functions defined by the user or other extensions.

This is exactly the issue. The goal is to nest all the code under the READTHEDOCS namespace to avoid collisions and make it easier to extend.

ericholscher avatar Aug 26 '20 17:08 ericholscher

@humitos Is this solved by our new module approach, I assume?

ericholscher avatar Mar 27 '23 21:03 ericholscher

@humitos Is this solved by our new module approach, I assume?

In the new module, we don't have a global object. All the configs come from the API and cannot be edited, so this is not an issue there. We haven't defined the user API to interact with our extension yet. I have an issue opened to talk about these things and use the best/standard js-y approach we can: https://github.com/readthedocs/readthedocs-client/issues/13

I would appreciate feedback and ideas there 😄

humitos avatar Mar 28 '23 08:03 humitos