Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

start of demo

  • Loading branch information...
commit 1bb9adaa93e974987a2abfc6eda2a5355388ca36 1 parent d8e97e9
Kevin Hakanson authored
63 demo.html
... ... @@ -0,0 +1,63 @@
  1 +<!DOCTYPE HTML>
  2 +<html>
  3 + <head>
  4 + <title>Demo</title>
  5 + <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6 + <script type="text/javascript">window.JSON || document.write('<script src="json2.js"><\/script>')</script>
  7 + <script type="text/javascript" src="jquery-1.6.3.js"></script>
  8 + <script type="text/javascript" src="OpenAjax.js"></script>
  9 + <script type="text/javascript" src="jquery-hub.js"></script>
  10 +
  11 + <script type="text/javascript">
  12 + $( document ).ready(function () {
  13 + var counter = 0;
  14 + function reset() {
  15 + $( "#name" ).val( "" ).focus();
  16 + $( "#key" ).val( "" );
  17 +
  18 + $ ( "#save" ).prop( "disabled", true );
  19 + $ ( "#cancel" ).prop( "disabled", true );
  20 + }
  21 + $( "#name" ).change(function () {
  22 + $ ( "#save" ).prop( "disabled", !$( this ).val() );
  23 + $ ( "#cancel" ).prop( "disabled", !$( this ).val() );
  24 + });
  25 + $( "#name" ).keyup(function() {
  26 + $( this ).change();
  27 + });
  28 + $( "#save" ).click(function () {
  29 + if ( $( "#key" ).val() ) {
  30 + $( "#" + $( "#key" ).val() ).text( $( "#name" ).val() );
  31 + } else {
  32 + $( "#list ul" ).append( "<li id='key" + counter++ + "'>" + $( "#name" ).val() + "</li>" );
  33 + }
  34 +
  35 + reset();
  36 + });
  37 + $( "#cancel" ).click(function () {
  38 + reset();
  39 + });
  40 +
  41 + $( "#list ul li" ).live("click", function() {
  42 + $( "#name" ).val( $( this ).text() ).change().focus();
  43 + $( "#key" ).val( $( this ).attr( "id" ) );
  44 + });
  45 + });
  46 + </script>
  47 + </head>
  48 + <body>
  49 + <h1>Demo</h1>
  50 + <div id="edit" style="border: 1px solid;">
  51 + <h2>Edit Widget</h2>
  52 + <label for="name">Name:</label> <input id="name" type="text" />
  53 + <input id="save" type="button" value="save" disabled />
  54 + <input id="cancel" type="button" value="cancel" disabled />
  55 + <input id="key" type="hidden" />
  56 + </div>
  57 +
  58 + <div id="list" style="border: 1px solid; margin-top: 1em;" >
  59 + <h2>List Widget</h2>
  60 + <ul></ul>
  61 + </div>
  62 + </body>
  63 +</html>
2  tests/AmplifyTestRunner.html
@@ -3,7 +3,7 @@
3 3 <head>
4 4 <title>$.hub Test Runner</title>
5 5 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6   - <script type="text/javascript">window.JSON || document.write('<script src="../JSON/json2.js"><\/script>')</script>
  6 + <script type="text/javascript">window.JSON || document.write('<script src="..\/json2.js"><\/script>')</script>
7 7 <script type="text/javascript" src="../jquery-1.6.3.js"></script>
8 8 <link rel="stylesheet" href="qunit.css" type="text/css" media="screen"/>
9 9 <script type="text/javascript" src="qunit.js"></script>
2  tests/TestRunner.html
@@ -3,7 +3,7 @@
3 3 <head>
4 4 <title>$.hub Test Runner</title>
5 5 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6   - <script type="text/javascript">window.JSON || document.write('<script src="../JSON/json2.js"><\/script>')</script>
  6 + <script type="text/javascript">window.JSON || document.write('<script src="..\/json2.js"><\/script>')</script>
