"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/slide/package.json" (8 Feb 2018, 5835 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) JSON source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 {
    2   "_from": "slide@>=1.1.6 <1.2.0",
    3   "_id": "slide@1.1.6",
    4   "_inBundle": true,
    5   "_location": "/slide",
    6   "_npmUser": {
    7     "name": "isaacs",
    8     "email": "i@izs.me"
    9   },
   10   "_npmVersion": "2.0.0-beta.3",
   11   "_phantomChildren": {},
   12   "_requiredBy": [
   13     "/npm",
   14     "/npm-registry-client",
   15     "/read-installed",
   16     "/write-file-atomic"
   17   ],
   18   "_resolved": "https://registry.npmjs.org/slide/-/slide-1.1.6.tgz",
   19   "_shasum": "56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707",
   20   "author": {
   21     "name": "Isaac Z. Schlueter",
   22     "email": "i@izs.me",
   23     "url": "http://blog.izs.me/"
   24   },
   25   "bugs": {
   26     "url": "https://github.com/isaacs/slide-flow-control/issues"
   27   },
   28   "contributors": [
   29     {
   30       "name": "S. Sriram",
   31       "email": "ssriram@gmail.com",
   32       "url": "http://www.565labs.com"
   33     }
   34   ],
   35   "dependencies": {},
   36   "description": "A flow control lib small enough to fit on in a slide presentation. Derived live at Oak.JS",
   37   "devDependencies": {},
   38   "directories": {},
   39   "dist": {
   40     "shasum": "56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707",
   41     "tarball": "http://registry.npmjs.org/slide/-/slide-1.1.6.tgz"
   42   },
   43   "engines": {
   44     "node": "*"
   45   },
   46   "gitHead": "8345e51ee41e35825abc1a40750ea11462f57028",
   47   "homepage": "https://github.com/isaacs/slide-flow-control",
   48   "license": "ISC",
   49   "main": "./lib/slide.js",
   50   "maintainers": [
   51     {
   52       "name": "isaacs",
   53       "email": "i@izs.me"
   54     }
   55   ],
   56   "name": "slide",
   57   "optionalDependencies": {},
   58   "readme": "# Controlling Flow: callbacks are easy\n\n## What's actually hard?\n\n- Doing a bunch of things in a specific order.\n- Knowing when stuff is done.\n- Handling failures.\n- Breaking up functionality into parts (avoid nested inline callbacks)\n\n\n## Common Mistakes\n\n- Abandoning convention and consistency.\n- Putting all callbacks inline.\n- Using libraries without grokking them.\n- Trying to make async code look sync.\n\n## Define Conventions\n\n- Two kinds of functions: *actors* take action, *callbacks* get results.\n- Essentially the continuation pattern. Resulting code *looks* similar\n  to fibers, but is *much* simpler to implement.\n- Node works this way in the lowlevel APIs already, and it's very flexible.\n\n## Callbacks\n\n- Simple responders\n- Must always be prepared to handle errors, that's why it's the first argument.\n- Often inline anonymous, but not always.\n- Can trap and call other callbacks with modified data, or pass errors upwards.\n\n## Actors\n\n- Last argument is a callback.\n- If any error occurs, and can't be handled, pass it to the callback and return.\n- Must not throw. Return value ignored.\n- return x ==> return cb(null, x)\n- throw er ==> return cb(er)\n\n```javascript\n// return true if a path is either\n// a symlink or a directory.\nfunction isLinkOrDir (path, cb) {\n  fs.lstat(path, function (er, s) {\n    if (er) return cb(er)\n    return cb(null, s.isDirectory() || s.isSymbolicLink())\n  })\n}\n```\n\n# asyncMap\n\n## Usecases\n\n- I have a list of 10 files, and need to read all of them, and then continue when they're all done.\n- I have a dozen URLs, and need to fetch them all, and then continue when they're all done.\n- I have 4 connected users, and need to send a message to all of them, and then continue when that's done.\n- I have a list of n things, and I need to dosomething with all of them, in parallel, and get the results once they're all complete.\n\n\n## Solution\n\n```javascript\nvar asyncMap = require(\"slide\").asyncMap\nfunction writeFiles (files, what, cb) {\n  asyncMap(files, function (f, cb) {\n    fs.writeFile(f, what, cb)\n  }, cb)\n}\nwriteFiles([my, file, list], \"foo\", cb)\n```\n\n# chain\n\n## Usecases\n\n- I have to do a bunch of things, in order. Get db credentials out of a file,\n  read the data from the db, write that data to another file.\n- If anything fails, do not continue.\n- I still have to provide an array of functions, which is a lot of boilerplate,\n  and a pita if your functions take args like\n\n```javascript\nfunction (cb) {\n  blah(a, b, c, cb)\n}\n```\n\n- Results are discarded, which is a bit lame.\n- No way to branch.\n\n## Solution\n\n- reduces boilerplate by converting an array of [fn, args] to an actor\n  that takes no arguments (except cb)\n- A bit like Function#bind, but tailored for our use-case.\n- bindActor(obj, \"method\", a, b, c)\n- bindActor(fn, a, b, c)\n- bindActor(obj, fn, a, b, c)\n- branching, skipping over falsey arguments\n\n```javascript\nchain([\n  doThing && [thing, a, b, c]\n, isFoo && [doFoo, \"foo\"]\n, subChain && [chain, [one, two]]\n], cb)\n```\n\n- tracking results: results are stored in an optional array passed as argument,\n  last result is always in results[results.length - 1].\n- treat chain.first and chain.last as placeholders for the first/last\n  result up until that point.\n\n\n## Non-trivial example\n\n- Read number files in a directory\n- Add the results together\n- Ping a web service with the result\n- Write the response to a file\n- Delete the number files\n\n```javascript\nvar chain = require(\"slide\").chain\nfunction myProgram (cb) {\n  var res = [], last = chain.last, first = chain.first\n  chain([\n    [fs, \"readdir\", \"the-directory\"]\n  , [readFiles, \"the-directory\", last]\n  , [sum, last]\n  , [ping, \"POST\", \"example.com\", 80, \"/foo\", last]\n  , [fs, \"writeFile\", \"result.txt\", last]\n  , [rmFiles, \"./the-directory\", first]\n  ], res, cb)\n}\n```\n\n# Conclusion: Convention Profits\n\n- Consistent API from top to bottom.\n- Sneak in at any point to inject functionality. Testable, reusable, ...\n- When ruby and python users whine, you can smile condescendingly.\n",
   59   "readmeFilename": "README.md",
   60   "repository": {
   61     "type": "git",
   62     "url": "git://github.com/isaacs/slide-flow-control.git"
   63   },
   64   "scripts": {},
   65   "version": "1.1.6"
   66 }