mauricemach / zappa

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

Using client-side routes with zappa/sammy #107

Open hudon opened 13 years ago

hudon commented 13 years ago

Zappa Docs say that you can do @ get, post, put, del in browser-side code (section "CLIENT-SIDE ROOT SCOPE"). Looking around the docs, and then at the source (0.3.1), I see zappa is exposing Sammy's routing functionality to do so. Only @ get is being exposed though, so:

@client '/foo.js': ->
  @get '#/': ->
    alert 'bar'
  @post '#/banana': ->
    alert 'ban'

@ post will throw an error as soon as it is read: "Uncaught TypeError: Object # has no method 'post'"

I tried doing:

@app.post '#/banana': ->

but that ends up causing 'has no method 'exec'' in the sammy.js code.

hudon commented 13 years ago

in the meantime I can just use @ get for all client side routing without a problem

mountain commented 12 years ago

I met same problem, but after reading the code, I understand the direct reason.

For the '@post' error, it is not supported by zappa's client context, please refer: https://github.com/mauricemach/zappa/blob/master/src/client.coffee

For the "has no method 'exec" error, it is because of the non-adaptive api interface between zappa and sammy. zappa use object literals to passing params, while sammy use normal function param-passing. Carefully read the code below and compare with sammy api https://github.com/mauricemach/zappa/blob/master/src/client.coffee#L17

But I do not understand the rationale why zappa keep a limited use of sammy apis.

Hope anybody could give an explanation.