-
Notifications
You must be signed in to change notification settings - Fork 32
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
consider Improving no-api-reassignments caveats #91
Comments
I am not familiar with how flow works, so bear with me. As far as I understand the meta XML file, your component looks like this: import { LightningElement } from 'lwc';
export default class Flow extends LightningElement {
@api values;
handleSomeEvent() {
this.values = /* some random value */;
}
} In which case, the |
I avoid flows since they had that Flash-based editor so I'm in same boat. Yes, this looks close to my use case. I've read some documentation and apparently there's an event I should be raising on change (https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.use_flow_runtime_considerations), good to know. And example that uses private properties + So yeah, would you consider adding an example similar to this or even just the link in the docs/rules/no-api-reassignments.md ? |
I was literally about to open an issue for this exact issue! I'm pretty sure this warning can be ignored in the context of an LWC component that is built specifically for a Flow. |
@pmdartus what is the correct way to use a getter/setter for this? A discussion on a PR came up today addressing this issue and we can't find the correct answer. Our first approach was this import { LightningElement, api } from "lwc";
export default class TodoItem extends LightningElement {
_itemName;
@api
get itemName() {
return this._itemName;
}
set itemName(value) {
this._itemName = value;
}
setName(evt) {
this._itemName = evt.target.value;
}
} In our PR reviews it was suggested that the @api contract expects the getter value to always be the same as the original value passed to the setter.
Honoring the above, should it actually look like this? import { LightningElement, api } from "lwc";
export default class TodoItem extends LightningElement {
_itemName;
_originalName;
@api
get itemName() {
return this._originalName;
}
set itemName(value) {
this._originalName = value;
this._itemName = value;
}
setName(evt) {
this._itemName = evt.target.value;
}
} |
Evening!
I'm slapped with "no-api-reassignment" violation on an lwc variable that yes, is exposed as
@api
but only because I need the values in a flow.In meta.xml file I have
I mean I know that for normal parent-child communication I'm supposed to use events, cool. But what about flows?
What's "better"? Disable the eslint rule or convert the variable to getter?
If this is an acceptable limitation (I don't expect js file's parser to jump over to meta.xml and have a look...) - can you add flows to the list of caveats? If getter is more appropriate - can you write that as alternative example of correct code?
The text was updated successfully, but these errors were encountered: