Skip to content

Commit 4ae7f1a

Browse files
fix: doc review
1 parent eed8082 commit 4ae7f1a

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

packages/@lwc/engine-core/README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,15 @@ If `setTrustedSignalSet` is called more than once, it will throw an error. If it
124124

125125
### setContextKeys
126126

127-
Enables a state manager context implementation to provide LWC with context Symbols, namely `connectContext` and `disconnectContext`. These symbols would then be defined on any manager-instantiated context as methods and those methods are called
128-
with a ContextConnector object when contextful components are connected and disconnected.
127+
Not intended for external use. Enables another library to establish contextful relationships via the LWC component tree. The `connectContext` and `disconnectContext` symbols that are provided are later used to identify methods that facilitate the establishment and dissolution of these contextful relationships.
129128

130129
### setTrustedContextSet()
131130

132-
This experimental API enables the addition of context as trusted context. If the [ENABLE_EXPERIMENTAL_SIGNALS](https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#lwcfeatures) feature is enabled
133-
and state manager-defined context has been added to this set, the context object's connectContext and disconnectContext methods will be called with a ContextConnector when the associated component is connected and disconnected.
131+
Not intended for external use. This experimental API enables the addition of context as trusted context. If the [ENABLE_EXPERIMENTAL_SIGNALS](https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#lwcfeatures) feature is enabled.
134132

135133
If `setTrustedContextSet` is called more than once, it will throw an error. If it is never called, then context will not be connected.
136134

137-
### ContextConnector
135+
### ContextBinding
138136

139-
The context object's `connectContext` and `disconnectContext` methods are called with this object when contextful components are connected and disconnected. The ContextConnector exposes `provideContext` and `consumeContext`,
137+
The context object's `connectContext` and `disconnectContext` methods are called with this object when contextful components are connected and disconnected. The ContextBinding exposes `provideContext` and `consumeContext`,
140138
enabling the provision/consumption of a contextful Signal of a specified variety for the associated component.

packages/@lwc/engine-core/src/framework/modules/context.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
ContextEventName,
1414
isTrustedContext,
1515
type ContextProvidedCallback,
16-
type ContextConnector as IContextConnector,
16+
type ContextBinding as IContextBinding,
1717
} from '@lwc/shared';
1818
import { type VM } from '../vm';
1919
import { logWarnOnce } from '../../shared/logger';
@@ -23,7 +23,7 @@ import type { ShouldContinueBubbling } from '../wiring/types';
2323

2424
type ContextVarieties = Map<unknown, Signal<unknown>>;
2525

26-
class ContextConnector<C extends object> implements IContextConnector<C> {
26+
class ContextBinding<C extends object> implements IContextBinding<C> {
2727
component: C;
2828
#renderer: RendererAPI;
2929
#providedContextVarieties: ContextVarieties;
@@ -34,26 +34,23 @@ class ContextConnector<C extends object> implements IContextConnector<C> {
3434
this.#renderer = vm.renderer;
3535
this.#elm = vm.elm;
3636
this.#providedContextVarieties = providedContextVarieties;
37+
38+
// Register the component as a context provider.
39+
this.#renderer.registerContextProvider(
40+
this.#elm,
41+
ContextEventName,
42+
(contextConsumer): ShouldContinueBubbling => {
43+
// This callback is invoked when the provided context is consumed somewhere down
44+
// in the component's subtree.
45+
return contextConsumer.setNewContext(this.#providedContextVarieties);
46+
}
47+
);
3748
}
3849

3950
provideContext<V extends object>(
4051
contextVariety: V,
4152
providedContextSignal: Signal<unknown>
4253
): void {
43-
// registerContextProvider is called one time when the component is first provided context.
44-
// The component is then listening for consumers to consume the provided context.
45-
if (this.#providedContextVarieties.size === 0) {
46-
this.#renderer.registerContextProvider(
47-
this.#elm,
48-
ContextEventName,
49-
(payload): ShouldContinueBubbling => {
50-
// This callback is invoked when the provided context is consumed somewhere down
51-
// in the component's subtree.
52-
return payload.setNewContext(this.#providedContextVarieties);
53-
}
54-
);
55-
}
56-
5754
if (this.#providedContextVarieties.has(contextVariety)) {
5855
logWarnOnce(
5956
'Multiple contexts of the same variety were provided. Only the first context will be used.'
@@ -107,7 +104,7 @@ export function connectContext(vm: VM) {
107104
try {
108105
for (let i = 0; i < contextfulKeys.length; i++) {
109106
(component as any)[contextfulKeys[i]][connectContext](
110-
new ContextConnector(vm, component, providedContextVarieties)
107+
new ContextBinding(vm, component, providedContextVarieties)
111108
);
112109
}
113110
} catch (err: any) {

packages/@lwc/shared/src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type ContextKeys = {
1717

1818
export type ContextProvidedCallback = (contextSignal?: object) => void;
1919

20-
export interface ContextConnector<C extends object> {
20+
export interface ContextBinding<C extends object> {
2121
component: C;
2222

2323
provideContext<V extends object>(contextVariety: V, providedContextSignal: object): void;

0 commit comments

Comments
 (0)