Giter Site home page Giter Site logo

Comments (2)

mizchi avatar mizchi commented on June 18, 2024

一旦 pure に揃える、という話になった

from redux-pluto.

yosuke-furukawa avatar yosuke-furukawa commented on June 18, 2024
yosuke_furukawa [12:25 AM]
親が毎回ちゃんとprops意識して渡してくれたら良いけど、 {...props} とかで渡してくると関心のないpropertyも子に渡しちゃうからその時に大変っていう。ただそういう渡し方をしない、かつ、必ず渡したpropsの型定義を書く、ならPureといっしょになると思われる。
まぁでもPureComponentにして、onlyUpdateFor書かせない or ほんとうに必要な時に書く、というのが時代の流れな気もするな、、、
関数ってでも基本的に一回作って渡したら変えないけど、connectからpropsで渡しちゃうとどうなるんだっけ、参照だから変わってないはず?
この辺が確か変わるんだったような気がするんだよな。。。
onClickか何かに関数作って渡しちゃうケースが多いからかな。
ちょっと細かい話になってきたな。
https://www.sitepoint.com/optimizing-react-performance-stateless-components/
SitePoint
Optimizing React Performance with Stateless Components — SitePoint
Writing inefficient React components can cause them to rerender too often. Peter Bengtsson looks at ways of creating and optimizing stateless components.
May 4th, 2017
https://www.sitepoint.com/wp-content/themes/sitepoint/assets/images/icon.javascript.png
こうやって毎回関数を作って渡しちゃうっていう書き方すると必ず新しい関数だから一回だけbindして欲しい時とかにPureだと毎回renderされちゃう。
```render() {
    return <div>
      <h1>Users</h1>
      {
        this.state.users.map(user => {
          return <User
            name={user.name}
            highlighted={user.highlighted}
            userSelected={() => {
              this.toggleUserHighlight(user)
            }}/>
         })
      }
    </div>
  }```
この userSelected が毎回関数作っちゃう

yosuke_furukawa [12:41 AM]
ただこうやって書いちゃうとやっぱり型定義と性能を両立させるためっていう文脈でbabel-pluginで解決させる策は Pure と変わらないものになるな。。。
koichikの奴はなくてもいいやっていう気がしてきた。
型定義と性能を両立するっていうのがそもそもあんまりだな。
型定義は型定義、性能は性能って切り分けたほうが考え方はシンプル。
Flowは書くけど、onlyUpdateForは必要に応じて書く。
僕の中ではスッキリした。なくていいやって結論になった。
flowtypeの型定義の強力さを受け入れるならonlyUpdateForはぶっちゃけ邪魔なんだな、、、そして性能を両立させようとすると型定義が曖昧になる。
型定義厳密にすると性能が落ちる
落ちるというかPureと変わらなくなる。

=> 型定義の厳密性と性能の両方を取ろうとすると中途半端になりがち && 設計が難しくなるので、一旦シンプルにDXを取って型定義の厳密さを採用。性能は別途都度でやったほうが良い。その時の啓蒙も合わせてする。

from redux-pluto.

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.