Comments (10)
mobx only supports sync batches, so no. your best bet would be to delay all state mutations at the end of the flow
from mobx-keystone.
In theory it should batch AFAIK, since it executes inside the same acttion
from mobx-keystone.
Well actually you should probably wrap the array for each with a mobx action / runInAction (or even better, as much as possible from that method) if it is not inside a modelAction or reaction
from mobx-keystone.
Summarizing, changes will batch as long as they are inside action, runInAction, reaction effect, modelAction or modelFlow
from mobx-keystone.
Cool, I will reopen it if I find a case where it's not, thank you!
from mobx-keystone.
Summarizing, changes will batch as long as they are inside action, runInAction, reaction effect, modelAction or modelFlow
Are you sure about this? I'm trying to do something like this:
@modelFlow
addNotes = _async(function* (this: NoteStore) {
console.log('pushing note1')
const note1 = Note.build({title: 'note1'})
this.notes.push(note1)
yield* _await(delay(50))
console.log('pushing note2')
const note2 = Note.build({title: 'note2'})
this.notes.push(note2)
console.log('all pushed!')
})
Then, I have this observer watching for changes of notes:
autorun(() => {
console.log(`current notes count: ${this.notes.length}`)
})
The observer is getting called after each note is added. Isn't it supposed to be called once after entire modelFlow
is finished?
from mobx-keystone.
in model flows batches are done between yield and yield
from mobx-keystone.
Oh. Is there any way to get it to execute an entire flow like that in one batch?
from mobx-keystone.
Sorry to bother you again, but I have one more question:
What's the use of modelFlow
if it doesn't really batch updates? You could just create async function on your model and use await, and it would be the same, no?
from mobx-keystone.
the reason is the same than why mobx flow exists
https://www.mobxjs.com/best/actions.html
from mobx-keystone.
Related Issues (20)
- How to provide default/fixed value for inheriting class? HOT 4
- Mental model and idea behind keystone's tweaks/patches related to mobx observe
- Root Registry / Backrefs with deep observation HOT 5
- Keystone types supporting `onActionMiddleware` HOT 3
- Is it valid to start actions in onActionMiddleware's onStart/onFinish? HOT 2
- How to listen "initial" onPatches on RootStore?
- incorrect detaches from root store when applying snapshot HOT 4
- model does not detached from root store if it in array HOT 4
- Exception when detaching model that have active reaction with reference HOT 4
- Not able to access static methods of parent class from child class when inheriting with generic types. HOT 1
- Does it support Typescript 5.X features? HOT 3
- Unnecessary loops causes low performance, how to optimize the performance HOT 2
- Binary data in models HOT 3
- getRootStore returns undefined. HOT 5
- yjs Map not recommended for key-value data. HOT 4
- Thank you HOT 2
- WeakMap key must be an Object HOT 5
- Getting 'extendObservable' only accepts plain objects as second argument HOT 1
- onInit does not execute from static creation method HOT 3
- No static checks to prevent assignment outside of an action HOT 2
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 mobx-keystone.