Skip to content

Commit

Permalink
fix issue with context of initialize with latest value call
Browse files Browse the repository at this point in the history
fixes #20
  • Loading branch information
rniemeyer committed Dec 10, 2013
1 parent 26b0cc4 commit 083feed
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "knockout-postbox",
"version": "0.4.0",
"version": "0.4.2",
"main": "build/knockout-postbox.min.js",
"dependencies": {
"knockout": ">= 2.0"
Expand Down
4 changes: 2 additions & 2 deletions build/knockout-postbox.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// knockout-postbox 0.4.1 | (c) 2013 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license
// knockout-postbox 0.4.2 | (c) 2013 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license
;(function(factory) {
//CommonJS
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
Expand Down Expand Up @@ -51,7 +51,7 @@
current = exports.topicCache[topic];

if (current !== undefined) {
action(current.value);
action.call(target, current.value);
}
}

Expand Down
4 changes: 2 additions & 2 deletions build/knockout-postbox.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "knockout-postbox",
"version": "0.4.1",
"version": "0.4.2",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-uglify": "0.x.x",
Expand Down
12 changes: 8 additions & 4 deletions spec/knockout-postbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,21 @@ describe("knockout-postbox", function(){
expect(callback).toHaveBeenCalledWith(newValue);
});

it("should call the callback with the appropriate target as the context during initialization", function() {
ko.postbox.publish(topic, newValue);
var newSubscription = ko.postbox.subscribe(topic, callback, target, true);

expect(callback.mostRecentCall.object).toEqual(target);
});

it("should not execute callback before publish", function() {
var newSubscription = ko.postbox.subscribe(topic, callback, target, true);
expect(callback).not.toHaveBeenCalled();
ko.postbox.publish(topic, newValue);
expect(callback).toHaveBeenCalledWith(newValue);
});

describe("when passing as the third argument", function(){
beforeEach(function(){
});

describe("when passing as the third argument", function() {
it("should receive the last published value", function() {
ko.postbox.publish(topic, newValue);
var newSubscription = ko.postbox.subscribe(topic, callback, true);
Expand Down
2 changes: 1 addition & 1 deletion src/knockout-postbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
current = exports.topicCache[topic];

if (current !== undefined) {
action(current.value);
action.call(target, current.value);
}
}

Expand Down

0 comments on commit 083feed

Please sign in to comment.