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

How to provide support for handlebar partials ? #3

Open
imvetri opened this issue Jan 9, 2019 · 11 comments
Open

How to provide support for handlebar partials ? #3

imvetri opened this issue Jan 9, 2019 · 11 comments

Comments

@imvetri
Copy link

imvetri commented Jan 9, 2019

No description provided.

@danakt
Copy link
Owner

danakt commented Jan 16, 2019

@imvetri unfortunately, partials are registered before compiling a template (Handlebars.registerPartial), meanwhile the react (jsx) has no compilation settings directly in the components. Therefore implementation of partials is not expected yet :(

@AndrewLeedham
Copy link
Contributor

AndrewLeedham commented May 2, 2019

@danakt Is this on the roadmap? If so, Wondering if you have an idea for how this would work:

Say we have

// child.handlebars
<div class="child">{{test}}</div>
// parent.handlebars
<div class="parent">
  {{#with context}}
    {{> child }}
  {{/with}}
</div>

The 2 ways I can see this being achieved:

  • Partials would be inlined, e.g:
// parent.jsx
props => <div class="parent"><div class="child">props.context.test</div></div>
  • Partials would simply call out to other files, this would reduce repeated code, but would require isModule and isComponent to be true, there would also need to be some consideration as to how file resolution would work:
// child.jsx
export default props => <div class="child">props.test</div>;
// parent.jsx
import child from './child';
export default props => <div class="parent"><child {...props.context}/></div>;

Happy to help with the implementation of this, thought I would start a discussion for now :)

@AndrewLeedham
Copy link
Contributor

@danakt Any thoughts?

@danakt
Copy link
Owner

danakt commented Jun 22, 2019

Oh! I apologize for not answering for so long.
I have no idea to implement support for partials. This package works with syntax, converting identical constructs, whereas partials refers to functionality, and there are no alternatives for them in jsx. The above example will break the existing mechanisms in the work of the package 😟

@AndrewLeedham
Copy link
Contributor

@danakt I have been revisiting this recently. I think It would be straightforward enough to fork @glimmer/syntax and add mapping for partials and partial blocks etc. However that poses the question of what partials should look like in JSX form. I would have thought the first option from #3 (comment) would be the simplest?

@imvetri
Copy link
Author

imvetri commented Aug 13, 2020

However that poses the question of what partials should look like in JSX form

A partial is a reference to another component, at least when we rewrite it to a react component. The best option would be to modify the path to closely match as its component name or we can pass in a transform function that can rewrite the component name.

Here is an example on how it would look like. On the left is a manually rewritten version of HBR to support partial and this gets compiled successfully using the current version of compile.

image

@AndrewLeedham
Copy link
Contributor

I ended up moving away from handlebars on the project I wanted this for. Looks interesting though 👍

@imvetri
Copy link
Author

imvetri commented Aug 13, 2020

Thanks for your response

@Rykus0
Copy link

Rykus0 commented Oct 12, 2020

I'm new to React components, but I saw there is a children property that could possibly be leveraged for this.

@imvetri
Copy link
Author

imvetri commented Oct 12, 2020

@Rykus0 feel free to tag me if you want to try this out. I'll help as much as I can

@Rykus0
Copy link

Rykus0 commented Oct 12, 2020 via email

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

No branches or pull requests

4 participants