From 8c9cc0e1f4312249724a0867bfdf39217762276f Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Wed, 17 Aug 2016 09:09:45 -0400 Subject: [PATCH] lint docs --- api/router.js | 1 - bundler/lintdocs.js | 5 ++++- docs/jsonp.md | 6 +++--- docs/route.md | 20 ++++++++++---------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/api/router.js b/api/router.js index bd0c2295..0902da10 100644 --- a/api/router.js +++ b/api/router.js @@ -16,7 +16,6 @@ module.exports = function($window, renderer, pubsub) { current.path = path, current.component = component renderer.render(root, payload.view(Vnode(component, null, args, undefined, undefined, undefined))) } - if (typeof payload.onmatch !== "function") payload.onmatch = function() {resolve(current.component)} if (path !== current.path) payload.onmatch(Vnode(payload, null, args, undefined, undefined, undefined), resolve) else resolve(current.component) } diff --git a/bundler/lintdocs.js b/bundler/lintdocs.js index 36a4d423..d8213019 100644 --- a/bundler/lintdocs.js +++ b/bundler/lintdocs.js @@ -44,7 +44,10 @@ function ensureCodeIsRunnable(file, data) { } try { - new Function("console,fetch", code).call(this, silentConsole, fetch) + new Function("console,fetch,module,require", code).call(this, silentConsole, fetch, {exports: {}}, function(dep) { + if (dep.indexOf("./mycomponent") === 0) return {view: function() {}} + if (dep === "mithril") return m + }) } catch (e) {console.log(file + " - javascript code cannot run\n\n" + e.stack + "\n\n" + code + "\n\n---\n\n")} diff --git a/docs/jsonp.md b/docs/jsonp.md index 0523dc3a..09a4aa9c 100644 --- a/docs/jsonp.md +++ b/docs/jsonp.md @@ -59,10 +59,10 @@ m.jsonp({ And sometimes, you just want to take advantage of HTTP caching for GET requests for rarely-modified data: ```javascript -//this request is always called with the same querystring, and therefore it is cached +// this request is always called with the same querystring, and therefore it is cached m.jsonp({ - url: "https://api.github.com/users/lhorie" - callbackName: "__callback" + url: "https://api.github.com/users/lhorie", + callbackName: "__callback", }) .run(function(response) { console.log(response.data.login) // logs "lhorie" diff --git a/docs/route.md b/docs/route.md index e513318a..60d59525 100644 --- a/docs/route.md +++ b/docs/route.md @@ -109,13 +109,13 @@ The `view` method is called on every redraw for a matching route. It is similar `vnode = routeResolve.view(vnode)` -Argument | Type | Required | Description -------------------- | --------------- | -------- | ----------- -`vnode` | `Object` | | A [vnode](vnodes.md) whose attributes object contains routing parameters. If the routeResolver does not have a `resolve` method, the vnode's `tag` field defaults to a `div` -`vnode.attrs` | `Object` | | A [vnode](vnodes.md) whose attributes object contains routing parameters. If the routeResolver does not have a `resolve` method, the vnode defaults to a `div` -`vnode.attrs.path` | `String` | | The current router path, including interpolated routing parameter values, but without the prefix. Same value as `m.route.get()` -`vnode.attrs.route` | `String` | | The matched route -**returns** | `Vnode` | | Returns a vnode +Argument | Type | Description +------------------- | --------------- | ----------- +`vnode` | `Object` | A [vnode](vnodes.md) whose attributes object contains routing parameters. If the routeResolver does not have a `resolve` method, the vnode's `tag` field defaults to a `div` +`vnode.attrs` | `Object` | A [vnode](vnodes.md) whose attributes object contains routing parameters. If the routeResolver does not have a `resolve` method, the vnode defaults to a `div` +`vnode.attrs.path` | `String` | The current router path, including interpolated routing parameter values, but without the prefix. Same value as `m.route.get()` +`vnode.attrs.route` | `String` | The matched route +**returns** | `Vnode` | Returns a vnode --- @@ -212,7 +212,7 @@ When navigating to routes, there's no need to explicitly specify the router pref Sometimes we want to have a variable id or similar data appear in a route, but we don't want to explicitly specify a separate route for every possible id. In order to achieve that, Mithril supports parameterized routes: -``` +```javascript var Edit = { view: function(vnode) { return [ @@ -390,8 +390,8 @@ Fortunately, there are a number of tools that facilitate the task of bundling mo ```javascript m.route(document.body, "/", { "/": { - resolve: function(use) { - //using Webpack async code splitting + onmatch: function(use) { + // using Webpack async code splitting require(['./Home.js'], use) }, },