Context#1200
Conversation
|
For consuming, an alternative API could be: on the provider side, you could use: Use case I'm thinking of: For anything that's embedded in a modal, they could react to it (optionally): Of course, the tag-based / template-based
|
|
I sometimes -- perhaps just as often if not more -- want the reverse! The children provide something for the parent. This calls for the "dreaded" (IMO) maybe foo does: This is offtopic! just wanted to say there's an inverse provide/consume relationship that requires boilerplate. |
|
consume can already work in the class, but not as a decorator -- no argument is needed, it's just on Provide using a decorator -- it breaks the "block scope" semantics that we get with the DOM, so I feel it would be too magical, and potentially leaky, to implement that way. on decorators in general, for type safety, it's easier to avoid them since we can't have decorators force a type on their decorated property.
your example from your second comment would be written as: const fooApi = makeContext();
class Foo extends Component {
makeApi = () => {/* ... */};
<template>
<fooApi.Provide @value={{ (this.makeApi) }}>
{{yield}}
</fooApi.Provide />
</template>
}
<template>
<Foo>
{{log (fooApi.consume)}} -- logs whatever makeApi returns
</Foo>
</template> |
|
could it be enhanced to support keyed values? non-keyed could also just work <template>
<fooApi.Provide @key="api" @value={{ (this.makeApi) }}>
<fooApi.Provide @key="theme" @value={{ (this.makeTheme) }}>
{{(ctx.consume 'api')}}
{{(ctx.consume 'theme')}}
</fooApi.Provide />
</fooApi.Provide />
</template>consume would walk up until it find the right provider |
Implementation: emberjs/ember.js#21450
Intent to supersede
Propose Context
Rendered
Summary
This pull request is proposing a new RFC.
To succeed, it will need to pass into the Exploring Stage, followed by the Accepted Stage.
A Proposed or Exploring RFC may also move to the Closed Stage if it is withdrawn by the author or if it is rejected by the Ember team. This requires an "FCP to Close" period.
An FCP is required before merging this PR to advance to Accepted.
Upon merging this PR, automation will open a draft PR for this RFC to move to the Ready for Released Stage.
Exploring Stage Description
This stage is entered when the Ember team believes the concept described in the RFC should be pursued, but the RFC may still need some more work, discussion, answers to open questions, and/or a champion before it can move to the next stage.
An RFC is moved into Exploring with consensus of the relevant teams. The relevant team expects to spend time helping to refine the proposal. The RFC remains a PR and will have an
Exploringlabel applied.An Exploring RFC that is successfully completed can move to Accepted with an FCP is required as in the existing process. It may also be moved to Closed with an FCP.
Accepted Stage Description
To move into the "accepted stage" the RFC must have complete prose and have successfully passed through an "FCP to Accept" period in which the community has weighed in and consensus has been achieved on the direction. The relevant teams believe that the proposal is well-specified and ready for implementation. The RFC has a champion within one of the relevant teams.
If there are unanswered questions, we have outlined them and expect that they will be answered before Ready for Release.
When the RFC is accepted, the PR will be merged, and automation will open a new PR to move the RFC to the Ready for Release stage. That PR should be used to track implementation progress and gain consensus to move to the next stage.
Checklist to move to Exploring
S-Proposedis removed from the PR and the labelS-Exploringis added.Checklist to move to Accepted
Final Comment Periodlabel has been added to start the FCP