Delay the readiness of the deber.js application until the initial ajax call returns

(using Ember 1.0.pre )

When the Ember.js application is first loaded for this user, I would like to make one ajax call and not load the data associated with the ember-data data until this single call returns. Here is what I think I need to do, but I'm not sure how to implement it:

  • implement ready() in the application
  • calling deferReadiness() in the application
  • initiate ajax call
  • call advanceReadiness() in ajax callback handler

I do not know how and where I need to call deferReadiness() . This is what I tried and its result:

 SocialRoi = Ember.Application.create({ ready: function() { this.deferReadiness(); console.log('SocialRoi almost ready...'); this.advanceReadiness(); return this._super(); } }); // RESULT: // Uncaught TypeError: Object SocialRoi has no method 'deferReadiness' 

Any ideas what I'm doing wrong? Is there a better approach to achieving my goal? Thanks.

+4
source share
2 answers

You can do something similar, for example, to use Ember with SignalR.

 APP = Ember.Application.create({ appname: "MyEmberApp", ready: function () { console.log("hello from ember"); if (Ember.empty($.connection.hub) || !$.connection.hub.stateChanged) { alert('SignalR error'); return; } } }); APP.deferReadiness(); $.connection.hub.url = 'http://localhost:8085/signalr'; $.connection.hub.logging = true; $.connection.hub.start() .done(function () { console.log("SignalR started!"); APP.advanceReadiness(); }) .fail(function () { alert('SignalR error)'; }); APP.Router = Ember.Router.extend({ ... }); APP.initialize(); 
+4
source

I get an error when initialize called. I needed to delay the start of my Ember application, which works in Cordoba, until the launch of Couchbase Lite. It looks like this:

 App = Ember.Application.create() App.deferReadiness() ⋮ ;( function() { function checkURL() { if( ! window.cblite ) { console.error( 'couchbase lite not present' ) } else { cblite.getURL( function( err, url ) { var adapter = App.__container__.lookup('store:main').adapterFor( 'application' ) url = url.substring( 0, url.length - 1 ) Ember.set( adapter, 'host', url ) App.advanceReadiness() ⋮ 
0
source

Source: https://habr.com/ru/post/1434655/


All Articles