WidgetCollection#subscribe now accepts a parameter that will be the context of the callback
This commit is contained in:
parent
948725b946
commit
e8a1ca70e3
3 changed files with 14 additions and 8 deletions
|
|
@ -37,8 +37,8 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Diaspora.WidgetCollection.prototype.subscribe = function(id, callback) {
|
Diaspora.WidgetCollection.prototype.subscribe = function(id, callback, context) {
|
||||||
this.eventsContainer.bind(id, callback);
|
this.eventsContainer.bind(id, $.proxy(callback, context));
|
||||||
};
|
};
|
||||||
|
|
||||||
Diaspora.WidgetCollection.prototype.publish = function(id) {
|
Diaspora.WidgetCollection.prototype.publish = function(id) {
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
InfiniteScroll.prototype.start = function() {
|
InfiniteScroll.prototype.start = function() {
|
||||||
var __bind = function(fn, me){
|
Diaspora.widgets.subscribe("stream/reloaded", this.initialize);
|
||||||
return function(){
|
|
||||||
return fn.apply(me, arguments);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
Diaspora.widgets.subscribe("stream/reloaded", __bind(this.initialize, this));
|
|
||||||
this.initialize();
|
this.initialize();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,17 @@ describe("Diaspora", function() {
|
||||||
widgets.subscribe("testing/event", function() { });
|
widgets.subscribe("testing/event", function() { });
|
||||||
expect(widgets.eventsContainer.data("events")["testing/event"]).toBeDefined();
|
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() {
|
describe("publish", function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue