Permalink
Browse files

Removed extraneous argument to callback functions.

Callbacks are now all called without any parameters. See #41
  • Loading branch information...
shimaore committed Sep 4, 2012
1 parent 41f8faa commit 152dc6d2a1dcc19eeadb86f9a44f980e3de0e1e5
Showing with 24 additions and 21 deletions.
  1. +19 −0 docs/migrate-0.4.md
  2. +2 −8 src/client.coffee
  3. +3 −13 src/zappa.coffee
View
@@ -43,3 +43,22 @@ Other changes are Zappa-specific and simplify the API:
That extraneous argument has been removed since it is a duplicate of `this`.
Helper functions now receive the arguments provided by the caller unmodified.
+
+* No argument (the databag or context) are passed to callbacks.
+
+ This might apply to you if you used the `databag` option (see below) or you used the context
+ argument instead of `this`.
+
+ This applies to (server-side) `@get`, `@post`, `@put`, `@del`, `@all`, all middleware functions,
+ and `@on`.
+ This applies to (client-side) `@get` (use `@params`) and `@on` (use `@data`).
+
+ For example, if your code said:
+
+ @get '/': (context) ->
+ context.params
+
+ replace it with
+
+ @get '/': ->
+ @params # or this.params
View
@@ -62,10 +62,7 @@ skeleton = ->
ctx.sammy_context = sammy_context
ctx.render = -> sammy_context.render.apply sammy_context, arguments
ctx.redirect = -> sammy_context.redirect.apply sammy_context, arguments
- switch settings['databag']
- when 'this' then r.handler.apply(sammy_context.params, [ctx])
- when 'param' then r.handler.apply(ctx, [sammy_context.params])
- else r.handler.apply(ctx, [ctx])
+ r.handler.apply ctx
# GO!!!
func.apply(context, [context])
@@ -89,10 +86,7 @@ skeleton = ->
apply_helpers ctx
- switch settings['databag']
- when 'this' then h.apply(data, [ctx])
- when 'param' then h.apply(ctx, [data])
- else h.apply(ctx, [ctx])
+ h.apply ctx
$(-> app.run '#/') if app?
View
@@ -343,10 +343,7 @@ zappa.app = (func,options={}) ->
data = {}
copy_data_to data, [req.query, req.params, req.body]
- switch app.settings['databag']
- when 'this' then f.apply(data, [ctx])
- when 'param' then f.apply(ctx, [data])
- else result = f.apply(ctx, [ctx])
+ f.apply ctx
if typeof r.handler is 'string'
app[r.verb] r.path, r.middleware..., (req, res) ->
@@ -424,11 +421,7 @@ zappa.app = (func,options={}) ->
data = {}
copy_data_to data, [req.query, req.params, req.body]
- # Go!
- switch app.settings['databag']
- when 'this' then result = r.handler.apply(data, [ctx])
- when 'param' then result = r.handler.apply(ctx, [data])
- else result = r.handler.apply(ctx, [ctx])
+ result = r.handler.apply ctx
res.contentType(r.contentType) if r.contentType?
if typeof result is 'string' then res.send result
@@ -490,10 +483,7 @@ zappa.app = (func,options={}) ->
ctx = build_ctx()
ctx.data = data
ctx.ack = ack
- switch app.settings['databag']
- when 'this' then h.apply(data, [ctx])
- when 'param' then h.apply(ctx, [data])
- else h.apply(ctx, [ctx])
+ h.apply ctx
# Go!
func.apply(context, [context])

0 comments on commit 152dc6d

Please sign in to comment.