Upgrade to Pro — share decks privately, control downloads, hide ads and more …

React Reconciler: как написать собственный ренд...

React Reconciler: как написать собственный рендерер

Что такое "реконсиляция" в React и какой путь проходит компонент от кода до отрисовки на экран, какие рендереры уже существуют и как написать свой собственный на примере отрисовки React-компонентов в Figma

Дополнительные материалы: https://github.com/LosYear/react-reconciler-talk

Yaroslav Losev

March 19, 2020
Tweet

More Decks by Yaroslav Losev

Other Decks in Programming

Transcript

  1. function components hooks class components lifecycle ref suspense context concurrent

    mode error boundaries key prop div span img props state
  2. function components hooks class components lifecycle ref suspense context concurrent

    mode error boundaries key prop div span img View Text Image props state
  3. ref suspense context props class components function components hooks concurrent

    mode error boundaries lifecycle key prop div span img View Text Image state Host-components Reconciler
  4. const App = ({username}) => React.createElement( 'div', className: 'app', },

    React.createElement( 'p', null, 'Hello, ', username, '!' ), ); createElement const App = ({username}) => ( <div className="app"> <p>Hello, {username}!</p> </div> ); !=> {
  5. const App = ({username}) => React.createElement( 'div', className: 'app', },

    React.createElement( 'p', null, 'Hello, ', username, '!' ), ); createElement const App = ({username}) => ( <div className="app"> <p>Hello, {username}!</p> </div> ); !=> {
  6. const App = ({username}) => React.createElement( 'div', className: 'app', },

    React.createElement( 'p', null, 'Hello, ', username, '!' ), ); createElement const App = ({username}) => ( <div className="app"> <p>Hello, {username}!</p> </div> ); !=> {
  7. const App = ({username}) => React.createElement( 'div', className: 'app', },

    React.createElement( 'p', null, 'Hello, ', username, '!' ), ); createElement const App = ({username}) => ( <div className="app"> <p>Hello, {username}!</p> </div> ); !=> {
  8. createElement const App = ({username}) => ( <div className="app"> <p>Hello,

    {username}!</p> </div> ); !=> { const App = ({username}) => React.createElement( 'div', className: 'app', }, React.createElement( 'p', null, 'Hello, ', username, '!' ), );
  9. React Element { $$typeof: Symbol(react.element), type: 'div', props: { className:

    'app', children: { $$typeof: Symbol(react.element), type: 'p', props: { children: ['Hello', ‘tver.io’, '!'], }, }, }, }
  10. Reconciler Renderer • Оперирует деревьями • UI agnostiс • Отрисовывает

    представление в конкретной среде • UI dependent
  11. React Native const WelcomeScreen = () => ( <View> <Header

    title="Welcome to React Native" /> <Text style={header}>Step One</Text> <Text>Edit App.js to change this screen and turn it into your app.</Text> … </View> );
  12. Ink const Counter = () => { const [i, setI]

    = useState(0); useEffect(() => { setInterval(() => { setI(prev => prev + 1); }, 100); }, []); return <Color green> {i} tests passed </Color>; };
  13. React Hardware const App = () => { const [ledState,

    setLedState] = useState(false); useEffect(() => { setInterval(() => { setLedState(prev => !prev); }, 1000); }, []); return <Led pin={13} value={ledState ? 255 : 0} />; }; const PORT = '/dev/tty.usbmodem1411'; ReactHardware.render(<App />, PORT);
  14. React Figma const App = () => ( <Frame name="Awesome

    frame"> <Rectangle name="More awesome rectangle" width={200} height={100} backgroundColor="#dd55aa" /> </Frame> );
  15. +

  16. ☹ Мало документации ☹ “Use it at your own risk”

    ☹ Иногда интегрироваться с host-environment сложно