7 7 <script type="text/javascript" src="../jquery-1.6.3.js"></script>
8 8 <link rel="stylesheet" href="qunit.css" type="text/css" media="screen"/>
9 9 <script type="text/javascript" src="qunit.js"></script>
26 tests/jQueryHubTestRunner.html
... ... @@ -0,0 +1,26 @@
  1 +<!DOCTYPE HTML>
  2 +<html>
  3 + <head>
  4 + <title>$.hub Test Runner</title>
  5 + <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6 + <script type="text/javascript">window.JSON || document.write('<script src="..\/json2.js"><\/script>')</script>
  7 + <script type="text/javascript" src="../jquery-1.6.3.js"></script>
  8 + <link rel="stylesheet" href="qunit.css" type="text/css" media="screen"/>
  9 + <script type="text/javascript" src="qunit.js"></script>
  10 +
  11 + <!-- NOTE: Add references to your qunit scripts here -->
  12 + <script type="text/javascript" src="../OpenAjax.js"></script>
  13 + <script type="text/javascript" src="../jquery-hub.js"></script>
  14 +
  15 + <script type="text/javascript" src="jquery-hub.tests.js"></script>
  16 +
  17 + </head>
  18 + <body>
  19 + <h1 id="qunit-header">QUnit example</h1>
  20 + <h2 id="qunit-banner"></h2>
  21 + <div id="qunit-testrunner-toolbar"></div>
  22 + <h2 id="qunit-userAgent"></h2>
  23 + <ol id="qunit-tests"></ol>
  24 + <div id="qunit-fixture">test markup, will be hidden</div>
  25 + </body>
  26 +</html>
2  tests/jQueryTestRunner.html
@@ -3,7 +3,7 @@
3 3 <head>
4 4 <title>$.hub Test Runner</title>
5 5 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6   - <script type="text/javascript">window.JSON || document.write('<script src="../JSON/json2.js"><\/script>')</script>
  6 + <script type="text/javascript">window.JSON || document.write('<script src="..\/json2.js"><\/script>')</script>
7 7 <script type="text/javascript" src="../jquery-1.6.3.js"></script>
8 8 <link rel="stylesheet" href="qunit.css" type="text/css" media="screen"/>
9 9 <script type="text/javascript" src="qunit.js"></script>
480 tests/jquery-hub.tests.js
@@ -3,6 +3,8 @@ QUnit.testStart = function( name ) {
3 3 $.hub._reset();
4 4 };
5 5
  6 +/* part 1 */
  7 +
