redom 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/redom/runtime.rb +39 -29
  2. data/lib/redom/version.rb +1 -1
  3. metadata +6 -6
@@ -8,7 +8,7 @@ module Redom
8
8
  TYPE_PROXY = 1,
9
9
  TYPE_ARRAY = 2,
10
10
  TYPE_ERROR = 3,
11
- TYPE_METHOD = 4
11
+ TYPE_METHOD = 4,
12
12
 
13
13
  REQ_HANDSHAKE = 0,
14
14
  REQ_METHOD_INVOCATION = 1,
@@ -19,26 +19,24 @@ module Redom
19
19
  P_INFO_NAME = 2,
20
20
  P_INFO_ARGS = 3;
21
21
 
22
+ var connections = {};
23
+
22
24
  if (window.Opal) {
23
- Object.prototype.$djsCall = function(name) {
24
- if (name == '') {
25
- return (function(obj) {
26
- return function(key) {
27
- return obj[key];
28
- };
29
- })(this);
25
+ Opal.$method = function(cid, name) {
26
+ if (Opal.top['$' + name]) {
27
+ return Opal.top['$' + name];
28
+ } else {
29
+ return connections[cid](name);
30
30
  }
31
+ }
31
32
 
32
- if (name == '$method') {
33
- return function(methodName) {
34
- if (Opal.top['$' + methodName]) {
35
- return Opal.top['$' + methodName];
36
- } else {
37
- return function(e) {
38
- window.djs.invoke(methodName, [e]);
39
- };
40
- }
41
- };
33
+ Object.prototype.$djsCall = function(name) {
34
+ if (name == '') {
35
+ return (function(obj) {
36
+ return function(key) {
37
+ return obj[key];
38
+ };
39
+ })(this);
42
40
  }
43
41
 
44
42
  if (Opal.top[name]) {
@@ -55,7 +53,7 @@ module Redom
55
53
  if (name[0] == "$" && this[name] == null) {
56
54
  name = name.substring(1);
57
55
  };
58
-
56
+
59
57
  if (this[name] != null) {
60
58
  if (typeof this[name] == 'function') {
61
59
  return (function(obj) {
@@ -81,7 +79,7 @@ module Redom
81
79
  };
82
80
  }
83
81
  }
84
-
82
+
85
83
  return function() {
86
84
  return null;
87
85
  };
@@ -97,6 +95,7 @@ module Redom
97
95
  Opal.top.$document = window.document;
98
96
  Opal.top.$navigator = window.navigator;
99
97
  Opal.top.$location = window.location;
98
+ Opal.top.$history = window.history;
100
99
  }
101
100
 
102
101
  var Redom = function(server) {
@@ -165,7 +164,7 @@ module Redom
165
164
  // Close this WebSocket connection
166
165
  function close() {
167
166
  ws.close();
168
- }
167
+ };
169
168
 
170
169
  // Serialize JavaScript object into message
171
170
  function serialize(data) {
@@ -190,7 +189,7 @@ module Redom
190
189
  return refs.get(args[1]);
191
190
  break;
192
191
  case TYPE_METHOD:
193
- return (function(name) {
192
+ return (function(cid, name) {
194
193
  if (window[name] && typeof(window[name]) == 'function') {
195
194
  return function() {
196
195
  window[name];
@@ -209,10 +208,10 @@ module Redom
209
208
  break;
210
209
  }
211
210
  }
212
- ws.send(serialize([REQ_METHOD_INVOCATION, name, args]));
211
+ ws.send(serialize([REQ_METHOD_INVOCATION, cid, name, args]));
213
212
  }
214
213
  }
215
- })(args[1]);
214
+ })(args[1], args[2]);
216
215
  break;
217
216
  }
218
217
  } else {
@@ -233,7 +232,7 @@ module Redom
233
232
 
234
233
  if (rcvr) {
235
234
  result = execute(rcvr, name, args);
236
- if (result == undefined) {
235
+ if (typeof result == "undefined") {
237
236
  rsps.push([oid, [TYPE_UNDEFINED]]);
238
237
  ws.send(serialize([REQ_PROXY_RESULT, tid, rsps]));
239
238
  return;
@@ -250,9 +249,19 @@ module Redom
250
249
  };
251
250
  }
252
251
  } else {
253
- rsps.push([oid, TYPE_ERROR, "no such object. ID='" + proxy[P_INFO_RCVR] + "'."]);
254
- ws.send(serialize([REQ_PROXY_RESULT, tid, rsps]));
255
- return;
252
+ if (name) {
253
+ rsps.push([oid, TYPE_ERROR, "no such object. ID='" + proxy[P_INFO_RCVR] + "'."]);
254
+ ws.send(serialize([REQ_PROXY_RESULT, tid, rsps]));
255
+ return;
256
+ } else {
257
+ connections[args] = (function(ws, cid) {
258
+ return function(name) {
259
+ return function(e) {
260
+ ws.send(serialize([REQ_METHOD_INVOCATION, cid, name, [[TYPE_PROXY, refs.put(e)]]]));
261
+ };
262
+ };
263
+ })(ws, args);
264
+ }
256
265
  }
257
266
  }
258
267
  ws.send(serialize([REQ_PROXY_RESULT, tid, rsps]));
@@ -278,7 +287,7 @@ module Redom
278
287
  return TYPE_METHOD;
279
288
  }
280
289
  return TYPE_UNDEFINED;
281
- }
290
+ };
282
291
 
283
292
  // Method invocation
284
293
  function execute(rcvr, name, args) {
@@ -297,6 +306,7 @@ module Redom
297
306
  result = rcvr[name];
298
307
  if (typeof result == "function") {
299
308
  result = result.apply(rcvr, args);
309
+ result = typeof result == "undefined" ? null : result;
300
310
  }
301
311
  }
302
312
  }
@@ -1,3 +1,3 @@
1
1
  module Redom
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-21 00:00:00.000000000Z
13
+ date: 2012-12-22 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: em-websocket
17
- requirement: &70180056191480 !ruby/object:Gem::Requirement
17
+ requirement: &70227380221180 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.3.5
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70180056191480
25
+ version_requirements: *70227380221180
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: opal
28
- requirement: &70180056190760 !ruby/object:Gem::Requirement
28
+ requirement: &70227380220300 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 0.3.27
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70180056190760
36
+ version_requirements: *70227380220300
37
37
  description: A distributed object based server-centric web framework.
38
38
  email: future.azure@gmail.com
39
39
  executables: