1
votes

I am using Ember with Ember Data and the LocalStorage Adapter and I'm looking for a way to force ember to reload the data from the localstorage and update the UI accordingly.

However, I have no idea how to manually force a reload from outside of Ember. Basically I am looking for something like this:

function reloadAssets() {
  App.ApplicationAdapter.init(); // Cannot be called
}

My initial idea was to just call the init() method of the LS Application Adapter, but this is not possible.

1
Can you explain your workflow/lifecycle of a record?Kingpin2k

1 Answers

1
votes

You might want to reconsider your application architecture if you can. But without knowing more, check out Ember.Instrumentation. Not sure if this is the best way, but maybe it can help you.

You can use this to send send signals/events from outside of Ember into Ember.

// use jQuery to setup a click handler outside of Ember that will send
// Ember an an 'html.click' event that we defined
$('html').click(function(evt) {
  Ember.Instrumentation.instrument('html.click', evt);
});

Inside of Ember, you can define what happens when that event is detected:

// maybe in a route
Ember.Instrumentation.subscribe('html.click', {
  before: function(name, timestamp, payload) {
    this.send('handleHtmlClick', payload);
  },
  after: function(){}
});

I think you could do this to force an Ember route transition to have the records reloaded from the LSA.