Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(engine): improve createElement() second parameter error messages #944

Merged
merged 2 commits into from
Jan 14, 2019

Conversation

apapko
Copy link
Collaborator

@apapko apapko commented Jan 11, 2019

Details

Improve createElement second parameter validation. Fixes #940

Does this PR introduce a breaking change?

  • Yes
  • No

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 26b1baf | Target commit: 9638669

lwc-engine-benchmark

table-append-1k metric base(26b1baf) target(9638669) trend
benchmark-table/append/1k duration 148.50 (±3.55 ms) 153.05 (±4.85 ms) +4.6ms (3.1%) 👎
table-clear-1k metric base(26b1baf) target(9638669) trend
benchmark-table/clear/1k duration 5.80 (±0.40 ms) 5.85 (±0.35 ms) +0.0ms (0.9%) 👌
table-create-10k metric base(26b1baf) target(9638669) trend
benchmark-table/create/10k duration 872.30 (±6.50 ms) 857.95 (±6.90 ms) -14.3ms (1.6%) 👍
table-create-1k metric base(26b1baf) target(9638669) trend
benchmark-table/create/1k duration 118.35 (±3.15 ms) 116.65 (±3.85 ms) -1.7ms (1.4%) 👌
table-update-10th-1k metric base(26b1baf) target(9638669) trend
benchmark-table/update-10th/1k duration 74.60 (±1.55 ms) 84.60 (±4.60 ms) +10.0ms (13.4%) 👎
tablecmp-append-1k metric base(26b1baf) target(9638669) trend
benchmark-table-component/append/1k duration 235.70 (±16.30 ms) 216.90 (±9.10 ms) -18.8ms (8.0%) 👍
tablecmp-clear-1k metric base(26b1baf) target(9638669) trend
benchmark-table-component/clear/1k duration 11.75 (±1.70 ms) 11.40 (±1.40 ms) -0.3ms (3.0%) 👌
tablecmp-create-10k metric base(26b1baf) target(9638669) trend
benchmark-table-component/create/10k duration 1696.40 (±13.25 ms) 1724.35 (±21.35 ms) +27.9ms (1.6%) 👎
tablecmp-create-1k metric base(26b1baf) target(9638669) trend
benchmark-table-component/create/1k duration 215.10 (±4.50 ms) 206.25 (±5.00 ms) -8.8ms (4.1%) 👍
tablecmp-update-10th-1k metric base(26b1baf) target(9638669) trend
benchmark-table-component/update-10th/1k duration 67.05 (±5.80 ms) 68.50 (±4.60 ms) +1.5ms (2.2%) 👌
wc-append-1k metric base(26b1baf) target(9638669) trend
benchmark-table-wc/append/1k duration 253.90 (±4.55 ms) 251.55 (±6.80 ms) -2.3ms (0.9%) 👌
wc-clear-1k metric base(26b1baf) target(9638669) trend
benchmark-table-wc/clear/1k duration 21.35 (±1.90 ms) 20.50 (±2.50 ms) -0.9ms (4.0%) 👌
wc-create-10k metric base(26b1baf) target(9638669) trend
benchmark-table-wc/create/10k duration 1931.90 (±22.80 ms) 1904.90 (±30.60 ms) -27.0ms (1.4%) 👍
wc-create-1k metric base(26b1baf) target(9638669) trend
benchmark-table-wc/create/1k duration 218.30 (±3.60 ms) 220.10 (±5.95 ms) +1.8ms (0.8%) 👎
wc-update-10th-1k metric base(26b1baf) target(9638669) trend
benchmark-table-wc/update-10th/1k duration 73.05 (±5.15 ms) 70.25 (±6.60 ms) -2.8ms (3.8%) 👌

