Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Some real world examples
define("jquery", function () {
return {
post: function (url, data, callback) {
callback( {
successful: true,
error: true,
message: "yo dawg!"
});
}
};
});
define("messagebus", function () {
return {
publish : function (topic, data) {
console.log(topic, data);
}
}
});
extend("policies", function () {
return function (policies){
var policy = {
matches : function (context) {
/* always execute */
return true;
},
execute : function (data) {
console.log("data:received", data);
}
}
policies.push(policy);
return policies;
};
});
extend("policies",["messagebus"], function (bus) {
return function (policies){
var policy = {
matches : function (context) {
/* only execute when */
return context.successful;
},
execute : function (data) {
bus.publish("successful", data);
}
}
policies.push(policy);
return policies;
};
});
extend("policies",["messagebus"], function (bus) {
return function (policies){
var policy = {
matches : function (context) {
/* only execute when */
return context.error;
},
execute : function (data) {
bus.publish("failure", data);
}
}
policies.push(policy);
return policies;
};
});
define("policies", function () {
return [];
});
define("fooModel",["jquery","policies"], function ($, policies) {
return {
save: function (attributes) {
$.post("/foo", attributes,function (data) {
policies.forEach(function(policy) {
if(policy.matches(data)){
policy.execute(data);
}
});
});
}
};
});
extend("backboneView", ["jquery","underscore","backbone"], function ($, _, Backbone) {
var extendedView = Backbone.View.extend({/* ... */});
return function (bbView) {
var oldRender = bbView.prototype.render;
bbView.prototype.render = function () {
var rendered = oldRender.call(this,arguments);
var myView = new extendedView();
this.on("someevent", function () {
myView.trigger("someotherevent");
});
return rendered;
}
return bbView;
}
});
define("backboneView", ["jquery","underscore","backbone"], function ($, _, Backbone) {
var bbView = Backbone.View.extend({
render: function () {
/* do stuff */
return this;
}
});
return bbView;
});
extend('jquery', function() {
return function($) {
$.fn.myplugin = function () {/*...*/}
return $;
}
});
define("fooView", ["jquery"], function ($) {
return {
init: function () {
$("#view").myplugin({/*..*/});
},
destory: function () {
$("#view").empty();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.