Skip to content

Commit 0a6c191

Browse files
wire api fix (#5294)
* fix: test for wire invocation order * fix: added wired method invocation test * feat: api + wire test * fix: api/wire invocation order * chore: remove .only * chore: typo and .only
1 parent beecebe commit 0a6c191

File tree

15 files changed

+129
-1
lines changed

15 files changed

+129
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"entry": "x/parent"
3+
}

packages/@lwc/engine-server/src/__tests__/fixtures/wire/invocation-sequence/method/error.txt

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<fixture-test>
2+
<template shadowrootmode="open">
3+
<x-wire>
4+
<template shadowrootmode="open">
5+
<div>
6+
Invocation sequence:
7+
1. component: setApiValue(parent provided (initial) value)
8+
2. adapter: connect()
9+
3. component: getApiValue(parent provided (initial) value)
10+
4. adapter: update()
11+
5. component: wiredMethod(wire provided value)
12+
6. component: setApiValue(wire provided value)
13+
</div>
14+
<div>
15+
Api Value: wire provided value
16+
</div>
17+
</template>
18+
</x-wire>
19+
</template>
20+
</fixture-test>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<x-wire api-value={apiValue}></x-wire>
3+
</template>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { LightningElement } from 'lwc';
2+
3+
export default class Parent extends LightningElement {
4+
apiValue = 'parent provided (initial) value';
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export let invocationSequence = [];
2+
3+
export class adapter {
4+
constructor(dataCallback) {
5+
this.dc = dataCallback;
6+
}
7+
8+
connect() {
9+
invocationSequence.push('adapter: connect()');
10+
}
11+
12+
update() {
13+
invocationSequence.push('adapter: update()');
14+
this.dc('wire provided value');
15+
}
16+
17+
disconnect() {}
18+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<template>
2+
<div>Invocation sequence: {invocationSequence}</div>
3+
<div>Api Value: {apiValue}</div>
4+
</template>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { LightningElement, wire, api } from 'lwc';
2+
3+
import { adapter, invocationSequence } from './adapter';
4+
5+
export default class Wire extends LightningElement {
6+
@api
7+
set apiValue(value) {
8+
invocationSequence.push(`component: setApiValue(${value})`);
9+
this._apiValue = value;
10+
}
11+
12+
get apiValue() {
13+
invocationSequence.push(`component: getApiValue(${this._apiValue})`);
14+
return this._apiValue;
15+
}
16+
17+
@wire(adapter, { apiValue: '$apiValue' })
18+
wiredMethod(value) {
19+
invocationSequence.push(`component: wiredMethod(${value})`);
20+
this.apiValue = value;
21+
}
22+
23+
get invocationSequence() {
24+
return invocationSequence.map((invocation, i) => `\n ${i + 1}. ${invocation}`).join('');
25+
}
26+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"entry": "x/wire"
3+
}

packages/@lwc/engine-server/src/__tests__/fixtures/wire/invocation-sequence/prop/error.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)