Skip to content

Removing tight coupling in recipe-editing vue components #386

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

Merged

Conversation

seyfeb
Copy link
Collaborator

@seyfeb seyfeb commented Nov 13, 2020

I noticed that the editing components (EditInputField, EditInputGroup, etc.) are tightly coupled with RecipeEdit due to the references from the child to the parent component. As an example, look at the EditInputField component which sets a field in the $parent.

In this PR I removed the tight coupling which should allow/lead to

  • a clear one-way dependency of those components
  • more flexible ways of data binding
  • v-model can be used on those components
  • components can be reused in different places.

@sam-19 Could you have a look at this?

@seyfeb seyfeb force-pushed the architecture/decouplingVueComponents branch from 4a7f62a to fe1a2cd Compare November 13, 2020 19:38
@seyfeb seyfeb changed the title Architecture/decoupling vue components Removing tight coupling in recipe-editing vue components Nov 13, 2020
@seyfeb seyfeb force-pushed the architecture/decouplingVueComponents branch from fe1a2cd to e37dc44 Compare November 14, 2020 16:21
@sam-19
Copy link
Contributor

sam-19 commented Dec 12, 2020

Hey, and sorry for the delay. I'm afraid I don't have quite enough time to review all the Vue-related pull requests at the moment, but one of the great things about Vue is that it's easy to grasp. @seyfeb probably can do it just as well as I at this point.

There is one thing that caught my attention. Some of the components have a prop named 'value' that is not explicitly passed down to the component from the parent. I can only assume this is an implicit feature that binds the v-model attribute to the value prop and as such is probably just fine. My personal design philosophy, however, has been to always avoid implicity for a number of reasons (it relies on features that may change, it may behave unexpectedly in edge scenarios, the code is harder to read or requires intimate familiarity with the framework etc.), and am happy that Nextcloud is (probably) deprecating jQuery in the near future. One potential issue is that if we have to add another input element to one of the components in question, someone has to decide which of them carries the "primary" value and which is only a secondary one. In the end of the day it's still just a matter of taste, but something to think about nevertheless.

Bottom line: I think moving away from tight coupling is the right way to go and if these changes work in a test environment, I'd say go for it. Sorry that I can't devote the time for a proper review right now.

@seyfeb
Copy link
Collaborator Author

seyfeb commented Dec 12, 2020

tl;dr I’m going to explicitly state which property is used by the v-model binding of the components.

Thank you @sam-19, for your comments!

Regarding v-model some thoughts from my side:

  • the two-way data binding is a fundamental feature provided by vue.js (and already discussed on the introduction page, so I’m rather optimistic that it won’t suddenly be gone. As it is introduced to vue beginners very early, I assume that most will understand what it is supposed to do.
  • using v-model even makes the code in the parent easier to read since it is less cluttered (no need for specifying v-bind and v-on)
  • you have a point with using the implicit value property. In v3 it is even going to be renamed as I just found out. In 2.2, however, the possibility of explicitly defining the property and event name handled by the v-model directive was introduced. Therefore I would propose to update the components to have an explicit statement in the code - making it easier to understand.
  • In v3 your problem: "decide which of them carries the "primary" value and which is only a secondary one" will also be solved since you can define multiple models! :)

@seyfeb seyfeb force-pushed the architecture/decouplingVueComponents branch from e37dc44 to 28c7501 Compare December 12, 2020 13:02
@codecov
Copy link

codecov bot commented Dec 12, 2020

Codecov Report

Merging #386 (ea56afb) into master (cce3864) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##             master    #386   +/-   ##
========================================
  Coverage      0.91%   0.91%           
  Complexity      414     414           
========================================
  Files            13      13           
  Lines          1307    1307           
========================================
  Hits             12      12           
  Misses         1295    1295           
Flag Coverage Δ Complexity Δ
integration 0.00% <ø> (ø) 0.00 <ø> (ø)
unittests 0.91% <ø> (ø) 0.00 <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@christianlupus christianlupus force-pushed the architecture/decouplingVueComponents branch 2 times, most recently from 0f6bb4b to 3d154bf Compare December 21, 2020 10:21
@christianlupus
Copy link
Collaborator

@seyfeb I fear the merging of #402 caused conflicts. Could you please have a look and rebase this branch?

@seyfeb seyfeb force-pushed the architecture/decouplingVueComponents branch from 3d154bf to 310ced8 Compare December 22, 2020 08:15
@christianlupus
Copy link
Collaborator

I just tested the changes and I found a small bug:

When opening a recipe without any nutrition information attached, I get warnings in the JS console if I change anything (aka trigger events):
grafik

@christianlupus
Copy link
Collaborator

Another thing I found just now: When creating a new recipe from scratch the nutrition settings are hidden. Saving and reopening for editing allows to set them correctly.

@seyfeb
Copy link
Collaborator Author

seyfeb commented Dec 23, 2020

Thank you for the feedback. It seems like the rebase didn’t go as smooth as hoped. The problems you found should be fixed now, @christianlupus !

@christianlupus christianlupus force-pushed the architecture/decouplingVueComponents branch from ac17a5b to ecc40bb Compare December 28, 2020 16:08
@christianlupus christianlupus merged commit d8f0f80 into nextcloud:master Dec 28, 2020
@seyfeb seyfeb deleted the architecture/decouplingVueComponents branch December 30, 2020 12:18
@christianlupus christianlupus mentioned this pull request Jan 2, 2021
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.

3 participants