from pRegroup2020
2019-07-16 - Verify if replacing the Reconsiler stops the image blinking on the iPad. done
2019-08-02
A collection of things written in pRegroup:. - Redux could make you happy. - Improved Tool selection - If you draw with a pen while zoomed out, it rattles.
In this section, we will create a React reconciler using react-reconciler package. We are going to implement the renderer using Fiber. Earlier, React was using a stack renderer as it was implemented on the traditional JavaScript stack. On the other hand, Fiber is influenced by algebraic effects and functional ideas. It can be thought of as a JavaScript object that contains information about a component, its input, and its output.
Organize your understanding of state management renewal
Essentially, this app is "an app that renders to HTML5 Canvas
Using Paper.js instead of drawing directly in Canvas (for rounding off hit judgments, etc.)
When the React-like state is updated, all Paper#Item is destroyed and regenerated.
That implementation works fine on Chrome on PC.
Uncomfortable flashing on "stickies with images" in Safari on iPad, Chrome, and Safari on PC, regardless of the number of stickies.
Probably only Chrome on PC, caching images in a layer (=browser) below Paper.js
Paper#item must not be discarded in order to work comfortably on iPad
That means that when the React-like state is updated, the Paper.js layer needs to deal with it by modifying or moving existing objects
This is almost the same processing that React does for the DOM, and it is handled by the Reconciler
You need to implement your own Reconciler or use an existing implementation. I don't want to implement it, so use react-paper-bindings
Attach unique identifier to the object
In addition, the entire state is currently subject to UNDO, but UNDO will be changed to push snapshots as needed.
As for the state substitution, we should first try to have a unique identifier and see if we can't use the same mechanism that react uses to render the list, and avoid creating our own differential rendering if at all possible.
However, the final output is a list of elements in paper.js, so we can't use the DOM manipulation methods, so we need to figure out how to do that.
Observation of how react-paper-binding is implemented
The point that an object must have a unique ID is called Key in React language.
https://github.com/nitin42/Making-a-custom-React-renderer/blob/master/part-one.md
Looks good because it uses react-paper-binding
state management - Issue with slow rendering of image stickies on iPad - > I'm sure the ideal of "100 image stickies and no flickering" can be achieved if you work on the deeper aspects of the design. - This one, not so easy when it comes to "keeping UNDO functioning." - That said, I'm not sure I'd want to throw away the UNDO feature...
Organizing the Issue
I'm a bit bewildered, but too early optimization is the root of all evil, so I'll start by creating an implementation that retains the entire state history.
Even with a single image, the behavior is that "the image is drawn with a delay of 0.5 to 1 second on the iPad," so to solve this problem, the implementation must be such that objects that have already been drawn are used as much as possible.
Do we need to treat Paper.js's tree of objects like React's virtual DOM?
I want to be able to co-edit. - Even one person needs to co-edit.
This page is auto-translated from /nishio/状態管理 using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.