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

Custom Element support for child functions and named child functions #708

Closed
matt-gadd opened this issue Mar 30, 2020 · 0 comments · Fixed by #714
Closed

Custom Element support for child functions and named child functions #708

matt-gadd opened this issue Mar 30, 2020 · 0 comments · Fixed by #714
Assignees
Labels
area: core Core next Issue/Pull Request for the next major version

Comments

@matt-gadd
Copy link
Contributor

matt-gadd commented Mar 30, 2020

Enhancement
In Dojo 7 we now have more types of children for widgets, the existing scenario being:

<Foo>
    <Bar />
</Foo>

With the new children functionality we now have the following additional ways to accept children:

Render func:

<Foo>
    { () => <Bar /> }
</Foo>

Named renders:

<Foo>
    {{ 
      bar: <Bar />, 
      qux: <Qux /> 
    }}
</Foo>

Named render funcs:

<Foo>
    {{ 
      bar: () => <Bar />, 
      qux: () => <Qux /> 
    }}
</Foo>

Named render funcs that inject values:

<Foo>
    {{ 
      bar: (active) => <Bar active={ active } />, 
      qux: (active) => <Qux active={ active } /> 
    }}
</Foo>

None of the above are supported with Custom Elements.

Some thoughts on how we could at least add basic support for the first 3:

  • To support basic render functions, we could add a function on top of our VNode and WNode objects, that return them themselves. This would mean we would not need to touch the Custom Element code for this support, as basically any Node can double as a factory safely. This probably also gives the benefit of every child being able to support both RenderResult and () => RenderResult, without any additional work.

  • For the named children. We add an additional property to our Custom Element wrapper that allows the user to specify the child name as a property. This would be similar to slot's for Custom Elements and we might even want to use that name.

An example of the above, for the following widget use in dojo:

<Foo>
    {{ 
      bar: <Bar />, 
      qux: <Qux /> 
    }}
</Foo>

for custom elements it would be:

<dojo-foo>
  <dojo-bar slot="bar" />
  <dojo-qux slot="qux" />
</dojo-foo>

The final scenario ie passing things into a render func, will need further thought as it is not suited to an event handler, and it means that the child nodes will essentially no longer be able to be used declaratively.

@matt-gadd matt-gadd added next Issue/Pull Request for the next major version area: core Core labels Mar 30, 2020
@rorticus rorticus self-assigned this Apr 2, 2020
@rorticus rorticus mentioned this issue Apr 2, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Core next Issue/Pull Request for the next major version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants