hybridsjs / hybrids

Extraordinary JavaScript UI framework with unique declarative and functional architecture
https://hybrids.js.org
MIT License
3.03k stars 85 forks source link

fix(parent/child): Add host argument to parent and child factories. #188

Closed au-z closed 2 years ago

au-z commented 2 years ago

Hi @smalluban!

Here's a totally unsolicited (but helpful) feature which you might find complementary to the existing parent/children factories...

For some complex components which reference parent and child elements based on element context, access to the host element is helpful. This can be done without a breaking change and creates some options for advanced component interactions.

For example, to get a parent which exposes a particular property name:

const MyChildComponent = define({
  tag: 'my-child-component',
  context: '__ctx__',
  contextProvider: parent((el, {context}) => el.hasOwnProperty(context)),
  // ...
})

Another use case:

const ChildElementCounter = define({
  tag: 'child-element-counter',
  childTag: '',
  children: children((el, {childTag}) => el.tag.toLowerCase() === childTag),
  // ...
})

Have a look and let me know what you think. Thanks! 👍

codesandbox-ci[bot] commented 2 years ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit cd2259dd34db9eb14d7654ee47493a5d847be561:

Sandbox Source
Hybrids web components playground Configuration
coveralls commented 2 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling cd2259dd34db9eb14d7654ee47493a5d847be561 on auzmartist:parent-child-context into 92fc3660c1b0d18205e144bc067dc5d6f56091ac on hybridsjs:master.

au-z commented 2 years ago

Alright, I've added a couple more tests and added to the API docs. Ready for re-review @smalluban. 👍

smalluban commented 2 years ago

Nice work, thanks!