4
votes

I have web app and Ember app in iframe. I want to import custom library from web app to ember app like global variable. Library look like object with function:

var helpers = {
    helper1: function() {},
    helper2: function() {}
};

Library working with sockets and will the same for both applications.

I wrote:

app.import("./../../../public/scripts/js-helpers.js"); //file located in web app 

I can't access variable helpers in project and ember-cli copy folder public into their working folder. Sorry if question is stupid, I can't understand ember-cli import principles.

1

1 Answers

7
votes

I'll propose one solution, which I find to be the easiest. You won't have globally scoped variables, but you use then ES6 module approach.

For example purposes, let's say you have a file under app_name/lib/ called helper.js. lib is a directory you create for holding your custom libraries. You don't have to use that name. Use the export default command as such:

export default {
    helper1: function() {},
    helper2: function() {}
};

Then, lets say you need this in a route. Here could be one such route:

import helper from 'app_name/lib/helper';

export default Ember.Route.extend({
   model: function(){
      helper.helper1();
}

helper is the name of what you imported, and represents the object that you exported in your helper.js. This method seems to be the style in which Ember-CLI suggests you should use