Created
November 21, 2013 19:49
-
-
Save tbranyen/7588341 to your computer and use it in GitHub Desktop.
Automatically bind Ember Classes to the Application object with AMD.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Ember App Attach Plugin v0.1.0 | |
* Copyright 2013, Tim Branyen (@tbranyen) | |
* ember-loader.js may be freely distributed under the MIT license. | |
*/ | |
define(function(require, exports) { | |
exports.version = "0.1.0"; | |
exports.load = function(name, req, load, config) { | |
var App = require("app"); | |
req([name], function(Class) { | |
var parts = name.split("/"); | |
var fileName = parts[parts.length-1]; | |
var titleCaseName = fileName.split("_").map(function(part) { | |
return part[0].toUpperCase() + part.slice(1); | |
}).join(""); | |
// Attach to Ember Application. | |
App[titleCaseName] = Class; | |
return config.isBuild ? load() : load(Class); | |
}); | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require({ | |
paths: { 'emAttach': 'em-attach' } | |
}, [ | |
'app', | |
'emAttach!user/user_model' | |
], function(App, UserModel) { | |
console.log(App.UserModel === UserModel); | |
// => true | |
}); |
Stef's resolver won't work with out of the box AMD because it expects some special ES6 module transpiler stuff (namely export called default
instead of the actual return value).
Either way, it won't work w/ async RequireJS because async resolution is a crazy can of worms that no one wants to open right now. Easier to just concat + source maps :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out Ember resolvers instead. This one works well with AMD: https://github.com/stefanpenner/ember-jj-abrams-resolver and I have one in progress for use with webpack: https://github.com/shama/ember-webpack-resolver