Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support $ as an alias for WidgetCollection #1679

Closed
tbuschto opened this issue Jun 15, 2018 · 2 comments
Closed

Support $ as an alias for WidgetCollection #1679

tbuschto opened this issue Jun 15, 2018 · 2 comments

Comments

@tbuschto
Copy link
Member

tbuschto commented Jun 15, 2018

Problem description

We often need to write JSX like this...

this.append(
  <widgetCollection>
    <textView/>
    <textView/>
    <textView/>
  </widgetCollection>
);

Expected behavior

A shorter alias such as $ would save a lot of characters in the long run.

Bonus: Since WidgetCollection API is already somewhat reminiscent of jQuery, we could put $ in to global scope and provide some more jQuery-like API on it. I'm thinking specifically on something like $(selector), where the selector searches globally through any currently existing widgets.

Environment

any

Code snippet

The result would be:

this.append(
  <$>
    <textView/>
    <textView/>
    <textView/>
  </$>
);

Note:
JSX supports empty element names like this...

this.append(
  <>
    <textView/>
    <textView/>
    <textView/>
  </>
);

... but unfortunately not with custom renderer like we use.

@tbuschto tbuschto added this to the 3.0 milestone Jun 15, 2018
@tbuschto tbuschto changed the title Support $ as an intrinsic element alias for WidgetCollection Support $ as an intrinsic JSX element alias for WidgetCollection Jun 15, 2018
@tbuschto tbuschto changed the title Support $ as an intrinsic JSX element alias for WidgetCollection Support $ as an alias for WidgetCollection Jun 16, 2018
@mpost mpost added the js label Jun 18, 2018
@tbuschto tbuschto added the api label Jun 19, 2018
@tbuschto
Copy link
Member Author

Caveat: This ONLY works if we put $ in global scope, since the character can not be used for intrinsic JSX elements. While I'm for that (as outlined above), we should probably discuss the PROs and CONs of that beforehand. The only library that I found using this is jQuery. While that is fairly popular, it is not very useful in tabris, and it has a no-conflict mode.

@mpost
Copy link
Member

mpost commented Aug 27, 2018

I agree that the current widgetCollection is rather lengthy. Would it be an option to leave out the top level element all together? It would be rather convenient.

@tbuschto tbuschto modified the milestone: 3.0 Nov 19, 2018
review-squirrel pushed a commit that referenced this issue Mar 18, 2019
As it turns out the auto-import of "$" does not always work in Visual
Studio Code, so making it global is the quickest fix for this. As
described on issue #1679 this should not really conflict with any known
libraries.

Change-Id: I177539e5ae2c334e78424394442b5f0b8bc644d6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants