0
votes

My question is very basic on one hand but on the other hand the general situation is more complex, plus I cannot really get any working sample.

I'm developing/maintaing a web-application which is currently in transition from GWT code base into Ember.js.

Most of the newer code already relies on Ember.js and I think it's really awesome. The problem is we cannot use Ember Router as all the request are being handled by the GWT. In order to enabled the application run in this unusual configuration we have special JavaScript files that create our Ember main objects (Controllers & Models) for us.

As you can imagine navigation between tabs is cumbersome and is handled by GWT who creates Ember objects when needed. We are in transit toward a brave new world Ember Router and all.

But in the meantime, this is the problem I'm facing right now.

The user clicks a link which opens a page that contains some Ember based table. The data is retrieved form the server using some Ajax code. Upon success it spawns a forEach loop which tries to pushObject all the received date into our Ember based components.

My problem happens when the user quickly switches between tabs. In this case the first list of object has not finished rendering yet and suddenly there's a new set of objects to handle. This causes Ember to throw errors like: "Uncaught Error: Cannot perform operations on a Metamorph that is not in the DOM. "

and

"Uncaught NotFoundError: An attempt was made to reference a Node in a context where it does not exist."

Is it possible to prevent the loop from trying to render? I've tried checking if the controller in question is already inDOM and it is, is there a way to notify Ember this object is no longer valid?

Sorry for a lengthy question and lack of running sample.

2
In your gwt tabs, can you execute some javascript before the tab change?Marcio Junior
I am doing so alreadyJust2Click

2 Answers

1
votes

I'd probably modify the switch tab code to only execute afterRender has completed, that way you aren't mucking with ember objects while they are being used.

  Ember.run.scheduleOnce('afterRender', this, function(){
    // call GWT switch tab routine
  });
0
votes

Thank you Daniel and Márcio Rodrigues Correa Júnior. eventually what I did is to add a patch that would check the current context of the application (in my case the currently selected tab). If upon receiving the AJAX response the application is in the correct context (meaning the user haven't change the tab) go on. Otherwise just ignore the response and do not try to render it.

Now it seems to be working