Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Conversation

@jpzwarte
Copy link
Contributor

@jpzwarte jpzwarte commented Mar 17, 2023

This provides a provideHelper method that you can use in cases where your component is isolated from the parent element that provides the context. Some examples here are unit tests, or in Storybook.

<x-foo @context-request=${provideHelper({ foo: 'Foo', bar: false })}></x-foo>

@jpzwarte jpzwarte requested a review from benjamind as a code owner March 17, 2023 14:36
@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2023

🦋 Changeset detected

Latest commit: cb7aeaa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lit-labs/context Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jpzwarte jpzwarte requested a review from justinfagnani as a code owner March 17, 2023 14:38
@jpzwarte jpzwarte changed the title Add provideHelper for use with isolated components [labs/context] Add provideHelper for use with isolated components Mar 17, 2023
Copy link
Collaborator

@rictic rictic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool, seems very useful for storybook code and other cases where an element that usually has a custom element ancestor is rendered without one.

Please add a few tests

* from the parent that provides the context.
*
* This helper provides static values for the specified contexts. It does
* not support updates via subscribe.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc is missing some important context I think. What actually is this function? How do you use it?

* This helper provides static values for the specified contexts. It does
* not support updates via subscribe.
*/
export const provideHelper = (params: {[key: string]: unknown}) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and elsewhere, the term "helper" is overly generic, like "util" or "meta." This does look like a helpful function, but most good functions are helpful, so naming it a helper doesn't aid the reader in understanding how it's helpful, or in what situations.

Consider a name that communicates more. If I understand this right, I think staticProvideHandler is one candidate. static because it provides a constant value, and handler because it's used as an event handler.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider:

  • providerListener() because they're event listeners, and this is a factory for making listeners that are providers.
  • contextProvider() though it's a little generic compared to other ways of providing, it reads ok at the use site.
  • contextListener() which might seem generic on the provide vs consume side, but only providers actually listen for events, while consumers fire them.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, +1 to listener instead of handler.

Of those, contextProvider is my fave, followed by providerListener. I think provide is so key to what's happening that it needs to be in the name.

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