Created
February 15, 2012 21:17
-
-
Save rauhryan/1839061 to your computer and use it in GitHub Desktop.
Some real world examples
This file contains 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
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); | |
} | |
}); | |
}); | |
} | |
}; | |
}); |
This file contains 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
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; | |
}); |
This file contains 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
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