Comments (4)
@dabit3 In our usage or ReSub, we've actually defined a ReadOnlyArray type that we often return from stores to prevent exactly these classes of issues.
interface ReadOnlyArray<T> {
readonly [n: number]: T;
readonly length: number;
concat(...items: (T | T[])[]): ReadOnlyArray<T>;
}
from resub.
@dabit3 I believe you've actually found a bug in the example :(
Data returned from stores should be immutable (using typescript readonly is a good way to do that for the objects, but arrays can be tricky). If you mutate an object in a store, you end up changing the value in the component since it wasn't deep cloned before returning (for perf reasons)
instead of:
addTodo(todo: String) {
this._todos.push(todo);
this.trigger();
console.log('t_todos:', this._todos)
}
do
addTodo(todo: String) {
this._todos = this._todos.concat(todo);
this.trigger();
console.log('t_todos:', this._todos)
}
I'll update the example
from resub.
Awesome, that worked! Thanks for your help.
from resub.
@berickson1 Ah nice, thanks for this!
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.