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

Extract PostStream state #2160

Merged
merged 65 commits into from
Aug 8, 2020

Conversation

askvortsov1
Copy link
Sponsor Member

@askvortsov1 askvortsov1 commented May 10, 2020

Fixes Part of #1821, #2144
Fixes #2001
Fixes #2086

Changes proposed in this pull request:
Extract PostStream state out of PostStream, PostStreamScrubber.

Reviewers should focus on:

  • Can we get rid of the positionChanged event sent out in PostStream?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

Copy link
Member

@dsevillamartin dsevillamartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some questions about the code and implementation.

Will look more thoroughly once I'm not on mobile.

js/src/forum/components/DiscussionPage.js Outdated Show resolved Hide resolved
js/src/forum/components/DiscussionPage.js Outdated Show resolved Hide resolved
js/src/forum/components/RenameDiscussionModal.js Outdated Show resolved Hide resolved
@askvortsov1 askvortsov1 linked an issue May 12, 2020 that may be closed by this pull request
65 tasks
@askvortsov1 askvortsov1 removed a link to an issue May 22, 2020
65 tasks
@franzliedke franzliedke linked an issue May 22, 2020 that may be closed by this pull request
@clarkwinkelmann
Copy link
Member

I'm mostly ok with this solution, but I'm thinking whether it wouldn't make sense to maybe keep the stream as a single class?

If we simply made the stream into a non-component class, that has just a render() method that outputs vnodes. The only thing that would need moving are the stuff in config(). Those could become a start and stop method that are called from the DiscussionPage component. And the things in init would move to the constructor instead. It would no longer be a component, but just a helper class to generate the output of the DiscussionPage.

It would make for a way simpler diff, and in my opinion this is a valid way to use Mithril (very similar to what I was suggesting with AlertManager or ModalManager).

@askvortsov1 askvortsov1 force-pushed the as/frontend_rewrite_post_stream_state_try_4 branch 2 times, most recently from d6df661 to eb52edc Compare June 19, 2020 21:57
@askvortsov1 askvortsov1 force-pushed the as/frontend_rewrite_post_stream_state_try_4 branch from eb52edc to 67b6691 Compare June 27, 2020 23:00
@clarkwinkelmann
Copy link
Member

Could you avoid force-pushing during the review phase? It makes it completely impossible to see what was changed since last review 😅 😅 😅

@askvortsov1
Copy link
Sponsor Member Author

Sorry, that was a rebase to avoid conflicts with other merged things.

@franzliedke franzliedke force-pushed the as/frontend_rewrite_post_stream_state_try_4 branch from 67b6691 to 81fa5bc Compare July 3, 2020 13:12
*/
reset(start, end) {
this.visibleStart = start || 0;
this.visibleEnd = this.sanitizeIndex(end || this.constructor.loadCount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since doing a major rewrite, might want to also change visibleEnd to:

this.visibleEnd = this.sanitizeIndex(end || this.constructor.loadCount - 1)

Logic:
Suppose loadCount is 1, visibleStart = 0 and visibleEnd should be the same post 0.

Would need to also adjust all the code that references visibleEnd - I can send you a pull request for that if you want.

@clarkwinkelmann
Copy link
Member

I'm really not sure how to handle review on this. The diff is very complicated to read.

If it works as before I'd say go ahead and we can always fix stuff later.

askvortsov1 and others added 10 commits July 31, 2020 11:17
…ernally (and using it would be bad practice), fixing up PostStream
The event is not triggered anymore.
This is now handled through the `positionHandler` prop.
...instead of calculating this derived value outside the state class.
In addition, this again avoids writing a state property from
outside the state class.

I am not 100% sure whether this extra sanitization is necessary,
but it seems to be the only place where it is not applied when
changing the value of `visibleEnd` (and not safeguarded otherwise),
so I erred on the safe side.
- Law of demeter (no need to access discussion through the state)
- Less public API surface of the state object
@franzliedke franzliedke force-pushed the as/frontend_rewrite_post_stream_state_try_4 branch from fb04724 to 1a2f952 Compare July 31, 2020 09:33
@franzliedke franzliedke force-pushed the as/frontend_rewrite_post_stream_state_try_4 branch from c13ff12 to 09c722e Compare July 31, 2020 10:14
@askvortsov1 askvortsov1 force-pushed the as/frontend_rewrite_post_stream_state_try_4 branch from fc5eddb to d4abf58 Compare August 4, 2020 22:07
@askvortsov1 askvortsov1 merged commit 6953d93 into master Aug 8, 2020
@askvortsov1 askvortsov1 deleted the as/frontend_rewrite_post_stream_state_try_4 branch August 8, 2020 18:45
franzliedke added a commit that referenced this pull request Aug 14, 2020
This also avoids a double-fade from the JavaScript code, which was
probably introduced in #2160.
askvortsov1 added a commit that referenced this pull request Aug 16, 2020
* Fix closing the composer with ESC key

Regression from #2161.

* Remove obsolete method

Regression from #2162.

* Mark method as protected

* Fade in posts in post stream using CSS

This also avoids a double-fade from the JavaScript code, which was
probably introduced in #2160.

* Fix fadeIn for post stream items

Co-authored-by: Alexander Skvortsov <sasha.skvortsov109@gmail.com>
askvortsov1 added a commit that referenced this pull request Sep 6, 2020
* Fix closing the composer with ESC key

Regression from #2161.

* Remove obsolete method

Regression from #2162.

* Mark method as protected

* Fade in posts in post stream using CSS

This also avoids a double-fade from the JavaScript code, which was
probably introduced in #2160.

* Fix fadeIn for post stream items

Co-authored-by: Alexander Skvortsov <sasha.skvortsov109@gmail.com>
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.

Link to post scrolls to the previous post PostStream scroll bug
5 participants