mauricemach / zappa

Node development for the lazy.
zappajs.org
MIT License
951 stars 81 forks source link

ctx.data in routes and helpers (0.3.0) #91

Open shimaore opened 13 years ago

shimaore commented 13 years ago

Idea: let's use ctx.data to represent the databag inside routes and helpers. This is especially convenient in helpers where values might come from req.query or req.body (when using bodyDecoder) depending on the calling environment (get vs post). In routes @data would allow for pre-0.3-like semantics (= more direct migration strategy).

Suggested changes: line 265

      if app.settings['databag']
        args[1].params = ctx.data

line 287

    if app.settings['databag']
      ctx.data = {}
      copy_data_to ctx.data, [req.query, req.params, req.body]

line 292

    switch app.settings['databag']
      when 'this' then result = r.handler.apply(ctx.data, [ctx])
      when 'param' then result = r.handler.apply(ctx, [ctx.data])
      else result = r.handler.apply(ctx, [ctx])