Comments (5)
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.
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.
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.
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.
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)
- ComponentBase HOT 4
- _buildState called on unmounted component HOT 3
- Proposal: Automatic Release HOT 1
- Non Singleton Usage of Store breaks the subscription keys HOT 1
- Discussion: Any examples on stores subscribing to other stores? HOT 2
- ReSub v2 setState not working? HOT 19
- Types Error in AutoSubscribe.spec.tsx
- Compatibility with Preact HOT 1
- Problem with _buildState + componentDidMount in same component HOT 3
- List ReSub extensions in README HOT 1
- React 18+ in StrictMode: _buildState is not triggered on state change HOT 9
- This repo is missing important files
- React 17 / state of maintenance HOT 3
- ComponentBase: Consider setState(updater) instead of setState(object)
- ComponentBase: Prevent _buildState re-entry HOT 3
- Avoid using lodash.bind as it calls Function#toString
- [discussion] Update ReSub to support the latest React HOT 20
- assert/production
- [discussion] ReSub Hook API HOT 6
- Compiler error using @key decorator HOT 21
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from resub.