Comments (6)
@brainkim Well, I can explain it, it is similar to React.
A B => B A
- insertPoint
first, save the insertPoint(Usually the previous fiber), when traversing B, its insertPoint is A, and insertPoint of A is null - insertBefore
If there is insertPoint, it will insert before it, so B will insert before A
if insertPoint is null, it will insert before null, same to appendChild - reused
Only reused fiber have insertPoint, others have not
if there is no insertPoint, it will insert befroe first child - key and index
React use not only key but also index to reused fibers, I simplify this.
I use hash to mark them meanwhile.
Generally speaking, it is actually the processing of insertpoint and reuse. In React, it distinguishes a variety of situations, and Fre super simplifies it.
You can try to debug them by yourself!
from didact.
Hey, I haven't. Let me know if you find something or if you try to do it yourself, I'd like to add a link to it.
from didact.
@Combo819 In Fre2 version, I refactor the reconciliation algorithm. The new algorithm uses Collision pointer for preprocessing, which is better implemented and easier to understand.
I can reinterpret the new algorithm implementation in Fre2:
1 2 3 4
1 3 2 4
We traverse from both ends to the middle, and find that 1 and 4 are exactly the same, then we skip them, and then it becomes:
2 3
3 2
The remaining nodes can be reused. We save their DOM references. Finally, we just need to change the position, that is, 3 is inserted in front of 2.
Of course, if you are interested in the old algorithm, you can look up the code of fre1, but I think fre2 will be better.
from didact.
Hi @yisar Did you change the implementation of reconciliation in fre? I'm confused after reading the explanation and the code. Thanks
from didact.
I implemented this in fre. It has the same performance as react, but it's super simple.
https://github.com/yisar/fre/blob/master/src/reconciler.js#L270
from didact.
@yisar can you explain the general algorithm you use? I canβt seem to figure out from the code itself sorry :)
from didact.
Related Issues (20)
- Buttons not working as expected HOT 1
- Updated child element gets appended to the end of the parent node. HOT 1
- Duplicate deletion commit
- "DELETION" exception HOT 1
- An awful question... IE11... HOT 3
- Why can not use '!==' here ? HOT 2
- course of 'build-your-own-vue' ?
- Tips "react-scripts": "5.0.0" will course jsx error HOT 3
- updateDom in createDom function HOT 2
- Use state hook not working on functional component
- I learned from 'Build Your Own React' and encountered problems in building Fiber HOT 4
- help: Confused with 'requestIdleCallback(workLoop)' HOT 2
- commitWork function should return after commitDeletion(anOldFiber, domParent)
- Old Fiber For First Render Is Null !!?
- requestIdleCallback is never stop?
- Adding useEffect hook HOT 1
- Router implementation? HOT 4
- How to handle styling?
- Doesn't render elements on different containers.
- Why does set state always start the work from root again
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from didact.