6 8 module( "Publish-Subscribe Channel" );
7 9
8 10 test( "subscribe will get message", function() {
@@ -24,9 +26,9 @@ test( "subscribe will get message", function() {
24 26 $.hub.unsubscribe( subscription);
25 27 });
26 28
27   -test( "wildcard subscribers", function() {
28   - var message = $.hub.message({});
29   - var subscriber1, subscriber2, subscriber3, subscriber4, subscriber5, subscriber6;
  29 +test( "wildcard subscribers get multiple messages", function() {
  30 + var message = { "x": "x" },
  31 + subscriber1, subscriber2, subscriber3, subscriber4, subscriber5, subscriber6;
30 32 var countA = 0,
31 33 countAstar = 0,
32 34 countAstarstar = 0,
@@ -75,10 +77,10 @@ test( "wildcard subscribers", function() {
75 77 });
76 78
77 79 test( "handle thrown exception", function() {
78   - // $.hub({ debug: true }); //only enable if you want your javascript debugger to breakpoint
  80 + // $.hub({ debug: true }); // only enable if you want your javascript debugger to break
79 81
80 82 var channel = "exception",
81   - message = { "a": "a" },
  83 + message = { "e": "e" },
82 84 actualMessage,
83 85 actualChannel;
84 86
@@ -96,6 +98,83 @@ test( "handle thrown exception", function() {
96 98 $.hub.unsubscribe( subscription );
97 99 });
98 100
  101 +test( "this and scope", function() {
  102 + var channel = "increment",
  103 + m1 = { "increment": 1 },
  104 + m2 = { "increment": 1 };
  105 + var subscriber1, subscriber2, subscriber3, subscriber4;
  106 +
  107 + window.count = 100; // bad this.count will leak out to window.count
  108 + var counter1 = {
  109 + count: 0,
  110 + increment: function( channel, message ) {
  111 + this.count++;
  112 + }
  113 + };
  114 + var counter2 = (function() {
  115 + var count = 200,
  116 + obj = {
  117 + increment: function( channel, message ) {
  118 + count++;
  119 + },
  120 + count: function() {
  121 + return count;
  122 + }
  123 + };
  124 + return obj;
  125 + })();
  126 +
  127 + subscriber1 = $.hub.subscribe( channel, counter1.increment ); // bug
  128 + subscriber2 = $.hub.subscribe( channel, counter1.increment, counter1 ); // scope
  129 + subscriber3 = $.hub.subscribe( channel, $.proxy( counter1.increment, counter1 ) ); // proxy
  130 +
  131 + subscriber4 = $.hub.subscribe( channel, counter2.increment ); // closure
  132 +
  133 + $.hub.publish( channel, m1 );
  134 +
  135 + equal( window.count, 101, "window.count will be incremented one time" );
  136 + equal( counter1.count, 2, "counter1.count will be incremented two times" );
  137 + equal( counter2.count(), 201, "counter2.count will be incremented one time" );
  138 +
  139 + $.hub.publish( channel, m2 );
  140 +
  141 + equal( window.count, 102, "window.count will be incremented two times" );
  142 + equal( counter1.count, 4, "counter1.count will be incremented four times" );
  143 + equal( counter2.count(), 202, "counter2.count will be incremented two times" );
  144 +
  145 + $.hub.unsubscribe( subscriber1 );
  146 + $.hub.unsubscribe( subscriber2 );
  147 + $.hub.unsubscribe( subscriber3 );
  148 + $.hub.unsubscribe( subscriber4 );
  149 +});
  150 +
  151 +/* part 2 */
  152 +
  153 +module( "Document Message" );
  154 +
  155 +test( "subscribe using message builder", function() {
  156 + var channel = "builder",
  157 + messageBody = { "key1": "value1", "key2": "value2" },
  158 + actualMessage,
  159 + actualChannel;
  160 +
  161 + var subscription = $.hub.subscribe( channel, function( channel, message ) {
  162 + actualChannel = channel;
  163 + actualMessage = message;
  164 + console.log(JSON.stringify(message));
  165 + });
  166 +
  167 + var message = $.hub.message( messageBody );
  168 + $.hub.publish( channel, message );
  169 +
  170 + equal( actualChannel, channel );
  171 + deepEqual( actualMessage.body, messageBody );
  172 +
  173 + $.hub.unsubscribe( subscription );
  174 +});
  175 +
  176 +/* part 3 */
  177 +
99 178 module( "Durable Subscriber" );
100 179
101 180 test( "subscribe will not get message", function() {
@@ -113,8 +192,8 @@ test( "subscribe will not get message", function() {
113 192 actualMessage = message;
114 193 });
115 194
116   - equal( actualChannel, null, "Subscribe happened after publish; message should have been missed" );
117   - equal( actualMessage, null, "Subscribe happened after publish; message should have been missed" );
  195 + equal( actualChannel, null, "subscribe happened after publish, message was missed" );
  196 + equal( actualMessage, null, "subscribe happened after publish, message was missed" );
118 197
119 198 $.hub.unsubscribe( subscription );
120 199 });
@@ -169,146 +248,61 @@ test( "create a hub that is not ready for publishing until triggered", function(
169 248 $.hub.unsubscribe( subscriptionB );
170 249 });
171 250
172   -module( "Message" );
173   -
174   -test( "subscribe using message builder", function() {
175   - var channel = "builder",
176   - messageBody = { "key1": "value1", "key2": "value2" },
177   - actualMessage,
178   - actualChannel;
179   -
180   - var subscription = $.hub.subscribe( channel, function( channel, message ) {
181   - actualChannel = channel;
182   - actualMessage = message;
183   - });
184   -
185   - var message = $.hub.message( messageBody );
186   - $.hub.publish( channel, message );
187   -
188   - equal( actualChannel, channel );
189   - deepEqual( actualMessage.body, messageBody );
190   -
191   - $.hub.unsubscribe( subscription );
192   -});
193   -
194   -module( "Request-Reply" );
195   -
196   -test( "subscribe using message builder with replyTo set", function() {
197   - var channel = "a",
198   - replyChannel = "b",
199   - messageBody = { "a": "a" },
200   - message = $.hub.message( messageBody ),
201   - replyMessage = $.hub.message({ "c": "c" }),
202   - correlationId,
203   - actualMessage,
204   - actualChannel,
205   - actualReplyMessage,
206   - actualReplyChannel;
207   -
208   - // listen for the request, then reply
209   - var subscription = $.hub.subscribe( channel, function( channel, message ) {
210   - actualChannel = channel;
211   - actualMessage = message;
212   - $.hub.reply(message, replyMessage );
213   - });
214   -
215   - // listen for the reply
216   - var replySubscription = $.hub.subscribe( replyChannel, function( channel, message ) {
217   - actualReplyChannel = channel;
218   - actualReplyMessage = message;
219   - correlationId = message.correlationId;
220   - });
221   -
222   - // replyTo is the channel where replies are sent
223   - message.replyTo = replyChannel;
224   - $.hub.publish( channel, message );
225   -
226   - equal( actualChannel, channel );
227   - deepEqual( actualMessage.body, messageBody );
228   -
229   - equal( actualReplyChannel, replyChannel);
230   - equal( message.messageId, correlationId);
231   - deepEqual( actualReplyMessage.body, replyMessage.body );
232   -
233   - $.hub.unsubscribe( subscription );
234   - $.hub.unsubscribe( replySubscription );
235   -});
236   -
237   -test( "subscribe using message builder with replyTo not set", function() {
238   - var channel = "a",
239   - replyChannel = "b",
240   - messageBody = { "a": "a" },
241   - replyMessage = $.hub.message({ "c": "c" }),
242   - correlationId,
243   - actualMessage,
244   - actualChannel,
245   - actualReplyMessage = null,
246   - actualReplyChannel = null;
  251 +/* part 4 */
247 252
248   - // listen for the request, then reply
249   - var subscription = $.hub.subscribe(channel, function( channel, message ) {
250   - actualChannel = channel;
251   - actualMessage = message;
252   - $.hub.reply( message, replyMessage );
253   - });
  253 +module( "Selective Consumer" );
254 254
255   - // replyTo is the channel where replies are sent
256   - var replySubscription = $.hub.subscribe( replyChannel, function( channel, message ) {
257   - actualReplyChannel = channel;
258   - actualReplyMessage = message;
259   - correlationId = message.correlationId;
260   - });
  255 +test( "createVersionFilter filters version strings", function() {
  256 + var channel = "createVersionFilter",
  257 + filter1 = $.hub.createVersionFilter( "1" ),
  258 + filter2 = $.hub.createVersionFilter( "2" ),
  259 + filter11 = $.hub.createVersionFilter( "1.1" ),
  260 + filter12 = $.hub.createVersionFilter( "1.2" ),
  261 + filter22 = $.hub.createVersionFilter( "2.2" ),
  262 + message1 = $.hub.message({}, { formatVersion: "1" }),
  263 + message2 = $.hub.message({}, { formatVersion: "2" }),
  264 + message11 = $.hub.message({}, { formatVersion: "1.1" }),
  265 + message12 = $.hub.message({}, { formatVersion: "1.2" }),
  266 + message22 = $.hub.message({}, { formatVersion: "2.2" });
261 267
262   - // forget to set the replyTo
263   - var message = $.hub.message( messageBody );
264   - $.hub.publish( channel, message );
  268 + // {major} versions
  269 + var is1 = filter1( channel, message1 );
  270 + var is2 = filter2( channel, message2 );
265 271
266   - equal( actualChannel, channel );
267   - deepEqual( actualMessage.body, messageBody );
  272 + ok( is1, "1 is version 1" );
  273 + ok( is2, "2 is version 2" );
268 274
269   - equal( actualReplyChannel, null );
270   - equal( correlationId, null );
271   - deepEqual( actualReplyMessage, null );
  275 + is1 = filter1( channel, message2 );
  276 + is2 = filter2( channel, message1 );
272 277
273   - $.hub.unsubscribe( subscription );
274   - $.hub.unsubscribe( replySubscription );
275   -} );
  278 + equal( is1, false, "2 is not version 1" );
  279 + equal( is2, false, "1 is not version 2" );
276 280
277   -test( "subscribe using message builder requestReply", function() {
278   - var channel = "a",
279   - replyChannel = "b",
280   - messageBody = { "a": "a" },
281   - message = $.hub.message( messageBody ),
282   - replyMessage = $.hub.message({ "c": "c" }),
283   - correlationId,
284   - actualMessage,
285   - actualChannel;
  281 + // {major}.{minor} versions
  282 + is1 = filter1( channel, message11 );
  283 + is2 = filter2( channel, message22 );
286 284
287   - // listen for the request, then reply
288   - var subscription = $.hub.subscribe(channel, function( channel, message ) {
289   - actualChannel = channel;
290   - actualMessage = message;
291   - $.hub.reply( message, replyMessage );
292   - });
  285 + ok( is1, "1.1 is version 1" );
  286 + ok( is2, "2.2 is version 2" );
293 287
294   - // requestReply auto defines and subscribes to a replyChannel
295   - $.hub.requestReply( channel, message, function( channel, message ) {
296   - actualReplyMessage = message;
297   - correlationId = message.correlationId;
298   - });
  288 + var is11 = filter11( channel, message11 );
  289 + var is12 = filter12( channel, message12 );
  290 + var is22 = filter22( channel, message22 );
299 291
300   - equal( actualChannel, channel );
301   - deepEqual( actualMessage.body, messageBody );
  292 + ok( is11, "1.1 is version 1.1" );
  293 + ok( is12, "1.2 is version 1.2" );
  294 + ok( is22, "2.2 is version 2.2" );
302 295
303   - equal( message.messageId, correlationId );
304   - deepEqual( actualReplyMessage.body, replyMessage.body );
  296 + is11 = filter11( channel, message1 );
  297 + is12 = filter12( channel, message11 );
  298 + is22 = filter22( channel, message2 );
305 299
306   - $.hub.unsubscribe( subscription );
  300 + equal( is11, false, "1.1 is not version 1" );
  301 + equal( is12, false, "1.2 is not version 1.1" );
  302 + equal( is22, false, "2.2 is not version 2" );
307 303 });
308 304
309   -module( "Selective Consumer" );
310   -
311   -test( "filter", function() {
  305 +test( "createVersionFilter for v1 and v2", function() {
312 306 var m1 = $.hub.message({ name: "Kevin Hakanson" }, { formatVersion: "1" });
313 307 var m2 = $.hub.message({ firstname: "Kevin", lastname: "Hakanson" }, { formatVersion: "2" });
314 308 var subscriber1, subscriber2, subscriber3;
@@ -354,59 +348,9 @@ test( "filter", function() {
354 348 $.hub.unsubscribe( subscriber3 );
355 349 });
356 350
357   -test( "createVersionFilter filters version strings", function() {
358   - var channel = "createVersionFilter",
359   - filter1 = $.hub.createVersionFilter( "1" ),
360   - filter2 = $.hub.createVersionFilter( "2" ),
361   - filter11 = $.hub.createVersionFilter( "1.1" ),
362   - filter12 = $.hub.createVersionFilter( "1.2" ),
363   - filter22 = $.hub.createVersionFilter( "2.2" ),
364   - message1 = $.hub.message({}, { formatVersion: "1" }),
365   - message2 = $.hub.message({}, { formatVersion: "2" }),
366   - message11 = $.hub.message({}, { formatVersion: "1.1" }),
367   - message12 = $.hub.message({}, { formatVersion: "1.2" }),
368   - message22 = $.hub.message({}, { formatVersion: "2.2" });
369   -
370   - // {major} versions
371   - var is1 = filter1( channel, message1 );
372   - var is2 = filter2( channel, message2 );
373   -
374   - ok( is1, "1 is version 1" );
375   - ok( is2, "2 is version 2" );
376   -
377   - is1 = filter1( channel, message2 );
378   - is2 = filter2( channel, message1 );
379   -
380   - equal( is1, false, "2 is not version 1" );
381   - equal( is2, false, "1 is not version 2" );
382   -
383   - // {major}.{minor} versions
384   - is1 = filter1( channel, message11 );
385   - is2 = filter2( channel, message22 );
386   -
387   - ok( is1, "1.1 is version 1" );
388   - ok( is2, "2.2 is version 2" );
389   -
390   - var is11 = filter11( channel, message11 );
391   - var is12 = filter12( channel, message12 );
392   - var is22 = filter22( channel, message22 );
393   -
394   - ok( is11, "1.1 is version 1.1" );
395   - ok( is12, "1.2 is version 1.2" );
396   - ok( is22, "2.2 is version 2.2" );
397   -
398   - is11 = filter11( channel, message1 );
399   - is12 = filter12( channel, message11 );
400   - is22 = filter22( channel, message2 );
401   -
402   - equal( is11, false, "1.1 is not version 1" );
403   - equal( is12, false, "1.2 is not version 1.1" );
404   - equal( is22, false, "2.2 is not version 2" );
405   -});
406   -
407 351 module( "Message Translator" );
408 352
409   -test( "filter and translate", function() {
  353 +test( "createVersionFilter for v2 and translate v2 to v1", function() {
410 354 var m2 = $.hub.message({ firstname: "Kevin", lastname: "Hakanson" }, { formatVersion: "2" });
411 355 var subscriber1, subscriber2, subscriber3;
412 356 var countV1 = 0, countV2 = 0;
@@ -464,7 +408,7 @@ test( "only receive same message once", function() {
464 408 equal( count1, 2, "1 m1 + 1 m2" );
465 409 equal( count2, 2, "1 m1 + 1 m2" );
466 410
467   - // should get both of these (no message id)
  411 + // should get both of these (null message)
468 412 $.hub.publish( channel, null );
469 413 $.hub.publish( channel, null );
470 414
@@ -479,6 +423,125 @@ test( "only receive same message once", function() {
479 423 $.hub.unsubscribe( subscriber2 );
480 424 });
481 425
  426 +/* part 4a */
  427 +
  428 +module( "Request-Reply" );
  429 +
  430 +test( "subscribe using message builder with replyTo set", function() {
  431 + var channel = "a",
  432 + replyChannel = "b",
  433 + messageBody = { "a": "a" },
  434 + message = $.hub.message( messageBody ),
  435 + replyMessage = $.hub.message({ "c": "c" }),
  436 + correlationId,
  437 + actualMessage,
  438 + actualChannel,
  439 + actualReplyMessage,
  440 + actualReplyChannel;
  441 +
  442 + // listen for the request, then reply
  443 + var subscription = $.hub.subscribe( channel, function( channel, message ) {
  444 + actualChannel = channel;
  445 + actualMessage = message;
  446 + $.hub.reply(message, replyMessage );
  447 + });
  448 +
  449 + // listen for the reply
  450 + var replySubscription = $.hub.subscribe( replyChannel, function( channel, message ) {
  451 + actualReplyChannel = channel;
  452 + actualReplyMessage = message;
  453 + correlationId = message.correlationId;
  454 + });
  455 +
  456 + // replyTo is the channel where replies are sent
  457 + message.replyTo = replyChannel;
  458 + $.hub.publish( channel, message );
  459 +
  460 + equal( actualChannel, channel );
  461 + deepEqual( actualMessage.body, messageBody );
  462 +
  463 + equal( actualReplyChannel, replyChannel);
  464 + equal( message.messageId, correlationId);
  465 + deepEqual( actualReplyMessage.body, replyMessage.body );
  466 +
  467 + $.hub.unsubscribe( subscription );
  468 + $.hub.unsubscribe( replySubscription );
  469 +});
  470 +
  471 +test( "subscribe using message builder with replyTo not set", function() {
  472 + var channel = "a",
  473 + replyChannel = "b",
  474 + messageBody = { "a": "a" },
  475 + replyMessage = $.hub.message({ "c": "c" }),
  476 + correlationId,
  477 + actualMessage,
  478 + actualChannel,
  479 + actualReplyMessage = null,
  480 + actualReplyChannel = null;
  481 +
  482 + // listen for the request, then reply
  483 + var subscription = $.hub.subscribe(channel, function( channel, message ) {
  484 + actualChannel = channel;
  485 + actualMessage = message;
  486 + $.hub.reply( message, replyMessage );
  487 + });
  488 +
  489 + // replyTo is the channel where replies are sent
  490 + var replySubscription = $.hub.subscribe( replyChannel, function( channel, message ) {
  491 + actualReplyChannel = channel;
  492 + actualReplyMessage = message;
  493 + correlationId = message.correlationId;
  494 + });
  495 +
  496 + // forget to set the replyTo
  497 + var message = $.hub.message( messageBody );
  498 + $.hub.publish( channel, message );
  499 +
  500 + equal( actualChannel, channel );
  501 + deepEqual( actualMessage.body, messageBody );
  502 +
  503 + equal( actualReplyChannel, null, "replySubscription never invoked" );
  504 + deepEqual( actualReplyMessage, null, "replySubscription never invoked" );
  505 + equal( correlationId, null, "replySubscription never invoked" );
  506 +
  507 + $.hub.unsubscribe( subscription );
  508 + $.hub.unsubscribe( replySubscription );
  509 +} );
  510 +
  511 +test( "subscribe using message builder requestReply", function() {
  512 + var channel = "a",
  513 + replyChannel = "b",
  514 + messageBody = { "a": "a" },
  515 + message = $.hub.message( messageBody ),
  516 + replyMessage = $.hub.message({ "c": "c" }),
  517 + correlationId,
  518 + actualMessage,
  519 + actualChannel;
  520 +
  521 + // listen for the request, then reply
  522 + var subscription = $.hub.subscribe(channel, function( channel, message ) {
  523 + actualChannel = channel;
  524 + actualMessage = message;
  525 + $.hub.reply( message, replyMessage );
  526 + });
  527 +
  528 + // requestReply auto defines/subscribes to a replyChannel
  529 + $.hub.requestReply( channel, message, function( channel, message ) {
  530 + actualReplyMessage = message;
  531 + correlationId = message.correlationId;
  532 + });
  533 +
  534 + equal( actualChannel, channel );
  535 + deepEqual( actualMessage.body, messageBody );
  536 +
  537 + equal( message.messageId, correlationId );
  538 + deepEqual( actualReplyMessage.body, replyMessage.body );
  539 +
  540 + $.hub.unsubscribe( subscription );
  541 +});
  542 +
  543 +/* part 4b */
  544 +
482 545 module( "Command Message" );
483 546
484 547 test( "command message and message endpoint", function() {
@@ -517,50 +580,3 @@ test( "command message and message endpoint", function() {
517 580 $.hub.unsubscribe( subscription );
518 581 });
519 582
520   -test( "this and scope", function() {
521   - var m1 = $.hub.message( { name: "Kevin Hakanson" }, { formatVersion: "1" } );
522   - var m2 = $.hub.message( { firstname: "Kevin", lastname: "Hakanson" }, { formatVersion: "2" } );
523   - var subscriber1, subscriber2, subscriber3, subscriber4;
524   -
525   - window.count = 100; // bad this.count will leak out to window.count
526   - var counter1 = {
527   - count: 0,
528   - increment: function( channel, message ) {
529   - this.count++;
530   - }
531   - };
532   - var counter2 = (function() {
533   - var count = 200,
534   - obj = {
535   - increment: function( channel, message ) {
536   - count++;
537   - },
538   - count: function() {
539   - return count;
540   - }
541   - };
542   - return obj;
543   - })();
544   -
545   - subscriber1 = $.hub.subscribe( "Person.*", counter1.increment );
546   - subscriber2 = $.hub.subscribe( "Person.*", counter1.increment, counter1 );
547   - subscriber3 = $.hub.subscribe( "Person.*", $.proxy( counter1.increment, counter1 ) );
548   - subscriber4 = $.hub.subscribe( "Person.*", counter2.increment );
549   -
550   - $.hub.publish( "Person.Cool", m1 );
551   -
552   - equal( window.count, 101, "window.count will be incremented one times" );
553   - equal( counter1.count, 2, "counter1.count will be incremented two times" );
554   - equal( counter2.count(), 201, "counter2.count will be incremented one times" );
555   -
556   - $.hub.publish( "Person.Cool", m2 );
557   -
558   - equal( window.count, 102, "window.count will be incremented two times" );
559   - equal( counter1.count, 4, "counter1.count will be incremented four times" );
560   - equal( counter2.count(), 202, "counter2.count will be incremented two times" );
561   -
562   - $.hub.unsubscribe( subscriber1 );
563   - $.hub.unsubscribe( subscriber2 );
564   - $.hub.unsubscribe( subscriber3 );
565   - $.hub.unsubscribe( subscriber4 );
566   -});

0 comments on commit 1bb9ada

Please sign in to comment.
Something went wrong with that request. Please try again.