plotly / dash-html-components

OBSOLETE - now part of https://github.com/plotly/dash
https://dash.plotly.com
Other
153 stars 49 forks source link

use a module instead of `html_` namespacing in julia wrapper #162

Open shashi opened 4 years ago

shashi commented 4 years ago

it would be nice to have

module HTML
function h1()... end
function div() ... end
...
end

So that we can use

HTML.h1 instead of html_h1

and potentially users can import the components they want in the beginning so as to not have to qualify it later.

import HTML: h1, div

Can still be done with backwards compatibility by simply defining

const html_div = HTML.div

or deprecating:

Base.@deprecate_binding html_div HTML.div

which will allow removing it in a later release after fair warning.

This is not a deal breaker, so feel free to not do it.

I'm very happy to see a Dashboard library for julia!

alexcjohnson commented 4 years ago

@shashi Just to be clear, you're suggesting that the DashHtmlComponents package would export HTML as a submodule - and eventually it would only export HTML, and not html_div etc? And presumably the ultimate goal from a user perspective is to be able to (with appropriate import/using statements) write div etc with no html_ or HTML. prefix, to make your layouts more compact?

This would make the syntax closer to what we have in Python, with our recommended syntax: import dash_html_components as html -> html.Div(...) as opposed to the current syntax which is closer to what we have in R: library(dashHtmlComponents) -> htmlDiv(...)

To be more complete, I guess with your suggestion if a user wanted shortcut access to div and h1 they'd need two lines:

using DashHtmlComponents
import HTML: h1, div

At which point all the other html components would also be available just inside the submodule, like HTML.p


You'll have to help me if I'm missing or mistaking pieces of Julia's import mechanisms...

On the one hand I like your proposal, as it makes it easier to know what you've added to the scope (just one symbol, HTML, and you can call names(HTML) to see everything inside it). On the other hand, as @waralex pointed out offline, this means if you only want h1 and div in your scope, it's two lines as above. Unless perhaps you can write:

using DashHtmlComponents.HTML: h1, div

My other concern is I don't really want to encourage users to import all of HTML into their global scope via using HTML - h1 and div are probably fine, but all the one-letter tags (a, b, i, p, q, s, and u) and the large number of tags (131 total) make accidental collisions seem likely. In Python you can do from dash_html_components import * to get the same effect but this is generally strongly discouraged.

waralex commented 4 years ago

using DashHtmlComponents.HTML: h1, div

In fact, I checked again - it looks like this form of using is possible. I'm just not sure she looks pretty. And there remains the problem of name conflict. For example, a button can be in multiple component packages. In principle, I can not export functions from the HTML submodule at all, then they will not be added automatically to the global namespace when using

using  DashHtmlComponents.HTML