angelozerr / tern-node-express

A Tern plugin adding support for express web application framework for node.
http://expressjs.com/
MIT License
56 stars 4 forks source link

app.VERB(path, [callback...], callback) #3

Closed ghost closed 10 years ago

ghost commented 10 years ago

Express API application routing is documented here: http://expressjs.com/4x/api.html#app.VERB For tern that would become 3 different entries:

app.get(path, [callback...], callback) app.post(path, [callback...], callback) app.put(path, [callback...], callback)

Beside that I'll have a few more questions...

Knowing we already have another app.get() in application settings section — is tern fine with this?

What would be tern syntax for an optional callback function at this position?

I don't get what "!effects": ["custom expressUse"] means or when it should be used (or not).

ghost commented 10 years ago

Is this correct tern syntax for get/post/put + all application routing APIs?

    get: {
        "!type": "fn(path: string, callback?: fn(req: +Request, req: +Response),callback: fn(req: +Request, req: +Response)) -> !this",
        "!effects": ["custom expressUse"],
        "!url": "http://expressjs.com/4x/api.html#app.VERB",
        "!doc": "The app.VERB() methods provide the routing functionality in Express, where VERB is one of the HTTP verbs (such as app.get()). "
      },
    post: {
        "!type": "fn(path: string, callback?: fn(req: +Request, req: +Response),callback: fn(req: +Request, req: +Response)) -> !this",
        "!effects": ["custom expressUse"],
        "!url": "http://expressjs.com/4x/api.html#app.VERB",
        "!doc": "The app.VERB() methods provide the routing functionality in Express, where VERB is one of the HTTP verbs (such as app.post()). "
      },
    put: {
        "!type": "fn(path: string, callback?: fn(req: +Request, req: +Response),callback: fn(req: +Request, req: +Response)) -> !this",
        "!effects": ["custom expressUse"],
        "!url": "http://expressjs.com/4x/api.html#app.VERB",
        "!doc": "The app.VERB() methods provide the routing functionality in Express, where VERB is one of the HTTP verbs (such as app.put()). "
      },
    all: {
        "!type": "fn(path: string, callback?: fn(req: +Request, req: +Response),callback: fn(req: +Request, req: +Response)) -> !this",
        "!effects": ["custom expressUse"],
        "!url": "http://expressjs.com/4x/api.html#app.all",
        "!doc" : "The app.all() method allows the execution of specified request handlers on a particular path no matter what the HTTP method of the request is."
      },        
angelozerr commented 10 years ago

Ok I have supported app.VERB.

Is this correct tern syntax for get/post/put + all application routing APIs?

yes it was the idea. But as get type is a little complex, aray of callback, wich is optional, tern is a little lost. To help tern to inject the well Request, Response type, I have created a custom function express_callback.

I have added a sample with app.VERB at https://github.com/angelozerr/tern-express/blob/master/demos/app.VERB.html

ghost commented 10 years ago

3 more verbs but one more question regarding integer parameters: is integer a valid tern type?

  render: {
      "!type": "fn(view: string, callback: [fn(err: integer, html: string)])",
      "!effects": ["custom express_callback"],
      "!url": "http://expressjs.com/4x/api.html#app.render",
      "!doc" : "Render a view with a callback responding with the rendered string. This is the app-level variant of res.render(), and otherwise behaves the same way."
    },
   listen: {
      "!type": "fn(port?: integer)"
      "!url": "http://expressjs.com/4x/api.html#app.listen",
      "!doc" : "Bind and listen for connections on the given host and port."
    },
   path: {
      "!type": "fn() -> +Path"
      "!url": "http://expressjs.com/4x/api.html#app.path",
      "!doc" : "Returns the canonical path of the app."
    },
ghost commented 10 years ago

2 more verbs to complete express application section — with another open issue about the on event callback parameter type: what's the correct type for tern?

mountpath: {
      "!type": "fn() -> +Mountpath"
      "!url": "http://expressjs.com/4x/api.html#app.mountpath",
      "!doc" : "Refers to the path pattern(s) on which a sub app was mounted. It is similar to the baseUrl property of the req object, except req.baseUrl returns the matched URL path, instead of the matched pattern(s)."
    },
on: {
      "!type": "fn('mount',callback:[fn(parent: application)])"
      "!effects": ["custom express_callback"],
      "!url": "http://expressjs.com/4x/api.html#app.onmount",
       "!doc" : "The mount event is fired on a sub app, when it is mounted on a parent app. The parent app is passed to the callback function."
            }
angelozerr commented 10 years ago

3 more verbs but one more question regarding integer parameters: is integer a valid tern type?

See my commit https://github.com/angelozerr/tern-express/commit/1a2d02b4221e30ac894a890a720666633b19ea9e to support render, listen, path

integer doesn't exists with tern. It's number.

angelozerr commented 10 years ago

for app.on. See https://github.com/angelozerr/tern-express/commit/01a5bb3e50a2ae90135a91fce0a8d658e9212eed

You have written

"!type": "fn('mount',callback:[fn(parent: application)])"

but it was :

"!type": "fn(name: string, callback: fn(parent: Application))",

Here several informations :

1) you cannot set 'mont', You can set a name variable and type. 2) it's very important for "!type" to add space after ':' and space after ',' otherwise tern will throw an error. 3) you have used [], but it seems calback is not an arry of fn. 4) you have used application, but it's Application that you must use. 5) you not need "!effects": ["custom express_callback"],