Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
How to wait until all ViewModel formulas are done changing in ExtJS?

I'm working with the Ext JS framework. We have a fairly complex ViewModel with many formulas bound to other formulas. I'd like to be able to run some code only once the ViewModel has finished its long cascade of events triggering events. I'm trying to verify that, after all the ViewModel formulas have calculated, whether or not the data model remains identical to the expected values for the calculated fields returned from our API -- basically a deferred model.isDirty() check.

I've tried using setTimeout to add my event to the end of the event queue, but it sometimes ends up firing in the middle of the formula-updating cascade. I could simply set a longer timeout, but that feels kludgey, would force the user to wait longer, and can't be guaranteed to work on a particularly slow browser.

Is there a good way to run code as soon as the ViewModel is done calculating, and not a moment sooner?

Is there a way to check whether or not the ViewModel is done?

Is there a way to defer an event similarly to setTimeout, but to run only after the event queue becomes entirely empty?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I've solved my own problem.

In Ext JS version 7.3.1, you can inspect the scheduledCount member of the ViewModel's Scheduler, to find out whether any ViewModel formulae are waiting to run. If the value is zero, you can be sure the ViewModel has finished calculating.

const scheduler = this.getViewModel().getScheduler();

setTimeout(awaitViewModelFinished, 0);
function awaitViewModelFinished() {
    if (scheduler.scheduledCount > 0) {
        setTimeout(awaitViewModelFinished, 0);
        return;
    }

    // Payload code goes here.
}

I couldn't find a supported feature of the framework to do this. Per the sencha docs, "[Scheduler] is a private utility class for internal use by the framework. Don't rely on its existence." If you're using another Ext JS version, you may need to find a similar but different solution for this.

about 4 years ago · Juan Pablo Isaza Report

0

Inside the controller you can use:

// come viewModel options might not be resolved

this.getViewModel().notify();

// all viewModel options are solved

!!Careful: if a binding is null the bound formula won't run.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!