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

Remove code duplication in shinyfeedback.js #42

Merged
merged 1 commit into from
Jul 21, 2020
Merged

Remove code duplication in shinyfeedback.js #42

merged 1 commit into from
Jul 21, 2020

Conversation

jcheng5
Copy link
Contributor

@jcheng5 jcheng5 commented Jul 21, 2020

Introduced a baseInputFeedback object that serves as a base class
for the other xxxInputFeedback implementations. Each impl need only
provide the methods that differ from the base class.

With these changes, I think the Shiny "feedback" custom message
handler can be slightly simplified--it should no longer be necessary
to hide() then show() for cases where feedback is shown twice in a
row for an input.

Introduced a baseInputFeedback object that serves as a base class
for the other xxxInputFeedback implementations. Each impl need only
provide the methods that differ from the base class.

With these changes, I think the Shiny "feedback" custom message
handler can be slightly simplified--it should no longer be necessary
to hide() then show() for cases where feedback is shown twice in a
row for an input.
@jcheng5
Copy link
Contributor Author

jcheng5 commented Jul 21, 2020

Note: The diff is a bit hard to make sense of at first, you might want to review the new version of the file first.

https://github.com/jcheng5/shinyFeedback/blob/dedupe-javascript/inst/assets/js/shinyfeedback.js

I tested these changes by running the supported_inputs_app example through shinytest, with and without valid values in all the inputs, and confirmed that the results are pixel-perfect.

@merlinoa
Copy link
Owner

Thanks @jcheng5 !! Yes this definitely reduces the code duplication and makes the input feedbacks more like shiny input binding with the base class and the $.extend() logic. Awesome!

One question on your comment:

With these changes, I think the Shiny "feedback" custom message
handler can be slightly simplified--it should no longer be necessary
to hide() then show() for cases where feedback is shown twice in a
row for an input.

Just to confirm, are you suggesting replacing this if/else block https://github.com/jcheng5/shinyFeedback/blob/3c1b7b2ad269e6920791a5ff0c900ca6552f0554/inst/assets/js/shinyfeedback.js#L444 with just feedbackFun.show(theInput, message)?

If so, yes I agree that this will be an improvement in both simplicity and functionality. I can make this change after merging this PR. Going to go ahead and merge now. Thanks!

@merlinoa merlinoa merged commit f3242a2 into merlinoa:master Jul 21, 2020
@jcheng5
Copy link
Contributor Author

jcheng5 commented Jul 21, 2020

Just to confirm, are you suggesting replacing this if/else block...

Yes, exactly. I haven't tested with that change but it sure seems like it should work.

@jcheng5 jcheng5 deleted the dedupe-javascript branch July 21, 2020 16:28
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.

2 participants