-
Notifications
You must be signed in to change notification settings - Fork 88
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
Fix inverted validate label check in NcInputField #3980
Conversation
Signed-off-by: Raimund Schlüßler <[email protected]>
Signed-off-by: Raimund Schlüßler <[email protected]>
Signed-off-by: Raimund Schlüßler <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works fine, tested 🎉
Thank you, interesting hidden problem 😅
Comment about watchs -> computed is non-blocking by me.
Signed-off-by: Raimund Schlüßler <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AH, wait
if (!isValidLabel) { | ||
console.warn('You need to add a label to the NcInputField component. Either use the prop label or use an external one, as per the example in the documentation.') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warn in computed = log every time the computed changes. It might not be the desired outcome
I'm not sure this is a good idea 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't the same happen if we warn in the watcher? The computed changes, the watcher fires, checks the label and warns in case it is not valid!?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, good point 🙈
I'm weirded out by this anti pattern though 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure the computed is not executed on other occasions? if so, you can merge !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The computed is triggered every time label
or labelOutside
is changed, but of cause the warning will only be fired if one of both is falsy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skjnldsv I don't know whether it's an anti-pattern, but we do the same here for example: https://github.com/nextcloud/nextcloud-vue/blob/master/src/mixins/actionText.js#L87-L93 🙈
The computed is triggered every time
label
orlabelOutside
is changed, but of cause the warning will only be fired if one of both is falsy.
I would think so too. If label
changes between False
, undefined
, null
, an empty string or anything else evaluating to False
, the warning would be triggered again even though it was invalid before already. But that seems a bit theoretic to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's hear what @ShGKme thinks about this approach 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skjnldsv I don't know whether it's an anti-pattern, but we do the samer here for example:
master
/src/mixins/actionText.js#L87-L93 see_no_evil
looks at blame
sees @skjnldsv
closes tab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's hear what @ShGKme thinks about this approach 🙂
It's too late, but yes 😅.
It proper works, but it is an anti-pattern, computed
should never have side-effects, only computing the value.
In options API there is a place for computed + watch
, in Composition - watchEffect
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments
The
NcInputField
component currently warns about a missing label only if a label is provided and if the label changes during the lifetime of the component (which probably is the reason why no one noticed this yet). This PR fixes the inverted logic and runs the check on component creation as well. This might spawn quite a few warnings in the apps using this component, but I guess that's what this warning is for 🤷As a side note, I would propose to change from
throw new Error
toVue.warn
, but that's a matter of taste, I guess.