From 42e13c15590c560b076ebdb8398b978e28fe8294 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Wed, 23 Nov 2016 01:49:06 -0500 Subject: [PATCH] lint docs --- docs/lint.js | 9 ++++++++- docs/promise.md | 14 +++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/docs/lint.js b/docs/lint.js index ee359915..240eb368 100644 --- a/docs/lint.js +++ b/docs/lint.js @@ -70,12 +70,19 @@ function initMocks() { global.m = require("../index") global.o = require("../ospec/ospec") global.stream = require("../stream") + global.alert = function() {} //routes consumed by request.md global.window.$defineRoutes({ "GET /api/v1/users": function(request) { return {status: 200, responseText: JSON.stringify([{name: ""}])} }, + "GET /api/v1/users/search": function(request) { + return {status: 200, responseText: JSON.stringify([{id: 1, name: ""}])} + }, + "GET /api/v1/users/1/projects": function(request) { + return {status: 200, responseText: JSON.stringify([{id: 1, name: ""}])} + }, "GET /api/v1/todos": function(request) { return {status: 200, responseText: JSON.stringify([])} }, @@ -125,7 +132,7 @@ function traverseDirectory(pathname, callback) { //run traverseDirectory("./docs", function(pathname) { - if (pathname.indexOf(".md") > -1 && pathname.indexOf("migration") < 0 && pathname.indexOf("tutorial") < 0) { + if (pathname.indexOf(".md") > -1 && !pathname.match(/migration|zero|simple|node_modules/)) { fs.readFile(pathname, "utf8", function(err, data) { if (err) console.log(err) else lint(pathname, data) diff --git a/docs/promise.md b/docs/promise.md index 9a659d74..4cca9b48 100644 --- a/docs/promise.md +++ b/docs/promise.md @@ -191,9 +191,9 @@ In the refactored version, it's trivial to test whether `getFirstTen` has any of Promises absorb other promises. Basically, this means you can never receive a Promise as an argument to `onFulfilled` or `onRejected` callbacks for `then` and `catch` methods. This feature allows us to flatten nested promises to make code more manageable. -```Javascript +```javascript function searchUsers(q) {return m.request("/api/v1/users/search", {data: {q: q}})} -function getUserProjects() {return m.request("/api/v1/user/" + id + "/projects")} +function getUserProjects(id) {return m.request("/api/v1/users/" + id + "/projects")} // AVOID: pyramid of doom searchUsers("John").then(function(users) { @@ -230,7 +230,7 @@ searchUsers("John") .then(getProjectTitles) .then(alert) .catch(function(e) { - console.error(e) + console.log(e) }) ``` @@ -275,10 +275,10 @@ Promise.all([ // data[0] is an array of users whose names are John // data[1] is an array of users whose names are Mary - //the returned value is equivalent to [ - // getUserNames(data[0]), - // getUserNames(data[1]), - //] + // the returned value is equivalent to [ + // getUserNames(data[0]), + // getUserNames(data[1]), + // ] return data.map(getUserNames) }) .then(alert)