Personal, generic, javascript code. Where to put? Application component? Application.create ready() function?

I’m using Ember 2.7.0 of course with ember-cli.

I come from Rails, I used to put in “assets/application.js” all my javascript like, for example:

var ready = function () {

	myFunction('test');

	$('#btn-fluid').on('click', function () {
		$('#myPage').toggleClass('container')
	});
}

document.addEventListener("turbolinks:load", function () {
	ready()
})

Now with Ember where I have to put this code in my application?

I read on the web the use of:

Ember.Application.create({
   ready: function () {
});

but I don’t know how to put this code: in app.js maybe, but I already have:

App = Ember.Application.extend({
  modulePrefix: config.modulePrefix,
  podModulePrefix: config.podModulePrefix,
  Resolver
});

and if I create another file in the root, like for example “mycode.js” like this:

import {Ember} from 'ember';

let myCode;

myCode = Ember.Application.create({
  ready: function () {
    console.log('Test!');
  }
});

export default myCode;

and import it in application using ember-cli-build.js here:

… app.import(‘mycode.js’);

it compile the big js with my code, but it doesn’t work at all my ready function.

How to do?

I have to use Components? Maybe an application component?

Which is the best Ember way for top performances?

1 Like