ããã«ã¡ã¯ãHabrïŒ Andrew Clarkã®èšäºãReact Fiber Architectureãã®ç¿»èš³ã«æ³šç®ããŠãã ããã
ãšã³ããªãŒ
React Fiberã¯ãäž»èŠãªReactã¢ã«ãŽãªãºã ã®é²æ©çãªå®è£ ã§ãã ããã¯ãReactéçºããŒã ã«ãã2幎éã®ç 究ã®é倧æã§ãã
Fiberã®ç®æšã¯ãã¢ãã¡ãŒã·ã§ã³ãããŒãžäžã®èŠçŽ ã®æŽçãèŠçŽ ã®ç§»åãªã©ã®ã¿ã¹ã¯ãéçºããéã®çç£æ§ãé«ããããšã§ãã ãã®äž»ãªæ©èœã¯ã€ã³ã¯ãªã¡ã³ã¿ã«ã¬ã³ããªã³ã°ã§ããã¬ã³ããŒã®äœæ¥ããŠãããã«åå²ããè€æ°ã®ãã¬ãŒã ã«åæ£ããæ©èœã§ãã
ä»ã®äž»èŠãªæ©èœã«ã¯ãDOMããªãŒã®çä¿¡æŽæ°ãäžæåæ¢ããã£ã³ã»ã«ããŸãã¯åå©çšããæ©èœãããŸããŸãªã¿ã€ãã®æŽæ°ã«åªå é äœãä»ããæ©èœãããã³ããªããã£ãã®èª¿æŽãå«ãŸããŸãã
ãã®èšäºãèªãåã«ãReactã®åºæ¬ååãç解ããããšããå§ãããŸãã
- Reactã³ã³ããŒãã³ããèŠçŽ ãããã³ã€ã³ã¹ã¿ã³ã¹
- å解
- React-åºæ¬çãªçè«çæŠå¿µ
- èšèšåå
埩ç¿
å解ãšã¯äœã§ããïŒ
調æŽã¯ã1ã€ã®èŠçŽ ããªãŒãå¥ã®èŠçŽ ããªãŒãšåºå¥ããŠã亀æãå¿ èŠãªéšåã決å®ããããã«äœ¿çšãããReactã¢ã«ãŽãªãºã ã§ãã
æŽæ°ã¯ãReactã¢ããªã±ãŒã·ã§ã³ã®ã¬ã³ããªã³ã°ã«äœ¿çšãããããŒã¿ã®å€æŽã§ãã ããã¯éåžžãsetStateã¡ãœãããåŒã³åºããçµæã§ãã ã³ã³ããŒãã³ãã®ã¬ã³ããªã³ã°ã®æçµçµæã
React APIã®éèŠãªèãæ¹ã¯ãæŽæ°ãã¢ããªã±ãŒã·ã§ã³ã®å®å šãªã¬ã³ããªã³ã°ã«ã€ãªãããã®ããã«èããããšã§ãã ããã«ãããéçºè ã¯å®£èšçã«è¡åããããšãã§ããããç¶æ ããå¥ã®ç¶æ ãžã®ã¢ããªã±ãŒã·ã§ã³ã®ç§»è¡ãã©ã®çšåºŠåççãïŒAããBãBããCãCããAãªã©ïŒãå¿é ããå¿ èŠã¯ãããŸããã
äžè¬ã«ãå€æŽããšã«ã¢ããªã±ãŒã·ã§ã³å šäœãã¬ã³ããªã³ã°ããããšã¯ãã»ãšãã©ã®åŸæ¥ã®ã¢ããªã±ãŒã·ã§ã³ã§ã®ã¿æ©èœããŸãã çŸå®ã®äžçã§ã¯ãããã¯ããã©ãŒãã³ã¹ã«æªåœ±é¿ãåãŒããŸãã ãã®è¡çºã«ã¯ãããã©ãŒãã³ã¹ã®å€§ããªéšåã«åœ±é¿ãäžããããšãªãå®å šãªã¬ã³ããªã³ã°ãã¥ãŒãäœæããæé©åãå«ãŸããŸãã ãããã®æé©åã®ã»ãšãã©ã«ã¯ã調æŽãšåŒã°ããããã»ã¹ãå«ãŸããŸãã
調æŽã¯ããã®èåŸã«ããã¢ã«ãŽãªãºã ã§ããããä»®æ³DOMããšåŒã°ãããã®ã§ãã å®çŸ©ã¯æ¬¡ã®ããã«èãããŸããReactã¢ããªã±ãŒã·ã§ã³ãã¬ã³ããªã³ã°ãããšãã¢ããªã±ãŒã·ã§ã³ã説æããèŠçŽ ããªãŒãäºçŽã¡ã¢ãªã«çæãããŸãã ãã®ããªãŒã¯ãã¬ã³ããªã³ã°ç°å¢ã«çµã¿èŸŒãŸããŸãããã©ãŠã¶ãŒã¢ããªã±ãŒã·ã§ã³ã®äŸã䜿çšããŠãDOMæäœã®ã»ããã«å€æãããŸãã ã¢ããªã±ãŒã·ã§ã³ã®ç¶æ ãæŽæ°ããããšïŒéåžžã¯setStateãåŒã³åºããŠïŒãæ°ããããªãŒãçæãããŸãã æ°ããããªãŒã¯åã®ããªãŒãšæ¯èŒãããæŽæ°ãããã¢ããªã±ãŒã·ã§ã³ã®åæç»ã«å¿ èŠãªæäœãæ£ç¢ºã«èšç®ããŠæå¹ã«ããŸãã
Fiberã¯èª¿æŽæ©èœã®å¯æ¥ãªå®è£ ã§ãããšããäºå®ã«ãããããããã»ãšãã©ã®å ŽåãReactã®ããã¥ã¡ã³ãã§èª¬æãããŠããé«ã¬ãã«ã®ã¢ã«ãŽãªãºã ã¯åãã§ãã
äž»ãªæŠå¿µïŒ
- ããŸããŸãªã¿ã€ãã®ã³ã³ããŒãã³ãã¯ãå®è³ªçã«ç°ãªãããªãŒã®çæã瀺åããŠããŸãã Reactã¯ããããæ¯èŒããããšã¯ãããåã«å€ãããªãŒãå®å šã«çœ®ãæããŸãã
- ãªã¹ãã¯ããŒã䜿çšããŠåºå¥ãããŸãã ããŒã¯ãæ°žç¶çãäºæž¬å¯èœãäžæãã§ãªããã°ãªããŸããã
調æŽãšã¬ã³ããªã³ã°
DOMããªãŒã¯Reactãæç»ã§ããç°å¢ã®1ã€ã§ãããæ®ãã¯React Nativeã䜿çšããŠãã€ãã£ãiOSããã³Androidãã¥ãŒã«èµ·å ããããšãã§ããŸãïŒãã®ããVirtual Domã¯å°ãäžé©åãªååã§ãïŒã
Reactãéåžžã«å€ãã®ç®æšããµããŒãããçç±ã¯ãReactã調æŽãšã¬ã³ããªã³ã°ãå¥ã ã®ãã§ãŒãºã«ãªãããã«æ§ç¯ãããŠããããã§ãã 調æŽæ©èœã¯ãããªãŒã®ã©ã®éšåãå€æŽãããããèšç®ããã¬ã³ãã©ãŒã¯åŸã§ãã®æ å ±ã䜿çšããŠä»¥åã«ã¬ã³ããªã³ã°ãããããªãŒãæŽæ°ããŸãã
ãã®åé¢ã¯ãReact DOMãšReact NativeããReact Coreã«ããåããã£ãã·ã¥ããŒã«ã䜿çšãããšãã«ç¬èªã®ã¬ã³ããªã³ã°ã¡ã«ããºã ã䜿çšã§ããããšãæå³ããŸãã
ãã¡ã€ããŒã¯ã調æŽã¢ã«ãŽãªãºã ã®åèšèšãããå®è£ ã§ãã ã¬ã³ããªã³ã°ãšéæ¥çãªé¢ä¿ããããŸãããæ°ããã¡ã«ããºã ã®ãã¹ãŠã®å©ç¹ããµããŒãããããã«ã¬ã³ããªã³ã°ã¡ã«ããºã ïŒã¬ã³ããªã³ã°ïŒãå€æŽã§ããŸãã
èšç»ã¯ããã€äœæ¥ãå®äºããå¿ èŠããããã決å®ããããã»ã¹ã§ãã
äœæ¥ -å®è¡ããå¿ èŠã®ããèšç®ã äœæ¥ã¯éåžžãæŽæ°ã®çµæã§ãïŒããšãã°ãsetStateã®åŒã³åºãïŒã
Reactã¢ãŒããã¯ãã£ã®ååã¯éåžžã«åªããŠããããããã®åŒçšã§ã®ã¿èª¬æã§ããŸãã
çŸåšã®Reactå®è£ ã§ã¯ãããªãŒãååž°çã«èµ°æ»ãã1ãã£ãã¯ïŒ16ããªç§ïŒã®éã«æŽæ°ãããããªãŒå šäœã§ã¬ã³ããªã³ã°é¢æ°ãåŒã³åºããŸãã ãã ããå°æ¥çã«ã¯ãããã€ãã®æŽæ°ããã£ã³ã»ã«ããŠãã¬ãŒã ã®ãžã£ã³ããé²ãããšãã§ããããã«ãªããŸãã
ããã¯ãReact Designã«é¢ããŠé »ç¹ã«è°è«ããããããã¯ã§ãã äžè¬çãªã©ã€ãã©ãªã®äžã«ã¯ããããã·ã¥ãã¢ãããŒããå®è£ ãããã®ããããæ°ããããŒã¿ãå©çšå¯èœã«ãªããšèšç®ãå®è¡ãããŸãã ãã ããReactã¯ãã«ã¢ãããŒããæ¡çšããŠãããå¿ èŠã«å¿ããŠèšç®ããã£ã³ã»ã«ã§ããŸãã
Reactã¯ãäžè¬åãããããŒã¿ãåŠçããããã®ã©ã€ãã©ãªã§ã¯ãããŸããã ããã¯ããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãæ§ç¯ããããã®ã©ã€ãã©ãªã§ãã ã©ã®èšç®ãé©åã§ãã©ã®èšç®ãçŸæç¹ã§ã¯é©åã§ãªãããå€æããããã«ãã¢ããªã±ãŒã·ã§ã³å ã§ç¬èªã®äœçœ®ãæã€å¿ èŠããããšèããŠããŸãã
èåŸã«äœããããã°ãããã«é¢é£ãããã¹ãŠã®ããžãã¯ãå ã«æ»ãããšãã§ããŸãã ããŒã¿ããã¬ãŒã ã¬ã³ããªã³ã°ã¬ãŒããããéãå°çããå ŽåãæŽæ°ãçµã¿åãããããšãã§ããŸãã ãã¬ãŒã ã®ããŠã³ããŒããé²æ¢ããããã«ããŠãŒã¶ãŒã®æäœïŒãã¿ã³ãã¯ãªãã¯ããããšãã®ã¢ãã¡ãŒã·ã§ã³ã®å€èŠ³ãªã©ïŒã®çµæãšããŠçããäœæ¥ã®åªå 床ããèæ¯ã§ã®éèŠåºŠã®äœãäœæ¥ïŒãµãŒããŒããèªã¿èŸŒãŸããæ°ããã³ã³ãã³ãã®ã¬ã³ããªã³ã°ïŒã«å¯ŸããŠé«ããããšãã§ããŸãã
äž»ãªæŠå¿µïŒ
- ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã§ã¯ãåæŽæ°ããã°ã©ã ãããã«é©çšããããšã¯éèŠã§ã¯ãããŸããã å®éããã®åäœã¯äžèŠã§ããããã¬ãŒã ã®äœäžãšUXã®äœäžã®äžå ãšãªããŸãã
- æŽæ°ã®çš®é¡ã«ãã£ãŠåªå é äœãç°ãªããŸããã¢ãã¡ãŒã·ã§ã³ã®æŽæ°ã¯ãããšãã°ããŒã¿ã¹ãã¬ãŒãžã®æŽæ°ãããæ©ãçµäºããã¯ãã§ãã
- ããã·ã¥ããŒã¹ã®ã¢ãããŒãã§ã¯ãã¢ããªã±ãŒã·ã§ã³ïŒéçºè ïŒãäœæ¥ã®èšç»æ¹æ³ã決å®ããå¿ èŠããããŸãã ãã«ããŒã¹ã®ã¢ãããŒãã«ããããã¬ãŒã ã¯ãŒã¯ã決å®ãäžãããšãã§ããŸãã
çŸæç¹ã§ã¯ãReactã«ã¯ãã©ã³ãã³ã°ã®å©ç¹ãããŸããããŸããã ãµãããªãŒå šäœã®æŽæ°çµæãããã«æç»ãããŸãã Reactã«ãŒãã«ã¢ã«ãŽãªãºã ã®èŠçŽ ãæ éã«éžæããŠã¹ã±ãžã¥ãŒãªã³ã°ãé©çšããããšããFiberã®éèŠãªã¢ã€ãã¢ã§ãã
ãã¡ã€ããŒãšã¯ïŒ
React Fiberã¢ãŒããã¯ãã£ãŒã®äžå¿ã«ã€ããŠèª¬æããŸãã ãã¡ã€ããŒã¯ãéçºè ãæèã«æ £ããŠããããããã¢ããªã±ãŒã·ã§ã³ã«å¯Ÿããäžäœã¬ãã«ã®æœè±¡åã§ãã ããªããããã絶æçã«ç解ããããšããè©Šã¿ãèãããªããèœèããããšãæããªãã§ãã ããïŒããªãã¯äžäººã§ã¯ãããŸããïŒã æ¢ãç¶ãããšãæçµçã«å®ãçµã³ãŸãã
ããã§ïŒ
Fiberã¢ãŒããã¯ãã£ã®äž»ãªç®æšã§ããReactãèšç»ã掻çšã§ããããã«ããŸããã å ·äœçã«ã¯ã次ã®ããšãã§ããå¿ èŠããããŸãã
- ä»äºãæ¢ããŠãåŸã§æ»ã£ãŠãã ããã
- ããŸããŸãªã¿ã€ãã®äœæ¥ã«åªå é äœãä»ããŸãã
- 以åã«è¡ã£ãäœæ¥ãåå©çšããŸãã
- äžèŠã«ãªã£ããäœæ¥ããã£ã³ã»ã«ããŸãã
ããããã¹ãŠè¡ãã«ã¯ããŸãäœæ¥ããŠãããã«åå²ããå¿ èŠããããŸãã ããæå³ã§ã¯ãããã¯ç¹ç¶ã§ãã ãã¡ã€ããŒã¯äœæ¥åäœãè¡šããŸãã
ããã«é²ãããã«ãReactã®åºæ¬çãªæŠå¿µãé¢æ°ããŒã¿ãšããŠã®ã³ã³ããŒãã³ããã«æ»ããŸãããã
v = f(d)
ãããæå³ããããšã¯ãReactã¢ããªã±ãŒã·ã§ã³ã®ã¬ã³ããªã³ã°ã¯ãæ¬äœã«ä»ã®é¢æ°ãžã®åŒã³åºããªã©ãå«ãŸããé¢æ°ãåŒã³åºããããªãã®ã§ããããšã§ãã ãã®é¡äŒŒæ§ã¯ãç¹ç¶ã«ã€ããŠèãããšãã«åœ¹ç«ã¡ãŸãã
ã³ã³ãã¥ãŒã¿ãåºæ¬çã«ããã°ã©ã ã®å®è¡é åºã確èªããæ¹æ³ã¯ãã³ãŒã«ã¹ã¿ãã¯ãšåŒã°ããŸãã é¢æ°ãå®äºãããšãæ°ããã¹ã¿ãã¯ã³ã³ãããã¹ã¿ãã¯ã«è¿œå ãããŸãã ãã®ã¹ã¿ãã¯ã³ã³ããã¯ãé¢æ°ã«ãã£ãŠå®è¡ãããäœæ¥ãè¡šããŸãã
ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã䜿çšããå Žåãããã«å€ãã®äœæ¥ãè¡ãããŸãããããã¯åé¡ã§ãããã¢ãã¡ãŒã·ã§ã³ã®ãžã£ã³ãã«ã€ãªãããæç¶çã«è¡šç€ºãããŸãã ããã«ããã®äœæ¥ã®äžéšã¯ãææ°ã®æŽæ°ããã°ã©ã ã«çœ®ãæããããå Žåã¯å¿
èŠãªãå ŽåããããŸãã ãã®æç¹ã§ãã³ã³ããŒãã³ãã¯äžè¬çãªæ©èœãããå
·äœçãªè²¬ä»»ãããããããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãšæ©èœã®æ¯èŒã¯ç°ãªããŸãã
ææ°ã®ãã©ãŠã¶ãŒãšReact Nativeã¯ããã®åé¡ã®è§£æ±ºã«åœ¹ç«ã€APIãå®è£
ããŠããŸãã
requestIdleCallbackã¯ã¿ã¹ã¯ãåé
ããŠãåªå
床ã®äœãé¢æ°ãåçŽãªæéã§åŒã³åºãããããã«ããrequestAnimationFrameã¯ã¿ã¹ã¯ãåé
ããŠãåªå
床ã®é«ãé¢æ°ã次ã®ãã¬ãŒã ã§åŒã³åºãããããã«ããŸãã åé¡ã¯ããããã®APIã䜿çšããã«ã¯ãã¬ã³ããªã³ã°äœæ¥ãå¢ååäœã«åå²ããå¿
èŠãããããšã§ãã åŒã³åºãã¹ã¿ãã¯ã®ã¿ã«äŸåããŠããå Žåãã¹ã¿ãã¯ã空ã«ãªããŸã§äœæ¥ãç¶è¡ãããŸãã
ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã®äžéšã®è¡šç€ºãæé©åããããã«åŒã³åºãã¹ã¿ãã¯ã®åäœãã«ã¹ã¿ãã€ãºã§ããããããšæããŸãããïŒ ã³ãŒã«ã¹ã¿ãã¯ã解é€ããŠã³ã³ãããæåã§æäœã§ããããããšæããŸãããïŒ
ãããReact Fiberã®åŒã³åºãã§ãã ãã¡ã€ããŒã¯ãReactã³ã³ããŒãã³ãã«åãããæ°ããã¹ã¿ãã¯å®è£ ã§ãã åäžã®ãã¡ã€ããŒãä»®æ³ã¹ã¿ãã¯ã³ã³ãããŒãšèãââãããšãã§ããŸãã
ã¹ã¿ãã¯ã®ãã®å®è£ ã®å©ç¹ã¯ãã³ã³ããã®ã¹ã¿ãã¯ãã¡ã¢ãªã«ä¿åããŠãå¿ èŠãªãšãã«ïŒãããŠã©ãã§ãïŒå®è¡ã§ããããšã§ãã ããã¯ãèšç»ç®æšãéæããããã®éèŠãªå®çŸ©ã§ãã
èšç»ã«å ããŠãã¹ã¿ãã¯ã§ã®æåã¢ã¯ã·ã§ã³ã«ããã䞊è¡æ§ããšã©ãŒå¢çãªã©ã®æŠå¿µã®å¯èœæ§ãæããã«ãªããŸãã
次ã®ã»ã¯ã·ã§ã³ã§ã¯ãç¹ç¶ã®æ§é ã«æ³šç®ããŸãã
ç¹ç¶æ§é
å ·äœçã«ã¯ãããã¡ã€ããŒãã¯ãã³ã³ããŒãã³ãããã®å ¥åããã³åºåã«é¢ããæ å ±ãå«ãJavaScriptãªããžã§ã¯ãã§ãã
ãã¡ã€ããŒã¯ã¹ã¿ãã¯ã³ã³ãããšäžèŽããŠããŸãããã³ã³ããŒãã³ãã®æ¬è³ªãšãäžèŽããŠããŸãã
ãç¹ç¶ãã®éèŠãªç¹æ§ã次ã«ç€ºããŸãïŒãã®ãªã¹ãã¯å®å šã§ã¯ãããŸããïŒã
ã¿ã€ããšããŒ
ã¿ã€ããšããŒã¯ããã¡ã€ããŒãšReactãšã¬ã¡ã³ããæäŸããŸãã å®éããã¡ã€ããŒãäœæããããšããããã®2ã€ã®ãã£ãŒã«ãã¯çŽæ¥ãã¡ã€ããŒã«ã³ããŒãããŸãã
ãã¡ã€ããŒã®ã¿ã€ãã¯ããã¡ã€ããŒã察å¿ããã³ã³ããŒãã³ããè¡šããŸãã ã³ã³ããŒãã³ãã®æ§æã®å Žåãã¿ã€ãã¯ã³ã³ããŒãã³ãã®é¢æ°ãŸãã¯ã¯ã©ã¹ã§ãã ãµãŒãã¹ã³ã³ããŒãã³ãïŒdivãspanïŒã®å Žåãã¿ã€ãã¯æååã§ãã
æŠå¿µçã«ã¯ãåã¯ãã¹ã¿ãã¯ã³ã³ããã«ãã£ãŠå®è¡ã远跡ãããé¢æ°ã§ãã
ã¿ã€ããšäžç·ã«ãããªãŒãæ¯èŒããŠãã¡ã€ããŒãåå©çšã§ãããã©ãããå€æãããšãã«ããŒã䜿çšãããŸãã
åäŸãšå
åŒ
ãããã®ãã£ãŒã«ãã¯ä»ã®ç¹ç¶ãæããç¹ç¶ã®ååž°æ§é ãè¡šããŸãã
ãã¡ã€ããŒã®åã¯ãã³ã³ããŒãã³ãã§renderã¡ãœãããåŒã³åºããçµæãšããŠè¿ãããå€ã«å¯Ÿå¿ããŸãã 以äžã®äŸã§ã¯ïŒ
function Parent() { return <Child /> }
芪ãã¡ã€ããŒã®åã¯åã«å¯Ÿå¿ããŸãã
renderãè€æ°ã®åãè¿ãå ŽåïŒFiberã®æ°æ©èœïŒãçžå¯ŸïŒãŸãã¯é£æ¥ïŒãã£ãŒã«ãã䜿çšãããŸãã
function Parent() { return [<Child1 />, <Child2 />] }
åç¹ç¶ã¯ãå é ãæåã®åã§ããåäžãªã³ã¯ãªã¹ãã§ãã ãããã£ãŠããã®äŸã§ã¯ãåã®èŠªã¯Child1ã§ãããChild1ã®èŠªã¯Child2ã§ãã
é¢æ°ãšã®é¡æšã«æ»ããšãåãã¡ã€ããŒã¯æåŸã«åŒã³åºãããé¢æ°ïŒããŒã«ãšåŒã°ããé¢æ°ïŒãšèããããšãã§ããŸãã
ãŠã£ãããã£ã¢ã®äŸïŒ
function foo(data) { a(data); return b(data); }
ãã®äŸã§ã¯ãããŒã«ãšåŒã°ããé¢æ°ã¯bã§ãã
æ»ãå€ïŒæ»ãïŒ
æ»ããã¡ã€ããŒã¯ãããã°ã©ã ãçŸåšã®ãã¡ã€ããŒãåŠçããåŸã«æ»ãã¹ããã¡ã€ããŒã§ãã ããã¯ãã¹ã¿ãã¯ã³ã³ããã®ã¢ãã¬ã¹ãè¿ãã®ãšåãã§ãã
ãŸãã芪ç¹ç¶ãšèŠãªãããšãã§ããŸãã
ãã¡ã€ããŒã«è€æ°ã®åãã¡ã€ããŒãããå Žåãååãã¡ã€ããŒã®æ»ãå€ã¯èŠªãã¡ã€ããŒãè¿ããŸãã äžèšã®äŸã§ã¯ãChild1ãšChild2ããã®æ»ããã¡ã€ããŒã¯èŠªã§ãã
çŸåšã®ããããã£ãšãã£ãã·ã¥ãããããããã£ïŒpendingPropsããã³memorizedPropsïŒ
æŠå¿µçã«ã¯ãããããã£ã¯é¢æ°ã®åŒæ°ã§ãã çŸåšã®ãã¡ã€ããŒããããã£ã¯ãå®è¡éå§æã®ãããã®ããããã£ã®ã»ããã§ãããã£ãã·ã¥ãããããããã£ã¯ãå®è¡çµäºæã®ã»ããã§ãã
å ¥ååŸ æ©ããããã£ããã£ãã·ã¥ããããšãããã¯ãèšç®ããã«ä»¥åã®ãã¡ã€ããŒåºåãåå©çšã§ããããšãæå³ããŸãã
çŸåšã®äœæ¥ã®åªå 床ïŒpendingWorkPriorityïŒ
åªå 床ã決å®ããäœæ¥ã®éã¯ããã¡ã€ããŒã«ãã£ãŠè¡šç€ºãããŸãã React ReactPrioritylevelã®åªå 床ã¢ãžã¥ãŒã«ã«ã¯ãããŸããŸãªåªå 床ã¬ãã«ãšããããè¡šããã®ãå«ãŸããŠããŸãã
ã¿ã€ãNoWorkïŒ0ïŒã®äŸå€ããå§ããŠãæ°åã倧ããã»ã©åªå é äœãæäœã«ãªããŸãã ããšãã°ã次ã®é¢æ°ã䜿çšããŠããã¡ã€ããŒã®åªå 床ãæå®ãããã¬ãã«ããã倧ãããã©ããã確èªã§ããŸãã
function matchesPriority(fiber, priority) { return fiber.pendingWorkPriority !== 0 && fiber.pendingWorkPriority <= priority }
ãã®é¢æ°ã¯ã説æã®ã¿ãç®çãšããŠããŸãã React FiberããŒã¿ããŒã¹ã®äžéšã§ã¯ãããŸããã
ã¹ã±ãžã¥ãŒã©ãŒã¯åªå é äœãã£ãŒã«ãã䜿çšããŠãå®è¡å¯èœãªæ¬¡ã®äœæ¥åäœãèŠã€ããŸãã ãã®ã¢ã«ãŽãªãºã ã«ã€ããŠã¯ã次ã®ã»ã¯ã·ã§ã³ã§èª¬æããŸãã
代æ¿ïŒãŸãã¯ãã¢ïŒ
ãã¡ã€ããŒã®æŽæ°ïŒãã©ãã·ã¥ïŒ-ããã¯ãç»é¢ã«åºåã衚瀺ããããšãæå³ããŸãã
éçºäžã®ãã¡ã€ããŒïŒäœæ¥äžïŒ-ãŸã æ§ç¯ãããŠããªããã¡ã€ããŒã ã€ãŸãããŸã è¿ãããŠããªãã¹ã¿ãã¯ã³ã³ããã§ãã
ãã€ã§ããã³ã³ããŒãã³ãã®æ¬è³ªã¯ãçŸåšã®ç¶æ ã®ç¹ç¶ãæŽæ°ãããç¹ç¶ããŸãã¯éçºäžã®ç¹ç¶ã«å¯Ÿå¿ããç¹ç¶ã®ç¶æ ã2ã€ä»¥äžããæã¡ãŸããã
çŸåšã®ãã¡ã€ããŒã®åŸã«éçºäžã®ãã¡ã€ããŒãç¶ãã次ã«ãã¡ã€ããŒãæŽæ°ãããŸãã
cloneFiberé¢æ°ã䜿çšããŠã次ã®ãã¡ã€ããŒç¶æ ãé 延äœæãããŸãã ã»ãšãã©ã®å Žåãæ°ãããªããžã§ã¯ããäœæãããšããcloneFiberã¯ããªãœãŒã¹ã®ã³ã¹ããæå°éã«æããªããã代æ¿ãã¡ã€ããŒïŒååšããå ŽåïŒã®åå©çšãè©Šã¿ãŸãã
ã¹ããŒã ãã£ãŒã«ãïŒãŸãã¯ä»£æ¿ïŒã¯å®è£ ã®è©³çŽ°ãšèããå¿ èŠããããŸãããããã¥ã¡ã³ããŒã·ã§ã³ã§ã¯é »ç¹ã«è¡šç€ºããããããèšåããããšã¯ã§ããŸããã
çµè«ã¯ãµãŒãã¹èŠçŽ ïŒãŸãã¯ãµãŒãã¹èŠçŽ ã®ã»ããïŒã§ãã ãªãŒãããŒãReactã¢ããªã±ãŒã·ã§ã³ã ãããã¯å衚瀺ç°å¢ã«åºæã§ãïŒããšãã°ããã©ãŠã¶ã§ã¯ãdivãããspanããªã©ïŒã JSXã§ã¯ããããã¯å°æåã®ã¿ã°åãšåŒã°ããŸãã
çµè«ïŒæ°ããReact v16.0ã¢ãŒããã¯ãã£ã®æ©èœãè©Šãããšããå§ãããŸã