Skip to content
Myr

fn -> callback

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Aaron Heckmann · committed by Aaron Heckmann · parent a4833e7 · Browse files · 6 files+60 added−60 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+60 added−60 removed

  • tests:+16 added−16 removed
  • other:+44 added−44 removed

6 files+60 added−60 removed

modified:lib/express/plugins/cache.js+4 added-4 removed
24 unmodified lines
25 * Override in subclass to provide data-store specific functionality.26 *27 * @param {string} key28 * @param {string} val29 * @param {function} fn29 * @param {function} callback30 * @api public31 */32 33 set: function(key, val, fn) {33 set: function(key, val, callback) {34 if (typeof key !== 'string')35 throw new Error(this.name + ' store #set() key must be a string')36 },37
1 unmodified line
39 * Ensure that the given _key_ is a string.40 * Override in subclass to provide data-store specific functionality.41 *42 * @param {string} key43 * @param {function} fn43 * @param {function} callback44 * @api public45 */46 47 get: function(key, fn) {47 get: function(key, callback) {48 if (typeof key !== 'string')49 throw new Error(this.name + 'store #get() key must be a string')50 },51
177 unmodified lines
modified:lib/express/plugins/hooks.js+12 added-12 removed
modified:lib/express/spec/mocks.js+16 added-16 removed
10 unmodified lines
11/**12 * Sync fs.readFile()13 */14 15fs.readFile = function(path, encoding, fn) {15fs.readFile = function(path, encoding, callback) {16 if (encoding instanceof Function)17 fn = encoding,17 callback = encoding,18 encoding = null19 try {20 fn(null, fs.readFileSync(path, encoding))20 callback(null, fs.readFileSync(path, encoding))21 } catch (e) {22 fn(e)22 callback(e)23 }24}2526/**27 * Sync path.exists()28 */29 30path.exists = function(path, fn) {30path.exists = function(path, callback) {31 try {32 fs.statSync(path)33 fn(true)33 callback(true)34 } catch (e) {35 fn(false)35 callback(false)36 }37}3839/**40 * Sync fs.stat()41 */42 43fs.stat = function(path, fn) {43fs.stat = function(path, callback) {44 try {45 fn(null, fs.statSync(path))45 callback(null, fs.statSync(path))46 } catch (e) {47 fn(e)47 callback(e)48 }49}5051// --- MockRequest
73 unmodified lines
125 * @return {MockResponse}126 * @api private127 */128129function request(method, path, options, fn) {129function request(method, path, options, callback) {130 var response = new MockResponse131 var request = new MockRequest(method, path, options)132 Express.server.route(request, response)133 return response
22 unmodified lines
156 * @api private157 */158159function route(method) {160 return function(path, options, fn){160 return function(path, options, callback){161 if (options instanceof Function)162 fn = options, options = {}163 if (fn instanceof Function)164 Express.routes.push(new Route(method, path, fn, options))162 callback = options, options = {}163 if (callback instanceof Function)164 Express.routes.push(new Route(method, path, callback, options))165 else166 return request(method, path, options, fn)166 return request(method, path, options, callback)167 }168}169170// --- Mock routing API
5 unmodified lines
modified:lib/express/core.js+5 added-5 removed
20 unmodified lines
21Route = new Class({22 23 /**24 * Initialize a route with the given _method_,25 * _path_, and callback _fn_.25 * _path_, and callback _callback_.26 *27 * The given _path_ becomes #originalPath, 28 * #path is then a normalized version converted29 * to a regular expression for routing.30 *31 * @param {string} method32 * @param {string} path33 * @param {function} fn33 * @param {function} callback34 * @param {hash} options35 * @api private36 */37 38 constructor: function(method, path, fn, options){38 constructor: function(method, path, callback, options){39 this.method = method40 this.originalPath = path41 this.path = this.normalize(path)42 this.fn = fn42 this.callback = callback43 },44 45 /**46 * Normalize _path_. When a RegExp it is simply returned,
60 unmodified lines
107 route: function() { 108 var body, 109 route = this.matchingRoute()110 if (route) {111 body = route.fn.apply(this.request, this.request.captures.slice(1));111 body = route.callback.apply(this.request, this.request.captures.slice(1));112 if (this.request.passed) {113 if (typeof this.request.passed === 'string')114 this.request.url.pathname = this.request.passed115 this.request.passed = false
218 unmodified lines
modified:lib/express/dsl.js+14 added-14 removed
8 unmodified lines
9 * @api private10 */1112function route(method) {13 return function(path, options, fn){13 return function(path, options, callback){14 if (options instanceof Function)15 fn = options, options = {}16 Express.routes.push(new Route(method, path, fn, options))15 callback = options, options = {}16 Express.routes.push(new Route(method, path, callback, options))17 }18}1920/**
55 unmodified lines
76 Express.server.run.apply(Express.server, arguments)77}7879/**80 * Configure _env_ with _fn_.80 * Configure _env_ with _callback_.81 *82 * Global configuration, disregards which83 * environment is active:84 *
11 unmodified lines
96 * 97 * configure('development')98 *99 * @param {string, function} env100 * @param {function} fn100 * @param {function} callback101 * @api public102 */103104exports.configure = function(env, fn) {104exports.configure = function(env, callback) {105 if (env instanceof Function)106 fn = env, env = 'all'107 if (fn instanceof Function)108 return Express.config.push([env, fn])106 callback = env, env = 'all'107 if (callback instanceof Function)108 return Express.config.push([env, callback])109 if (typeof env !== 'string')110 throw new TypeError('environment required')111 Express.config.each(function(conf){112 if (conf[0] === env ||
2 unmodified lines
115 })116}117118/**119 * Pre-process param _key_ with _fn_.119 * Pre-process param _key_ with _callback_.120 *121 * @param {string} key122 * @param {function} fn122 * @param {function} callback123 * @api public124 */125126exports.param = function(key, fn) {126exports.param = function(key, callback) {127 if (typeof key !== 'string')128 throw new TypeError('param key must be a string')129 if (typeof fn !== 'function')129 if (typeof callback !== 'function')130 throw new TypeError('param must pass a function to process "' + key + '"')131 Express.params[key] = fn131 Express.params[key] = callback132}133134// --- Routing API135
4 unmodified lines
modified:lib/express/http.js+9 added-9 removed