Git Product home page Git Product logo

Comments (9)

japgolly avatar japgolly commented on July 4, 2024

What this does is configure shouldComponentUpdate to compare equality of props & state.
Concept is good, JS implementation isn't what we want for Scala.

Better would be to add something applicable via ReactComponentB.configure that uses scalaz.Equal for comparison, or plain == for dangerous people.

from scalajs-react.

japgolly avatar japgolly commented on July 4, 2024

Bloody callbacks stuff up Props equality... Might need to introduce a mechanism for callback identity and comparison.

from scalajs-react.

Odomontois avatar Odomontois commented on July 4, 2024

+1 First thing i was sad about.

from scalajs-react.

japgolly avatar japgolly commented on July 4, 2024

A better equivalent of this will be in the next version of scalajs-react.
(Better because the JS version 1) has an issue, 2) doesn't play with with Scala, 3) give no guarantees).

Release should be out in under a month.

from scalajs-react.

ngbinh avatar ngbinh commented on July 4, 2024

Awesome!

from scalajs-react.

Odomontois avatar Odomontois commented on July 4, 2024

Right now i'm using this workaround.

implicit class ReactCompBExt[Props, State, Backend](comp: ReactComponentB[Props, State, Backend]) {    
    def pure = shouldUpdateS { case (was, toBe) => was != toBe }

    def shouldUpdate(f: ((Props, Props)) => Boolean) = comp.shouldComponentUpdate(
      (scope, newProps, _) => f(scope.props, newProps))

    def shouldUpdateS(f: (((Props, State), (Props, State))) => Boolean) = comp.shouldComponentUpdate(
      (scope, newProps, newState) => f((scope.props, scope.state), (newProps, newState))
    )
  }

I could say nothing about performance yet though

from scalajs-react.

japgolly avatar japgolly commented on July 4, 2024

Using universal equality is dangerous in that when you, maybe now, maybe later, slip something in your props or state for which == doesn't hold, you're not going to know unless you pay close attention at runtime and then investigate back. The Scala compiler is not your friend and will not help you.

This is especially an issue when you pass callbacks around (which is the norm). How would one expect Scala to compare functions? By reference? Most callbacks will be regenerated unless you've structured them a very special way, and again, because the compiler's not involved there's no way of knowing whether you're doing it wrong and are going to break shouldComponentUpdate on every call.

It's unpleasant but it's a real issue. It's something to be aware of when using an approach like above.

I have a solution for these issues. I'll try to get it online well before the release so they can be critiqued. Feedback is always appreciated and just now looking at your snippet there's already a case I didn't touch - state comparison (I only use props comparison).

from scalajs-react.

japgolly avatar japgolly commented on July 4, 2024

I've created a branch for the performance management stuff that will go into 0.9.0 and added tools that address this issue.

Read all about it here:
https://github.com/japgolly/scalajs-react/blob/0.9/extra/PERF.md

This will go out in 0.9.0 in about a month's time, and close this issue.

from scalajs-react.

japgolly avatar japgolly commented on July 4, 2024

Closed via 9e8f5bd

from scalajs-react.

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.