if (!isObject(options) || isNull(options)) {
throw new TypeError();
throw new TypeError(`"createElement" function was invoked with invalid second parameter "${options}". Expected an object that contains property "is" mapped to an object that extends LightningElement from "lwc".`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have to call ${toString(options)} in case the argument can't be transformed into a string.


if (isNull(Ctor) || isUndefined(Ctor)) {
throw new TypeError(
`"createElement" function was invoked with invalid second parameter. "is" property value was "${Ctor}", but expected an object that extends LightningElement from "lwc". ` +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toString on the Ctor

if (!isObject(options) || isNull(options)) {
throw new TypeError();
throw new TypeError(`"createElement" function was invoked with invalid second parameter "${options}". Expected an object that contains property "is" mapped to an object that extends LightningElement from "lwc".`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the first error message minimal and focussed. Something like sound be enough:

"createElement" expects an object as second parameter.

If we were to add another required parameters to createElement we would need to update both error messages with the error messages you proposed.


if (isNull(Ctor) || isUndefined(Ctor)) {
throw new TypeError(
`"createElement" function was invoked with invalid second parameter. "is" property value was "${Ctor}", but expected an object that extends LightningElement from "lwc". ` +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error is inaccurate here: You probably forgot to add the extend clause on the class declaration.. We are only checking if the is property is not null or undefined.

Since we are validating if the is value in getComponentDef, we should only warn if the Ctor is from the wrong type.

}

let Ctor = (options as any).is as ComponentConstructor;

if (isNull(Ctor) || isUndefined(Ctor)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking if the function is null or undefined, I would rather check if the Ctor is a function.

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 19953e1 | Target commit: f598b72

lwc-engine-benchmark

table-append-1k metric base(19953e1) target(f598b72) trend
benchmark-table/append/1k duration 148.50 (±4.05 ms) 148.85 (±4.40 ms) +0.4ms (0.2%) 👌
table-clear-1k metric base(19953e1) target(f598b72) trend
benchmark-table/clear/1k duration 6.30 (±0.30 ms) 5.90 (±0.40 ms) -0.4ms (6.3%) 👍
table-create-10k metric base(19953e1) target(f598b72) trend
benchmark-table/create/10k duration 874.55 (±6.90 ms) 861.15 (±7.40 ms) -13.4ms (1.5%) 👍
table-create-1k metric base(19953e1) target(f598b72) trend
benchmark-table/create/1k duration 118.65 (±3.35 ms) 120.05 (±2.90 ms) +1.4ms (1.2%) 👌
table-update-10th-1k metric base(19953e1) target(f598b72) trend
benchmark-table/update-10th/1k duration 75.95 (±2.05 ms) 75.40 (±2.45 ms) -0.5ms (0.7%) 👌
tablecmp-append-1k metric base(19953e1) target(f598b72) trend
benchmark-table-component/append/1k duration 240.80 (±14.45 ms) 252.55 (±6.90 ms) +11.8ms (4.9%) 👎
tablecmp-clear-1k metric base(19953e1) target(f598b72) trend
benchmark-table-component/clear/1k duration 11.80 (±1.55 ms) 11.80 (±1.60 ms) 0.0ms (0.0%) 👌
tablecmp-create-10k metric base(19953e1) target(f598b72) trend
benchmark-table-component/create/10k duration 1729.45 (±16.45 ms) 1750.40 (±22.40 ms) +21.0ms (1.2%) 👎
tablecmp-create-1k metric base(19953e1) target(f598b72) trend
benchmark-table-component/create/1k duration 210.80 (±5.35 ms) 213.20 (±6.70 ms) +2.4ms (1.1%) 👌
tablecmp-update-10th-1k metric base(19953e1) target(f598b72) trend
benchmark-table-component/update-10th/1k duration 70.85 (±6.35 ms) 69.80 (±4.55 ms) -1.0ms (1.5%) 👌
wc-append-1k metric base(19953e1) target(f598b72) trend
benchmark-table-wc/append/1k duration 254.80 (±5.05 ms) 254.75 (±5.95 ms) -0.1ms (0.0%) 👌
wc-clear-1k metric base(19953e1) target(f598b72) trend
benchmark-table-wc/clear/1k duration 22.40 (±2.10 ms) 21.80 (±2.25 ms) -0.6ms (2.7%) 👌
wc-create-10k metric base(19953e1) target(f598b72) trend
benchmark-table-wc/create/10k duration 1925.80 (±24.45 ms) 1963.15 (±13.00 ms) +37.3ms (1.9%) 👎
wc-create-1k metric base(19953e1) target(f598b72) trend
benchmark-table-wc/create/1k duration 223.85 (±5.60 ms) 221.25 (±6.05 ms) -2.6ms (1.2%) 👌
wc-update-10th-1k metric base(19953e1) target(f598b72) trend
benchmark-table-wc/update-10th/1k duration 70.50 (±4.55 ms) 72.85 (±5.80 ms) +2.3ms (3.3%) 👌

@diervo diervo merged commit 8dc263b into master Jan 14, 2019
@diervo diervo deleted the apapko/create-element-param-validation branch January 14, 2019 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants