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

Bad design of StateTree.collectDirtyNodes() #317

Closed
denis-anisimov opened this issue Mar 17, 2016 · 2 comments · Fixed by #6618
Closed

Bad design of StateTree.collectDirtyNodes() #317

denis-anisimov opened this issue Mar 17, 2016 · 2 comments · Fixed by #6618

Comments

@denis-anisimov
Copy link
Contributor

denis-anisimov commented Mar 17, 2016

com.vaadin.flow.internal.StateTree.collectDirtyNodes() is a public method which mutates the internal state.
The method cleans up dirty nodes list.
User may call it at any time so it will break the logic which relies on this list to collect changes.

Actually collectChanges() method delegates the call to collectDirtyNodes() snd also causes the same issue.

The dirty nodes list should be cleaned up once (in the end of request handling ?) instead of cleaning up each time when changes are collected (f.e. as a reaction on event). And this logic should not be exposed as API.

@denis-anisimov
Copy link
Contributor Author

Notes for myself:

  • identify all methods that should not be public and breaks the "assumption" (which is : the StateTree state is changed (actually cleaned up) only from expected places).
  • if it's possible make "friend" classes so that those methods are not exposed as public API anyhow.
  • if it's not possible to tricky then just add javadocs so anyone who is going to call these methods don't call them unexpectedly.

@denis-anisimov
Copy link
Contributor Author

denis-anisimov commented Oct 4, 2019

In the PR :

  • collectDirtyNodes doesn't clean the internal state anymore.
  • collectChanges is still an issue. It mutates the internal state and has to be called from one place in fact. But it's too tricky to fix this since:
    • there are many tests that rely on it. I can make it private method so only one dedicated caller may call it but it will be too hard to fix existing tests.
    • the problem is also delegated to the StateNode::collectChanges method which also mutates the StateNode state though it should only collect changes. And this method is also used in many places in the tests.

So I've just added warnings to avoid calling this methods from unexpected places.

@joheriks joheriks added this to the 2.1.0.beta2 milestone Oct 7, 2019
ujoni pushed a commit that referenced this issue Oct 11, 2019
ujoni pushed a commit that referenced this issue Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants