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(wire-service): update wire method arg to an object #44

Merged
merged 2 commits into from
Jan 30, 2018

Conversation

yungcheng
Copy link
Contributor

@yungcheng yungcheng commented Jan 26, 2018

Details

Does this PR introduce a breaking change?

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

Wired method argument has been updated to {error, data} instead of error, data. However, it's a phasing approach so if the wiredMethod.length === 2, the old approach is still supported

@salesforce-best-lwc-internal
Copy link

Benchmark comparison

Base commit: 839cdfe | Target commit: 0a77f6c

benchmark base(839cdfe) target(0a77f6c) trend

this.cmp[this.propName](null, value);
// TODO: deprecate (error, data) args
if (wireMethod.length === 2) {
wireMethod.call(this.cmp, null, value);
Copy link
Contributor

@caridy caridy Jan 26, 2018

Choose a reason for hiding this comment

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

should we log a warning a deprecation warning the console here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, however this is going to be short-lived (2 weeks)

this.cmp[this.propName](err, undefined);
// TODO: deprecate (error, data) args
if (wireMethod.length === 2) {
wireMethod.call(this.cmp, err, undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we log a warning a deprecation warning the console here?

@salesforce-best-lwc-internal
Copy link

Benchmark comparison

Base commit: 839cdfe | Target commit: 183c73c

benchmark base(839cdfe) target(183c73c) trend

console.warn('[DEPRECATE] @wire function no longer supports two arguments (error, data), please update your code to use ({error, data}) instead.');
wireMethod.call(this.cmp, err, undefined);
} else {
wireMethod.call(this.cmp, { data: undefined, error: err });
Copy link
Contributor

Choose a reason for hiding this comment

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

Whats the reasoning behind using undefined for missing data and null for missing error? Do we even need to include data and error keys at all in these cases?

Copy link
Contributor

Choose a reason for hiding this comment

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

interesting question, but not really about this PR. @yungcheng can you open an issue to discuss that?

I have no strong opinions here. In general I think of errors as objects, in which case it could be null or an object that detonates the error, while I think of data as anything that might or might not exists, in which case undefined is more accurate.

It will be interesting to mix this with the fact that the request might be in-flight during the first rendering process, and if that's the case, what will be the guideline for people to protect against that situation? /cc @kevinv11n

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kevinv11n wanna chime in?

Copy link
Contributor

@kevinv11n kevinv11n Jan 30, 2018

Choose a reason for hiding this comment

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

the request might be in-flight

I don't understand the significance of that. Can you elaborate?

When it was a function call with 2 arguments we had to provide a value for the first argument. I spec'ed it as undefined. Now that we're using an object I think we shouldn't define the key when it has no value. So this line becomes wireMethod.call(this.cmp, { error: err })

And line 125: wireMethod.call(this.cmp, { data: value })

With destructuring, this results in undefined being assigned to the absent keys.

@yungcheng yungcheng merged commit 6eae53d into master Jan 30, 2018
@yungcheng yungcheng deleted the vince/wire-method-arg-update branch January 30, 2018 20:37
Copy link
Contributor

@kevinv11n kevinv11n left a comment

Choose a reason for hiding this comment

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

Looks good except for undefined/null passing in object. See comment.

console.warn('[DEPRECATE] @wire function no longer supports two arguments (error, data), please update your code to use ({error, data}) instead.');
wireMethod.call(this.cmp, err, undefined);
} else {
wireMethod.call(this.cmp, { data: undefined, error: err });
Copy link
Contributor

@kevinv11n kevinv11n Jan 30, 2018

Choose a reason for hiding this comment

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

the request might be in-flight

I don't understand the significance of that. Can you elaborate?

When it was a function call with 2 arguments we had to provide a value for the first argument. I spec'ed it as undefined. Now that we're using an object I think we shouldn't define the key when it has no value. So this line becomes wireMethod.call(this.cmp, { error: err })

And line 125: wireMethod.call(this.cmp, { data: value })

With destructuring, this results in undefined being assigned to the absent keys.

This pull request was closed.
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.

5 participants