Skip to content

Instantly share code, notes, and snippets.

@jcreamer898
Created July 13, 2012 21:18
Show Gist options
  • Save jcreamer898/3107540 to your computer and use it in GitHub Desktop.
Save jcreamer898/3107540 to your computer and use it in GitHub Desktop.
Using amplifyjs as with RequireJS 2.0

Using AmplifyJS with RequireJS 2.0

With the lastest version of Require, a new config object was introduced, the shim.

http://requirejs.org/docs/api.html#config-shim

That allows Amplify to now be used within AMD projects.

Have Fun!

define(["amplify", "someModule"], function (amplify, someModule) {
var app = {
init: function () {
amplify.publish("do-it");
}
};
return app;
});
<!DOCTYPE html>
<html>
<head>
<title>AmplifyJS with RequireJS</title>
</head>
<body>
<h1>Amplify</h1>
<script src="js/require-jquery.js" data-main="js/main"></script>
</body>
</html>
require.config({
paths: {
"amplify": "lib/amplify.min"
},
shim: {
"amplify": {
deps: ["jquery"],
exports: "amplify"
}
}
});
require(['app'], function (app) {
app.init();
});
define(["amplify"], function (amplify) {
var someModule = function () {
amplify.subscribe("do-it", this.doIt);
};
someModule.prototype.doIt = function () {
console.log("It's done");
};
return new someModule();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment