Skip to content

Instantly share code, notes, and snippets.

@thehydroimpulse
Created January 12, 2013 17:11
Show Gist options
  • Select an option

  • Save thehydroimpulse/4519348 to your computer and use it in GitHub Desktop.

Select an option

Save thehydroimpulse/4519348 to your computer and use it in GitHub Desktop.
// Define a file.
// This allows us to use dependency injection file-wide, instead of class/function wide.
// This brings some simplicity to each file, as each will have
// a base, common framework.
File.define('framework', function(router, jsonController){
// As stated below, we want to listen on this error, otherwise the system will automatically
// trigger an error.
this.on("error", function(error){
console.log("We have an error: " + JSON.stringify(error));
throw Error(error);
});
// The dependency "router" can only be of type Ember.Oject.
// This simulates types sorta in other languages (Java, PHP)
// It does involve adding an extra step, instead of this feature being
// on the language level, but it'll work for now.
//
// If lock returns false, it'll emit/trigger an error, unless you listen on the
// "error" event.
this.lock({
[router, Ember.Object],
[jsonController, Tower.get('baseController')]
});
// Accessing modules through a service locator:
// A service locator is an alternative to dependency injection, and is
// a lot simpler, though the syntax might be a little different.
var services = Tower.get('Services');
var authentication = Tower.get('Authentication');
// Let's include another File module.
// You NEED to know about the file you are using and what it expects.
// otherwise, you'll set off some errors.
// You simply call the function and pass parameters as an array.
// This will run the async method.
var net = File.require('netConnections', ['firstParameter', sevices, authentication]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment