Skip to content

Commit

Permalink
fix(radio-group): fix log error in storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
skhamvon authored and dpellier committed Jan 26, 2024
1 parent ae65809 commit 0d54745
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { html } from 'lit-html';
import { unsafeHTML } from 'lit-html/directives/unsafe-html';

import { extractStoryParams, getTagAttributes } from '../../../core/componentHTMLUtils';

const storyParams = {
Expand All @@ -19,20 +18,20 @@ var radioGroupMsgB = document.getElementById("radio-group-msg-b");
function myAsyncAction({checked, value}) {
const max = 1, min = 0, delay = 1000;
logger.log('simulate xhr call...', {checked, value});
console.log('simulate xhr call...', {checked, value});
return new Promise(
(resolve, reject) => {
const isSuccess = Math.floor(Math.random() * (max - min + 1) + min)
if (isSuccess) {setTimeout(() => {logger.log('xhr call success');resolve("backend updated")}, delay)}
else {setTimeout(() => {logger.log('xhr call failed');reject(new Error("backend failed!"))}, delay)}
if (isSuccess) {setTimeout(() => {console.log('xhr call success');resolve("backend updated")}, delay)}
else {setTimeout(() => {console.log('xhr call failed');reject(new Error("backend failed!"))}, delay)}
}
);
}
// optimistic
if(radioGroupA) {
radioGroupA.addEventListener('odsValueChange', (event) => {
logger.log('radioGroupA value change', {detail: event.detail});
console.log('radioGroupA value change', {detail: event.detail});
const {newValue, previousValue} = event.detail;
radioGroupMsgA.innerText = '';
myAsyncAction({value: newValue})
Expand All @@ -47,7 +46,7 @@ if(radioGroupB) {
radioGroupB.save = ({value}) => myAsyncAction({value})
.catch((error) => {radioGroupMsgB.innerText = 'error updating value. try again'; throw error;});
radioGroupB.addEventListener('odsValueChange', (event) => {
logger.log('radioGroupB value change', {detail: event.detail});
console.log('radioGroupB value change', {detail: event.detail});
});
}
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { html } from 'lit-html';
import { unsafeHTML } from 'lit-html/directives/unsafe-html';

import { extractArgTypes, extractStoryParams, getTagAttributes } from '../../../core/componentHTMLUtils';

const slotJs = `
Expand All @@ -12,12 +11,12 @@ const slotJs = `
function myAsyncAction({checked, value}) {
const max = 1, min = 0, delay = 1000;
logger.log('simulate xhr call...', {checked, value});
console.log('simulate xhr call...', {checked, value});
return new Promise(
(resolve, reject) => {
const isSuccess = Math.floor(Math.random() * (max - min + 1) + min)
if (isSuccess) {setTimeout(() => {logger.log('xhr call success');resolve("backend updated")}, delay)}
else {setTimeout(() => {logger.log('xhr call failed');reject(new Error("backend failed!"))}, delay)}
if (isSuccess) {setTimeout(() => {console.log('xhr call success');resolve("backend updated")}, delay)}
else {setTimeout(() => {console.log('xhr call failed');reject(new Error("backend failed!"))}, delay)}
}
);
}
Expand All @@ -29,20 +28,20 @@ const slotJs = `
radio5.save = ({checked, value}) => myAsyncAction({checked, value})
.catch((error) => {radioMsg5.innerText = 'error updating value. try again'; throw error;});
radio5.addEventListener('odsValueChange', (event) => {
logger.log('radio5 value change', {detail: event.detail});
console.log('radio5 value change', {detail: event.detail});
});
radio5.addEventListener('odsCheckedChange', (event) => {
logger.log('radio5 Checked change', {detail: event.detail});
console.log('radio5 Checked change', {detail: event.detail});
});
}
// optimistic
if(radio4) {
radio4.addEventListener('odsValueChange', (event) => {
logger.log('radio4 value change', {detail: event.detail});
console.log('radio4 value change', {detail: event.detail});
});
radio4.addEventListener('odsCheckedChange', (event) => {
logger.log('radio4 Checked change', {detail: event.detail}, 'calling async action...');
console.log('radio4 Checked change', {detail: event.detail}, 'calling async action...');
radioMsg4.innerText = '';
myAsyncAction({checked: event.detail.checked, value: event.detail.value})
.catch(() => {radioMsg4.innerText = 'error updating value. try again';radio4.checked = false})
Expand Down

0 comments on commit 0d54745

Please sign in to comment.