Permalink
Browse files

first stab at CommonJS compatibility

  • Loading branch information...
1 parent b8cf81c commit 65a6eab6e6c333db9be289ce95f9cec17801897b @mental committed Jan 1, 2011
Showing with 36 additions and 27 deletions.
  1. +23 −20 src/Actor.coffee
  2. +7 −4 src/Match.coffee
  3. +6 −3 src/Worker.coffee
View
43 src/Actor.coffee
@@ -1,4 +1,7 @@
-@WebActors ?= {}
+WebActors = if require? and exports?
+ exports
+ else
+ @WebActors ?= {}
class NullActor
constructor: ->
@@ -258,22 +261,22 @@ injectEvent = (actor_id, verb, args...) ->
actor[verb].apply(actor, args)
undefined
-@WebActors.spawn = spawn
-@WebActors.spawnLinked = spawnLinked
-@WebActors.send = send
-@WebActors.receive = receive
-@WebActors.self = self
-@WebActors.sendSelf = sendSelf
-@WebActors.trapKill = trapKill
-@WebActors.kill = kill
-@WebActors.link = link
-@WebActors.unlink = unlink
-@WebActors.sendback = sendback
-@WebActors.sendbackTo = sendbackTo
-@WebActors.injectEvent = injectEvent
-@WebActors.registerGateway = registerGateway
-@WebActors.unregisterGateway = unregisterGateway
-@WebActors.setDefaultGateway = setDefaultGateway
-@WebActors.getLocalPrefix = getLocalPrefix
-@WebActors.setLocalPrefix = setLocalPrefix
-@WebActors.allocateChildPrefix = allocateChildPrefix
+WebActors.spawn = spawn
+WebActors.spawnLinked = spawnLinked
+WebActors.send = send
+WebActors.receive = receive
+WebActors.self = self
+WebActors.sendSelf = sendSelf
+WebActors.trapKill = trapKill
+WebActors.kill = kill
+WebActors.link = link
+WebActors.unlink = unlink
+WebActors.sendback = sendback
+WebActors.sendbackTo = sendbackTo
+WebActors.injectEvent = injectEvent
+WebActors.registerGateway = registerGateway
+WebActors.unregisterGateway = unregisterGateway
+WebActors.setDefaultGateway = setDefaultGateway
+WebActors.getLocalPrefix = getLocalPrefix
+WebActors.setLocalPrefix = setLocalPrefix
+WebActors.allocateChildPrefix = allocateChildPrefix
View
11 src/Match.coffee
@@ -1,4 +1,7 @@
-@WebActors ?= {}
+WebActors = if require? and exports?
+ exports
+ else
+ @WebActors ?= {}
class CapturingPattern
constructor: (@body) ->
@@ -53,8 +56,8 @@ match = (pattern, value, captured) ->
return null unless pattern is value
return captured
-@WebActors.match = (pattern, value) ->
+WebActors.match = (pattern, value) ->
match pattern, value, []
-@WebActors.$VAR = $VAR
-@WebActors.ANY = ANY
+WebActors.$VAR = $VAR
+WebActors.ANY = ANY
View
9 src/Worker.coffee
@@ -1,4 +1,7 @@
-@WebActors ?= {}
+WebActors = if require? and exports?
+ exports
+ else
+ @WebActors ?= {}
spawnWorker = (script_url) ->
worker_prefix = WebActors.allocateChildPrefix("worker")
@@ -27,5 +30,5 @@ initWorker = (body) ->
WebActors.spawn ->
body.apply(this)
-@WebActors.spawnWorker = spawnWorker
-@WebActors.initWorker = initWorker
+WebActors.spawnWorker = spawnWorker
+WebActors.initWorker = initWorker

0 comments on commit 65a6eab

Please sign in to comment.