Skip to content
Extraits de code Groupes Projets
Valider e8a1ca70 rédigé par Dan Hansen's avatar Dan Hansen
Parcourir les fichiers

WidgetCollection#subscribe now accepts a parameter that will be the context of the callback

parent 948725b9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -37,8 +37,8 @@
}
};
Diaspora.WidgetCollection.prototype.subscribe = function(id, callback) {
this.eventsContainer.bind(id, callback);
Diaspora.WidgetCollection.prototype.subscribe = function(id, callback, context) {
this.eventsContainer.bind(id, $.proxy(callback, context));
};
Diaspora.WidgetCollection.prototype.publish = function(id) {
......
......@@ -28,12 +28,7 @@
};
InfiniteScroll.prototype.start = function() {
var __bind = function(fn, me){
return function(){
return fn.apply(me, arguments);
};
};
Diaspora.widgets.subscribe("stream/reloaded", __bind(this.initialize, this));
Diaspora.widgets.subscribe("stream/reloaded", this.initialize);
this.initialize();
};
......
......@@ -58,6 +58,17 @@ describe("Diaspora", function() {
widgets.subscribe("testing/event", function() { });
expect(widgets.eventsContainer.data("events")["testing/event"]).toBeDefined();
});
it("accepts a context in which the function will always be called", function() {
var foo = "bar";
widgets.subscribe("testing/context", function() { foo = this.foo; });
widgets.publish("testing/context");
expect(foo).toEqual(undefined);
widgets.subscribe("testing/context_", function() { foo = this.foo; }, { foo: "hello" });
widgets.publish("testing/context_");
expect(foo).toEqual("hello");
});
});
describe("publish", function() {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter