Open shimaore opened 13 years ago
Great idea! Very simple to implement and understand, gives a lot of flexibility and choice. I'll give it a try, and think about how it should interact with autoexport/autoimport.
Thanks!
Just realized I didn't define "data" in the original gist, that's corrected.
OK, I implemented it as you described, the only difference being I'm using the setting value, as the two options are mutually exclusive.
So, in default 0.3.0 you receive and send data explicitly. Both the context and the param are references to the object with the zappa API appropriate for the situation:
zappa (foo) ->
@get '/': ->
funzo = @query.funzo
funzo += '!'
@render index: {funzo}
# Alternative:
foo.get '/': (bar) ->
funzo = bar.query.funzo
funzo += '!'
bar.render index: {funzo}
@on said: ->
funzo = @data.funzo
funzo += '!'
@broadcast said: {funzo}
@client '/index.js': ->
@connect()
@on welcome: ->
funzo = @data.funzo
With the option below, the param becomes the merged collection of input variables, and it will also be sent to templates implicitly:
zappa ->
@set databag: 'param'
@get '/': (bar) ->
bar.funzo += '!'
@render 'index'
@on said: (bar) ->
bar.funzo += '!'
@broadcast said: bar
@client '/index.js': ->
@connect()
@on welcome: (bar) ->
funzo = bar.funzo
And with this one, the same thing but with the context instead:
zappa (foo) ->
foo.set databag: 'context'
foo.get '/': (bar) ->
@funzo += '!'
bar.render 'index'
foo.on said: (bar) ->
@funzo += '!'
bar.broadcast said: {@funzo}
foo.client '/index.js': (fuu) ->
fuu.connect()
fuu.on welcome: ->
funzo = @funzo
Note: databag: 'context'
changed to databag: 'this'
.
Diff: https://gist.github.com/1228579 contains two options: