Giter Site home page Giter Site logo

Comments (10)

xaviergonz avatar xaviergonz commented on May 18, 2024 1

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.

xaviergonz avatar xaviergonz commented on May 18, 2024

In theory it should batch AFAIK, since it executes inside the same acttion

from mobx-keystone.

xaviergonz avatar xaviergonz commented on May 18, 2024

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.

xaviergonz avatar xaviergonz commented on May 18, 2024

Summarizing, changes will batch as long as they are inside action, runInAction, reaction effect, modelAction or modelFlow

from mobx-keystone.

terrysahaidak avatar terrysahaidak commented on May 18, 2024

Cool, I will reopen it if I find a case where it's not, thank you!

from mobx-keystone.

vojto avatar vojto commented on May 18, 2024

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.

xaviergonz avatar xaviergonz commented on May 18, 2024

in model flows batches are done between yield and yield

from mobx-keystone.

vojto avatar vojto commented on May 18, 2024

Oh. Is there any way to get it to execute an entire flow like that in one batch?

from mobx-keystone.

vojto avatar vojto commented on May 18, 2024

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.

xaviergonz avatar xaviergonz commented on May 18, 2024

the reason is the same than why mobx flow exists
https://www.mobxjs.com/best/actions.html

from mobx-keystone.

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.