From 2594171a669b38a59ed0c95f2cc5d00e3d453e54 Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Wed, 6 Feb 2013 12:42:31 -0500 Subject: [PATCH] Add Channel.buildFactory(). This simple change wraps all of jschannel in a function call that can be accessed through Channel.buildFactory(). This allows jschannel to be used outside of the context of cross-document messaging, for example as an RPC mechanism between a server and client, or to create intra-document APIs that can easily become cross-document if needed. Also added example/fake-window.html to illustrate the use of the new function. --- example/fake-window.html | 164 +++++++++++++++++++++++++++++++++++++++ src/jschannel.js | 10 ++- 2 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 example/fake-window.html diff --git a/example/fake-window.html b/example/fake-window.html new file mode 100644 index 00000000..4eaf1070 --- /dev/null +++ b/example/fake-window.html @@ -0,0 +1,164 @@ + + + + JSChannel Fake Window Examples + + + + + + +

JSChannel fake window example

+

+ Welcome to the JSChannel fake window example page. View source and you'll + get an idea of how you can use Channel.buildFactory() to use jschannel + as a generic RPC mechanism that's not limited to cross-document messaging. +

+ +First, here is basic function invocation: +
+ +Next, here's error handling: +
+ +Next, here's notification output: +
+ +Finally, here's callback invocation output: +
+ + + + + diff --git a/src/jschannel.js b/src/jschannel.js index a57d00f3..7241d70f 100644 --- a/src/jschannel.js +++ b/src/jschannel.js @@ -37,8 +37,9 @@ */ ;var Channel = (function() { - "use strict"; +"use strict"; +var buildFactory = function buildFactory(window) { // current transaction id, start out at a random *odd* number between 1 and a million // There is one current transaction counter id per page, and it's shared between // channel instances. That means of all messages posted from a single javascript @@ -611,4 +612,11 @@ return obj; } }; +}; + +var Channel = buildFactory(window); +Channel.buildFactory = buildFactory; + +return Channel; + })();