Repository navigation
Move task list logic outside of WpcomChecklist render tree - #28057
Conversation
sixhours
left a comment
There was a problem hiding this comment.
I tested the checklist notification in inline help! All is working as expected.
jsnajdr
left a comment
There was a problem hiding this comment.
Looks and works very well 👍 Posted just two little nits.
| ( storedTask !== task.key || storedTask === null ) && | ||
| ! isFinished && | ||
| ! taskList.areAllTasksCompleted() && | ||
| ( storedTask !== taskList.getFirstIncompleteTask().id || storedTask === null ) && |
There was a problem hiding this comment.
Could we eliminate the check for areAllTasksCompleted()? That's equivalent to getFirstIncompleteTask() returning null, isn't it?
There was a problem hiding this comment.
It is. It was more of a conceptual thing, but you're right, "no first incomplete task" is easy enough to grasp to not require another method.
| } = this.props; | ||
|
|
||
| const canShowChecklist = this.canShow(); | ||
| const taskList = new WpcomTaskList( taskStatuses, { designType } ); |
There was a problem hiding this comment.
Here we create a new instance on every rerender. Doesn't it cause some unwanted rerenders?
There was a problem hiding this comment.
We're already inside the render method, so the component and its children are already going to render. That said, this could make a difference if one of the children is looking at its props to determine whether or not to re-render itself (e.g. by being a pure component, or by having a shouldComponentUpdate).
In order to cover those situations, I added memoization to this.
| const completeCount = tasks.filter( task => task.isCompleted ).length; | ||
| const isFinished = taskList.areAllTasksCompleted(); | ||
| const firstIncomplete = taskList.getFirstIncompleteTask(); | ||
| const completePercentage = Math.round( ! total ? 0 : ( completeCount / total ) * 100 ); |
There was a problem hiding this comment.
What if there was a getCompletedPercentage method on the taskList? Or getCompletionStatus that would return an object that contains everything our UI wants to know:
{
completed: 6,
total: 10,
percent: 60,
}Just an idea on how to improve the object-oriented API of WpcomTaskList 🙂
74a9606 to
0ffe350
Compare
|
Thanks, @jsnajdr! All comments addressed. |
Task list logic was stuck inside the WpcomChecklist render tree, forcing checklist instances to look at the list of children to determine completion status. This also made it difficult to determine whether the checklist should be rendered without actually rendering it. This commit refactors the task list into a class that's instanced by WpcomChecklist and attached as a prop to the checklist component in its render tree. This instance serves as the single source of truth on the list of tasks, the completion status of each task, and the overall completion status for the task list.
4b912ea to
11b1279
Compare
|
Heh, can't leave changes open for more than a few days... I rebased on top of |
Changes proposed in this Pull Request
WpcomChecklistand friends. Using.jsxfor files including JSX and.jsfor files containing plain JS.lodashmethod usage with native methods.WpcomChecklistrender tree.Each of these changes is presented as a separate commit, and it will likely be easier to look at each commit individually.
The last change is the main one in this PR, and is intended as an architectural revision that improves decoupling between rendering and logic.
Task list logic was stuck inside the
WpcomChecklistrender tree, forcing checklist instances to look at the list of their children to determine completion status. This also made it difficult to determine whether the checklist should be rendered without actually rendering it (which will be useful in optimization work; see #27926).This commit refactors the task list into a class that's instanced by
WpcomChecklistand attached as a prop to the checklist component in its render tree.This instance serves as the single source of truth on the list of tasks, the completion status of each task, and the overall completion status for the task list.
Testing instructions
/checklistpage; the banner in/stats; the inline help integration)