File tree Expand file tree Collapse file tree 7 files changed +49
-2
lines changed
engine-server/src/__tests__/fixtures/wire/ctor-on-adapter-prop
ssr-compiler/src/compile-js/decorators Expand file tree Collapse file tree 7 files changed +49
-2
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "entry" : " x/wire"
3+ }
Original file line number Diff line number Diff line change 1+ < fixture-test >
2+ < template shadowrootmode ="open ">
3+ Wire adapter invoked: true
4+ </ template >
5+ </ fixture-test >
Original file line number Diff line number Diff line change 1+ export let isAdapterInvoked = false ;
2+
3+ class Adapter {
4+ constructor ( dataCallback ) {
5+ this . dc = dataCallback ;
6+ }
7+
8+ connect ( ) { }
9+
10+ update ( ) {
11+ isAdapterInvoked = true ;
12+ this . dc ( true ) ;
13+ }
14+
15+ disconnect ( ) { }
16+ }
17+
18+ const arrowFnWithAdapter = ( ) => { } ;
19+ arrowFnWithAdapter . adapter = Adapter ;
20+
21+ export { arrowFnWithAdapter } ;
Original file line number Diff line number Diff line change 1+ < template >
2+ Wire adapter invoked: {isAdapterInvoked}
3+ </ template >
Original file line number Diff line number Diff line change 1+ import { LightningElement , wire } from 'lwc' ;
2+
3+ import { arrowFnWithAdapter , isAdapterInvoked } from './adapter' ;
4+
5+ export default class Wire extends LightningElement {
6+ @wire ( arrowFnWithAdapter )
7+ wiredProp ;
8+
9+ get isAdapterInvoked ( ) {
10+ return isAdapterInvoked ;
11+ }
12+ }
Original file line number Diff line number Diff line change @@ -190,7 +190,10 @@ const bCallWiredMethod = esTemplate`
190190` < ExpressionStatement > ;
191191
192192const bWireAdapterPlumbing = esTemplate `{
193- const wireInstance = new ${ /*wire adapter constructor*/ is . expression } ((newValue) => {
193+ // Callable adapters are expressed as a function having an 'adapter' property, which
194+ // is the actual wire constructor.
195+ const AdapterCtor = ${ /*wire adapter constructor*/ is . expression } .adapter ?? ${ /*wire adapter constructor*/ 0 } ;
196+ const wireInstance = new AdapterCtor((newValue) => {
194197 ${ /*update the decorated property or call the decorated method*/ is . expressionStatement } ;
195198 });
196199 wireInstance.connect?.();
@@ -203,7 +206,7 @@ const bWireAdapterPlumbing = esTemplate`{
203206 // this preserves the behavior of the browser-side wire implementation as well as the
204207 // original SSR implementation.
205208 wireInstance.update(getLiveConfig(), undefined);
206- __connectContext(${ /*wire adapter constructor*/ 0 } , instance, (newContextValue) => {
209+ __connectContext(AdapterCtor , instance, (newContextValue) => {
207210 wireInstance.update(getLiveConfig(), newContextValue);
208211 });
209212 }
You can’t perform that action at this time.
0 commit comments