Skip to content

Allow tag selectors in render functions #4016

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

Closed
wants to merge 3 commits into from
Closed

Allow tag selectors in render functions #4016

wants to merge 3 commits into from

Conversation

shreeve
Copy link
Contributor

@shreeve shreeve commented Oct 23, 2016

This allows tags such as section.active.admin@intro, which would yield <section class='active admin' id='intro'>.

Allowing these types of selectors, when used in combination with another tiny enhancement (https://github.com/shreeve/coffeescript/pull/1) to CoffeeScript allows us to write native CoffeeScript that looks a lot like JSX, but is actually full fledged CoffeeScript. Here's an example of something we're working on (a work in progress, but coming along!):

conversation coffee lite 2016-10-22 23-08-41

This allows tags such as 'section.active.admin@intro', which would
yield <section class='active admin' id='intro'>
When checking for undefined components, use 'undefined' instead of a
tag with an empty string, since an empty string will now failover to a
<div> tag. This may sound awkward, but an empty string tag previously
could arguably be considered an error/invalid. By allowing this to
failover to a <div> tag, it makes constructs such as '.active@menu' to
naturally be resolved as <div class="active" id="menu">, etc.
@phanan
Copy link
Member

phanan commented Oct 23, 2016

If I get this right, I don't think this belongs to the core. Maybe a custom render function is what it should be.

@shreeve
Copy link
Contributor Author

shreeve commented Oct 23, 2016

A custom render function would work. Is there a way to have a hook inside of createElement that is able to invoke this code if specified?

@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Oct 23, 2016

Yes you can.

Vue.mixin({
  beforeMount() {
    this.$createElement = customCreateElement
  }
})

Vue.prototype._h = customCreateElement

This should works. The first statement is for render function, the second statement is for compiled template .

POC https://jsfiddle.net/v368d4g3/3/

Caveats: implementation details are liable to change

@shreeve
Copy link
Contributor Author

shreeve commented Oct 24, 2016

Oh, man! That's great.

Is this a one-liner type of tweak that we could put in our top-level app and everything would inherit? That would make it super easy. Is there another library, module, or mixin (or whatever else) that could be used as an example for this type of feature?

@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Oct 24, 2016

Is this a one-liner type of tweak that we could put in our top-level app and everything would inherit?

Yes, if I read the code correct. Place it in your entry file and most things will be fine. (with the probable exception of functional component, functional component behavior is not changed, you can just use your own createdElement function in render function as long as it returns VNode compatible object)

Is there another library, module, or mixin (or whatever else) that could be used as an example for this type of feature?

I don't know. I think this is too hacky to be included in a project's README...

@shreeve
Copy link
Contributor Author

shreeve commented Oct 24, 2016

@phanan - Is there already a way to support such as custom render function as a Vue plugin?

@phanan
Copy link
Member

phanan commented Oct 24, 2016

As it has turned into a discussion, I'd suggest opening a thread on the forum instead.

@phanan phanan closed this Oct 24, 2016
@shreeve shreeve deleted the pr/tag-selectors branch October 27, 2016 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants