Giter VIP home page Giter VIP logo

Comments (5)

berickson1 avatar berickson1 commented on May 17, 2024

You're correct, immutable data and shallow checks would be more efficient, however we decided to let consumers make their own decisions with respects to data immutability. In our uses of ReSub we have large amounts of immutable data (enforced by typescript compiler using readonly attributes) and have provided a custom comparator to detect when we're using immutable structures and do a shallow comparison.

We left the ability for consumers of ReSub to provide their own callback for props and state equality checking, so you could choose to use a shallow comparator there.
import ReSubOptions from 'resub/dist/src/Options'; ReSubOptions.shouldComponentUpdateComparator = ReSubOptions.shouldComponentUpdateComparator = <T extends {}>(a: T, b:T ): boolean => { // Custom equality logic goes here return true }

from resub.

joewood avatar joewood commented on May 17, 2024

Could you add a special base class as a PureComponent? The problem with mutating state is that there are many community components that are optimized to not update through mutated prop changes. I think this is one of the reasons why the reducer approach in redux has become popular.

from resub.

ms-deregtd avatar ms-deregtd commented on May 17, 2024

Can you possibly list some examples of these? I'm confused how a component that doesn't respond to props changes is supposed to work, or what its purpose would be.

from resub.

joewood avatar joewood commented on May 17, 2024

Any React component that is built on React.PureComponent will only update on a shallow property change comparison. This is common for components built to be used with a high level of data changes (e.g. real time dashboards etc..). It's a React best practice to use immutable data structures

from resub.

berickson1 avatar berickson1 commented on May 17, 2024

I made some changes in #96 that brings shouldComponentUpdate back to returning true (inline with React's guidance)
If you want a proxy for React.PureComponent you can implement a custom comparator that does a shallow comparison of props and state. You can either apply this globally to all components or utilize the decorator with custom comparator as seen in #96

from resub.

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.