Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ async function compileFixture({
pluginVirtual(`export { default } from "${entry}";`, input),
lwcRollupPlugin({
enableDynamicComponents: true,
enableLwcOn: true,
experimentalDynamicComponent: {
loader: path.join(__dirname, './utils/custom-loader.js'),
strictSpecifier: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"entry": "x/lwc-on"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<fixture-test>
<template shadowrootmode="open">
<button>
Button which listens for multiple events
</button>
</template>
</fixture-test>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<button lwc:on={eventListeners}>Button which listens for multiple events</button>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { LightningElement } from 'lwc';

export default class LwcOn extends LightningElement {
eventListeners = {
click: () => {
console.log('click');
},
foo: () => {
console.log('foo');
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ async function getCompiledModule(dirName, compileForSSR) {
strict: true,
},
enableDynamicComponents: true,
enableLwcOn: true,
enableStaticContentOptimization: !DISABLE_STATIC_CONTENT_OPTIMIZATION,
experimentalDynamicDirective: true,
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
props: {},
snapshot(target) {
const div = target.shadowRoot.querySelector('div');

return {
div,
};
},
test(target, snapshots) {
const snapshotAfterHydration = this.snapshot(target);
expect(snapshotAfterHydration.div).toBe(snapshots.div);

// verify handler
snapshotAfterHydration.div.click();
expect(target.timesClickedHandlerIsExecuted).toBe(1);
snapshotAfterHydration.div.dispatchEvent(new CustomEvent('foo'));
expect(target.timesFooHandlerIsExecuted).toBe(1);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div lwc:on={eventListeners}>I listen for events specified in the eventListeners object</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { LightningElement, api } from 'lwc';

export default class Main extends LightningElement {
_clickedHandlerCounter = 0;
_fooHandlerCounter = 0;

@api
get timesClickedHandlerIsExecuted() {
return this._clickedHandlerCounter;
}

@api
get timesFooHandlerIsExecuted() {
return this._fooHandlerCounter;
}

eventListeners = {
click: function () {
this._clickedHandlerCounter++;
},
foo: function () {
this._fooHandlerCounter++;
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ async function compileFixture({ entry, dirname }: { entry: string; dirname: stri
targetSSR: true,
ssrMode: SSR_MODE,
enableDynamicComponents: true,
enableLwcOn: true,
// TODO [#3331]: remove usage of lwc:dynamic in 246
experimentalDynamicDirective: true,
modules: [{ dir: modulesDir }],
Expand Down
1 change: 1 addition & 0 deletions packages/@lwc/ssr-compiler/src/compile-template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default function compileTemplate(
experimentalComputedMemberExpression: options.experimentalComputedMemberExpression,
experimentalComplexExpressions: options.experimentalComplexExpressions,
enableDynamicComponents: options.enableDynamicComponents,
enableLwcOn: options.enableLwcOn,
preserveHtmlComments: options.preserveHtmlComments,
enableStaticContentOptimization: options.enableStaticContentOptimization,
instrumentation: options.instrumentation,
Expand Down