Skip to content

Add syntax for handling nested callbacks #1704

@paulmillr

Description

@paulmillr

The main problem of node.js apps are nested callbacks. You use them A LOT everywhere. Code becomes like a ladder etc. I propose to add a simple operator for their handling.

With "<-" operator, these two snippets of code would be identical. Coco had already added this thing and it's very comfortable / easy-to-use.

(found) <- path.exists mainFilePath
return unless found

(error, data) <- fs.readFile mainFilePath, "utf8"
return helpers.logError error if error
compiler = stylus(data)
  .set("filename", mainFilePath)
  .set("compress", true)
  .include(@getPath "src")
compiler.use nib if nib

(error, css) <- compiler.render
return helpers.logError error if error
mainCss = @getBuildPath "web/css/main.css"

(error) <- fs.writeFile mainCss, css, "utf8"
return helpers.logError error if error
helpers.logSuccess "[Stylus]: compiled main.css."
path.exists mainFilePath, (found) ->
  return unless found
  fs.readFile mainFilePath, "utf8", (error, data) ->
    return helpers.logError error if error
    compiler = stylus(data)
      .set("filename", mainFilePath)
      .set("compress", true)
      .include(@getPath "src")
    compiler.use nib if nib
    compiler.render (error, css) ->
      return helpers.logError error if error
      mainCss = @getBuildPath "web/css/main.css"
      fs.writeFile mainCss, css, "utf8", (error) ->
        return helpers.logError error if error
        helpers.logSuccess "[Stylus]: compiled main.css."

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions