GithubHelp home page GithubHelp logo

keys implementation? about didact HOT 6 OPEN

pomber avatar pomber commented on June 15, 2024
keys implementation?

from didact.

Comments (6)

yisar avatar yisar commented on June 15, 2024 3

@brainkim Well, I can explain it, it is similar to React.

A B => B A
  1. insertPoint
    first, save the insertPoint(Usually the previous fiber), when traversing B, its insertPoint is A, and insertPoint of A is null
  2. 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
  3. reused
    Only reused fiber have insertPoint, others have not
    if there is no insertPoint, it will insert befroe first child
  4. 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.

pomber avatar pomber commented on June 15, 2024 2

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.

yisar avatar yisar commented on June 15, 2024 2

@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.

Combo819 avatar Combo819 commented on June 15, 2024 1

Hi @yisar Did you change the implementation of reconciliation in fre? I'm confused after reading the explanation and the code. Thanks

from didact.

yisar avatar yisar commented on June 15, 2024

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.

brainkim avatar brainkim commented on June 15, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.