Skip to content

Instantly share code, notes, and snippets.

@sir-dunxalot
Last active August 29, 2015 13:57
Show Gist options
  • Save sir-dunxalot/9848013 to your computer and use it in GitHub Desktop.
Save sir-dunxalot/9848013 to your computer and use it in GitHub Desktop.
A simple way to load vendor javascript asynchronously in an ember-rails app

application.js

//= stub ./vendor/moment.min.js

Mixin

App.EmberGraphs = Em.Mixin.create({

  getEgApi: function() {
    var _this = this,
        url = '/assets/vendor/ember-graphs.min.js';

    $.getScript(url).done(function() {
      _this._egCallback();
    });
  }.on('willInsertElement'),

  _egCallback: function() {
    // Empty function to override in the view
  }
});

View

App.StatsView(
  App.EmberGraphs, {

  _egCallback: function() {
    // Optional override logic here
  },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment