Skip to content

Commit

Permalink
Fix callback thrown detection
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Nov 1, 2023
1 parent f4a6a2a commit 1fd04f2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
50 changes: 34 additions & 16 deletions src/renderer/src/stories/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,10 @@ export class Table extends LitElement {
this.col
);
callback(true); // Allow empty value
return true;
return;
}


if (value && k === ogThis.keyColumn && unresolved[this.row]) {
if (value in ogThis.data) {
ogThis.#handleValidationResult(
Expand All @@ -294,13 +295,13 @@ export class Table extends LitElement {
this.col
);
callback(false);
return false;
return;
}
}

if (!(await runThisValidator(value, this.row, this.col))) {
callback(false);
return true;
return;
}

if (!value && isRequired) {
Expand All @@ -310,20 +311,35 @@ export class Table extends LitElement {
this.col
);
callback(false);
return true;
return;
}
};

if (info.validator) {
const og = info.validator;
info.validator = async function (value, callback) {
const called = await validator.call(this, value, callback);
if (!called) og(value, callback);
let wasCalled = false;

const newCallback = (valid) => {
wasCalled = true;
callback(valid);
};

await validator.call(this, value, newCallback);
if (!wasCalled) og(value, callback);
};
} else
info.validator = async function (value, callback) {
const called = await validator.call(this, value, callback);
if (!called) callback(true); // Default to true if not called earlier

let wasCalled = false;

const newCallback = (valid) => {
wasCalled = true;
callback(valid);
};

await validator.call(this, value, newCallback);
if (!wasCalled) callback(true); // Default to true if not called earlier
};

return info;
Expand Down Expand Up @@ -435,14 +451,16 @@ export class Table extends LitElement {

const isUserUpdate = initialCellsToUpdate <= validated;

// Transfer data to object
if (header === this.keyColumn) {
if (value && value !== rowName) {
const old = target[rowName] ?? {};
this.data[value] = old;
delete target[rowName];
delete unresolved[row];
rowHeaders[row] = value;
// Transfer data to object (if valid)
if (isValid){
if (header === this.keyColumn) {
if (value && value !== rowName) {
const old = target[rowName] ?? {};
this.data[value] = old;
delete target[rowName];
delete unresolved[row];
rowHeaders[row] = value;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class GuidedSubjectsPage extends Page {
];
}
} else {
delete parent.sessions; // Delete dessions from parent copy
delete parent.sessions; // Delete sessions from parent copy
return validateOnChange(key, parent, ["Subject"], v);
}
},
Expand Down

0 comments on commit 1fd04f2

Please sign in to comment.