diff --git a/.eslintignore b/.eslintignore index 1b9fe34c..08396583 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,11 +1,6 @@ -coverage .vscode -examples -docs -node_modules -tests -test-utils -ospec -mithril.js -mithril.min.js -archive +/node_modules +/examples +/docs/lib +/mithril.js +/mithril.min.js diff --git a/.eslintrc.js b/.eslintrc.js index 25278201..bdd0cd98 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -60,7 +60,14 @@ module.exports = { "id-blacklist": "error", "id-length": "off", "id-match": "error", - "indent": "off", + "indent": [ + "warn", + "tab", + { + "outerIIFEBody": 0, + "SwitchCase": 1 + } + ], "init-declarations": "off", "jsx-quotes": "error", "key-spacing": "off", @@ -188,7 +195,7 @@ module.exports = { "quotes": [ "error", "double", - "avoid-escape" + {"avoidEscape": true} ], "radix": [ "error", @@ -209,7 +216,7 @@ module.exports = { "space-infix-ops": "off", "space-unary-ops": "error", "spaced-comment": "off", - "strict": "off", + "strict": ["error", "global"], "template-curly-spacing": "error", "valid-jsdoc": "off", "vars-on-top": "off", @@ -217,5 +224,6 @@ module.exports = { "wrap-regex": "error", "yield-star-spacing": "error", "yoda": "off" - } -}; \ No newline at end of file + }, + "root": true +}; diff --git a/.gitignore b/.gitignore index 8af32a76..285af458 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ jsconfig.json npm-debug.log .vscode .DS_Store +.eslintcache diff --git a/.travis.yml b/.travis.yml index af37c828..154fc1ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,10 +10,10 @@ cache: directories: - node_modules -# Custom install step so the travis scripts don't need to be in package.json +# Custom install step so the travis-only stuff doesn't need to be in package.json install: - npm install -- npm install @alrra/travis-scripts@^3.0.1 +- npm install @alrra/travis-scripts@^3.0.1 gh-pages@^0.12.0 # Bundle before running tests so the bundle is always up-to-date before_script: npm run build @@ -21,37 +21,43 @@ before_script: npm run build # This is the default, but leaving so it is obvious # script: npm test -# After a successful build create bundles & commit back to the repo +# After a successful build commit changes back to repo after_success: - | + # Set up SSH environment + $(npm bin)/set-up-ssh \ + --key "$encrypted_8b86e0359d64_key" \ + --iv "$encrypted_8b86e0359d64_iv" \ + --path-encrypted-key "./.deploy.enc" + + # Commit bundle changes generated in before_script step + # --commands is a weird no-op but required for commit-changes to run + # --branch arg is to ensure this only runs against the `next` branch + $(npm bin)/commit-changes \ + --commands "echo committing" \ + --commit-message "Bundled output for commit $TRAVIS_COMMIT [skip ci]" \ + --branch "next" - # Only want to commit when building a push on whatever $BRANCH is + # Only want to commit docs when building pushes on master & + # this doesn't have the built-in branch protection likt commit-changes if [ "$TRAVIS_EVENT_TYPE" == "push" ] && \ - [ "$TRAVIS_BRANCH" == "$BRANCH" ] && \ - [ "$TRAVIS_REPO_SLUG" == "$REPO" ] + [ "$TRAVIS_BRANCH" == "master" ] && \ + [ "$TRAVIS_REPO_SLUG" == "lhorie/mithril.js" ] then - # Set up SSH environment - $(npm bin)/set-up-ssh \ - --key "$encrypted_8b86e0359d64_key" \ - --iv "$encrypted_8b86e0359d64_iv" \ - --path-encrypted-key "./.deploy.enc" + # Generate docs + $(npm-bin) run gendocs - # Commit changes (if there were any) from running build earlier - $(npm bin)/commit-changes \ - --commands "echo committing" \ - --commit-message "Bundled output for commit $TRAVIS_COMMIT [skip ci]" \ - --branch "$BRANCH" + # Commit docs to gh-pages branch + # Using --add to ensure that archived versions aren't lost + # Using --repo to force it to go over SSH so the saved keys are used (tschaub/gh-pages#160) + $(npm bin)/gh-pages --dist ./dist --add --repo "git@github.com:lhorie/mithril.js.git" else - echo "Not submitting build artifacts" + echo "Not submitting documentation updates" fi - + # Environment configuration env: global: - # Restrict the branch this will activate on - - BRANCH=next - - REPO=lhorie/mithril.js - # Set up GH_USER_EMAIL & GH_USER_NAME env variables used by travis-scripts package - secure: Xvqvm3+PvJu/rs3jl/NNn0RWLkkLkIoPHiL0GCfVRaywgjCYVN02g54NVvIDaOfybqPmu9E6PJFVs92vhF34NMFQHf4EWskynusIGV271R2BV0i+OJBfLMuLgiwm6zRn7/Zw4JvWIUGEwcnlz0qxbqdHsS0SOR3fIkFzePickW0= - secure: Rf/ldEO9d4vItJhe6EmqWpFAyCARzoCb422nHnjr1hYJknnwIXpgyZ1C/7On/9o7rWPPf+8WcHC/rgjK2rthKCldzdG5I60LfWSNzap9lk3Aa4TpSCoDBuEp7JVvDr5tc3rKnBXVT71hOay7RSx1StWzXiJs9mjaeVMJzYzRT78= diff --git a/api/redraw.js b/api/redraw.js index e975d286..1b22271b 100644 --- a/api/redraw.js +++ b/api/redraw.js @@ -38,10 +38,10 @@ module.exports = function($window) { var index = callbacks.indexOf(key) if (index > -1) callbacks.splice(index, 2) } - function redraw() { - for (var i = 1; i < callbacks.length; i += 2) { - callbacks[i]() - } - } + function redraw() { + for (var i = 1; i < callbacks.length; i += 2) { + callbacks[i]() + } + } return {subscribe: subscribe, unsubscribe: unsubscribe, redraw: redraw, render: renderService.render} } diff --git a/api/tests/test-mount.js b/api/tests/test-mount.js index 4ba466c7..db2bee04 100644 --- a/api/tests/test-mount.js +++ b/api/tests/test-mount.js @@ -71,8 +71,8 @@ o.spec("mount", function() { o("redraws on events", function(done) { var onupdate = o.spy() - var oninit = o.spy() - var onclick = o.spy() + var oninit = o.spy() + var onclick = o.spy() var e = $window.document.createEvent("MouseEvents") e.initEvent("click", true, true) @@ -107,13 +107,13 @@ o.spec("mount", function() { o("redraws several mount points on events", function(done, timeout) { timeout(60) - + var onupdate0 = o.spy() - var oninit0 = o.spy() - var onclick0 = o.spy() + var oninit0 = o.spy() + var onclick0 = o.spy() var onupdate1 = o.spy() - var oninit1 = o.spy() - var onclick1 = o.spy() + var oninit1 = o.spy() + var onclick1 = o.spy() var e = $window.document.createEvent("MouseEvents") @@ -228,7 +228,7 @@ o.spec("mount", function() { done() }, FRAME_BUDGET) }) - + o("throttles", function(done, timeout) { timeout(200) @@ -252,4 +252,4 @@ o.spec("mount", function() { }) }) }) -}) \ No newline at end of file +}) diff --git a/api/tests/test-router.js b/api/tests/test-router.js index f43605e1..9406de70 100644 --- a/api/tests/test-router.js +++ b/api/tests/test-router.js @@ -6,7 +6,6 @@ var browserMock = require("../../test-utils/browserMock") var m = require("../../render/hyperscript") var callAsync = require("../../test-utils/callAsync") -var coreRenderer = require("../../render/render") var apiRedraw = require("../../api/redraw") var apiRouter = require("../../api/router") var Promise = require("../../promise/promise") @@ -31,7 +30,7 @@ o.spec("route", function() { o("throws on invalid `root` DOM node", function() { var threw = false try { - route(null, '/', {'/':{view: function() {}}}) + route(null, "/", {"/":{view: function() {}}}) } catch (e) { threw = true } @@ -141,7 +140,7 @@ o.spec("route", function() { done() } }) - + o("redraws when render function is executed", function() { var onupdate = o.spy() var oninit = o.spy() @@ -206,7 +205,6 @@ o.spec("route", function() { o("event handlers can skip redraw", function(done) { var onupdate = o.spy() var oninit = o.spy() - var onclick = o.spy() var e = $window.document.createEvent("MouseEvents") e.initEvent("click", true, true) @@ -354,11 +352,6 @@ o.spec("route", function() { o("accepts RouteResolver with onmatch that returns Promise", function(done) { var matchCount = 0 var renderCount = 0 - var Component = { - view: function() { - return m("span") - } - } var resolver = { onmatch: function(args, requestedPath) { @@ -395,11 +388,6 @@ o.spec("route", function() { o("accepts RouteResolver with onmatch that returns Promise", function(done) { var matchCount = 0 var renderCount = 0 - var Component = { - view: function() { - return m("span") - } - } var resolver = { onmatch: function(args, requestedPath) { @@ -437,14 +425,9 @@ o.spec("route", function() { var matchCount = 0 var renderCount = 0 var spy = o.spy() - var Component = { - view: function() { - return m("span") - } - } var resolver = { - onmatch: function(args, requestedPath) { + onmatch: function() { matchCount++ return Promise.reject(new Error("error")) }, @@ -499,7 +482,7 @@ o.spec("route", function() { }) }) - o("changing `vnode.key` in `render` resets the component", function(done, timeout){ + o("changing `vnode.key` in `render` resets the component", function(done){ var oninit = o.spy() var Component = { oninit: oninit, @@ -545,25 +528,19 @@ o.spec("route", function() { }) o(root.firstChild.nodeName).equals("DIV") + o(renderCount).equals(1) }) o("RouteResolver `render` does not have component semantics", function(done) { - var renderCount = 0 - var A = { - view: function() { - return m("div") - } - } - $window.location.href = prefix + "/a" route(root, "/a", { "/a" : { - render: function(vnode) { + render: function() { return m("div") }, }, "/b" : { - render: function(vnode) { + render: function() { return m("div") }, }, @@ -632,7 +609,7 @@ o.spec("route", function() { onmatch: function() { matchCount++ }, - render: function(vnode) { + render: function() { renderCount++ return {tag: Component} }, @@ -726,7 +703,7 @@ o.spec("route", function() { render: render }, "/b" : { - render: function(vnode){ + render: function(){ redirected = true } } @@ -838,7 +815,7 @@ o.spec("route", function() { }) callAsync(function() { - route.set('/b') + route.set("/b") callAsync(function() { callAsync(function() { callAsync(function() { @@ -865,7 +842,7 @@ o.spec("route", function() { render: render }, "/b" : { - onmatch: function(vnode){ + onmatch: function(){ redirected = true return {view: function() {}} } @@ -895,7 +872,7 @@ o.spec("route", function() { render: render }, "/b" : { - render: function(vnode){ + render: function(){ redirected = true } } @@ -924,7 +901,7 @@ o.spec("route", function() { render: render }, "/b" : { - view: function(vnode){ + view: function(){ redirected = true } } @@ -1032,7 +1009,7 @@ o.spec("route", function() { var render = o.spy(function() {return m("div")}) $window.location.href = prefix + "/" - route(root, '/', { + route(root, "/", { "/": { onmatch: onmatch, render: render @@ -1081,23 +1058,23 @@ o.spec("route", function() { o("routing with RouteResolver works more than once", function(done) { $window.location.href = prefix + "/a" - route(root, '/a', { - '/a': { + route(root, "/a", { + "/a": { render: function() { return m("a", "a") } }, - '/b': { + "/b": { render: function() { return m("b", "b") } } }) - route.set('/b') + route.set("/b") callAsync(function() { - route.set('/a') + route.set("/a") callAsync(function() { o(root.firstChild.nodeName).equals("A") @@ -1122,7 +1099,7 @@ o.spec("route", function() { }) }) }, - render: function(vnode) { + render: function() { rendered = true resolved = "a" } @@ -1180,7 +1157,7 @@ o.spec("route", function() { route.set("/b") }) }, - render: function(vnode) { + render: function() { rendered = true resolved = "a" } @@ -1210,7 +1187,7 @@ o.spec("route", function() { var i = 0 $window.location.href = prefix + "/" route(root, "/", { - "/": {view: function(v) {i++}} + "/": {view: function() {i++}} }) var before = i diff --git a/browser.js b/browser.js index fed323f1..0debb4ea 100644 --- a/browser.js +++ b/browser.js @@ -1,3 +1,5 @@ +"use strict" + var m = require("./index") if (typeof module !== "undefined") module["exports"] = m else window.m = m diff --git a/bundler/bin/bundle b/bundler/bin/bundle index e0c4279a..81c65c90 100644 --- a/bundler/bin/bundle +++ b/bundler/bin/bundle @@ -1,3 +1,4 @@ #!/usr/bin/env node +"use strict" require("../cli") diff --git a/bundler/tests/test-bundler.js b/bundler/tests/test-bundler.js index 5af0d74a..15e7f932 100644 --- a/bundler/tests/test-bundler.js +++ b/bundler/tests/test-bundler.js @@ -1,3 +1,5 @@ +"use strict" + var o = require("../../ospec/ospec") var bundle = require("../bundle") @@ -5,10 +7,10 @@ var fs = require("fs") var ns = "bundler/tests/" function read(filepath) { - try {return fs.readFileSync(ns + filepath, "utf8")} catch (e) {} + try {return fs.readFileSync(ns + filepath, "utf8")} catch (e) {/* ignore */} } function write(filepath, data) { - try {var exists = fs.statSync(ns + filepath).isFile()} catch (e) {} + try {var exists = fs.statSync(ns + filepath).isFile()} catch (e) {/* ignore */} if (exists) throw new Error("Don't call `write('" + filepath + "')`. Cannot overwrite file") fs.writeFileSync(ns + filepath, data, "utf8") } @@ -18,254 +20,255 @@ function remove(filepath) { o.spec("bundler", function() { o("relative imports works", function() { - write("a.js", `var b = require("./b")`) - write("b.js", `module.exports = 1`) + write("a.js", 'var b = require("./b")') + write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals(`;(function() {\nvar b = 1\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar b = 1\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports works with semicolons", function() { - write("a.js", `var b = require("./b");`) - write("b.js", `module.exports = 1;`) + write("a.js", 'var b = require("./b");') + write("b.js", "module.exports = 1;") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals(`;(function() {\nvar b = 1;\n}());`) - + o(read("out.js")).equals(";(function() {\nvar b = 1;\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports works with let", function() { - write("a.js", `let b = require("./b")`) - write("b.js", `module.exports = 1`) + write("a.js", 'let b = require("./b")') + write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals(`;(function() {\nlet b = 1\n}());`) - + o(read("out.js")).equals(";(function() {\nlet b = 1\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports works with const", function() { write("a.js", 'const b = require("./b")') - write("b.js", `module.exports = 1`) + write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals(`;(function() {\nconst b = 1\n}());`) - + o(read("out.js")).equals(";(function() {\nconst b = 1\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports works with assignment", function() { - write("a.js", `var a = {}\na.b = require("./b")`) - write("b.js", `module.exports = 1`) + write("a.js", 'var a = {}\na.b = require("./b")') + write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar a = {}\na.b = 1\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar a = {}\na.b = 1\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports works with reassignment", function() { - write("a.js", `var b = {}\nb = require("./b")`) - write("b.js", `module.exports = 1`) + write("a.js", 'var b = {}\nb = require("./b")') + write("b.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar b = {}\nb = 1\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar b = {}\nb = 1\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports removes extra use strict", function() { - write("a.js", `"use strict"\nvar b = require("./b")`) - write("b.js", `"use strict"\nmodule.exports = 1`) + write("a.js", '"use strict"\nvar b = require("./b")') + write("b.js", '"use strict"\nmodule.exports = 1') bundle(ns + "a.js", ns + "out.js") - o(read("out.js")).equals(`;(function() {\n"use strict"\nvar b = 1\n}());`) - + o(read("out.js")).equals(';(function() {\n"use strict"\nvar b = 1\n}());') + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports removes extra use strict using single quotes", function() { - write("a.js", `'use strict'\nvar b = require("./b")`) - write("b.js", `'use strict'\nmodule.exports = 1`) + write("a.js", "'use strict'\nvar b = require(\"./b\")") + write("b.js", "'use strict'\nmodule.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\n'use strict'\nvar b = 1\n}());`) - + + o(read("out.js")).equals(";(function() {\n'use strict'\nvar b = 1\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("relative imports removes extra use strict using mixed quotes", function() { - write("a.js", `"use strict"\nvar b = require("./b")`) - write("b.js", `'use strict'\nmodule.exports = 1`) + write("a.js", '"use strict"\nvar b = require("./b")') + write("b.js", "'use strict'\nmodule.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\n"use strict"\nvar b = 1\n}());`) - + + o(read("out.js")).equals(';(function() {\n"use strict"\nvar b = 1\n}());') + remove("a.js") remove("b.js") remove("out.js") }) o("works w/ window", function() { - write("a.js", `window.a = 1\nvar b = require("./b")`) - write("b.js", `module.exports = function() {return a}`) + write("a.js", 'window.a = 1\nvar b = require("./b")') + write("b.js", "module.exports = function() {return a}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nwindow.a = 1\nvar b = function() {return a}\n}());`) - + + o(read("out.js")).equals(";(function() {\nwindow.a = 1\nvar b = function() {return a}\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("works without assignment", function() { - write("a.js", `require("./b")`) - write("b.js", `1 + 1`) + write("a.js", 'require("./b")') + write("b.js", "1 + 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\n1 + 1\n}());`) - + + o(read("out.js")).equals(";(function() {\n1 + 1\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("works if used fluently", function() { - write("a.js", `var b = require("./b").toString()`) - write("b.js", `module.exports = []`) + write("a.js", 'var b = require("./b").toString()') + write("b.js", "module.exports = []") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar _0 = []\nvar b = _0.toString()\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar _0 = []\nvar b = _0.toString()\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("works if used fluently w/ multiline", function() { - write("a.js", `var b = require("./b")\n\t.toString()`) - write("b.js", `module.exports = []`) + write("a.js", 'var b = require("./b")\n\t.toString()') + write("b.js", "module.exports = []") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar _0 = []\nvar b = _0\n\t.toString()\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar _0 = []\nvar b = _0\n\t.toString()\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("works if used w/ curry", function() { - write("a.js", `var b = require("./b")()`) - write("b.js", `module.exports = function() {}`) + write("a.js", 'var b = require("./b")()') + write("b.js", "module.exports = function() {}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar _0 = function() {}\nvar b = _0()\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar _0 = function() {}\nvar b = _0()\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("works if used w/ curry w/ multiline", function() { - write("a.js", `var b = require("./b")\n()`) - write("b.js", `module.exports = function() {}`) + write("a.js", 'var b = require("./b")\n()') + write("b.js", "module.exports = function() {}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar _0 = function() {}\nvar b = _0\n()\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar _0 = function() {}\nvar b = _0\n()\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("works if used fluently in one place and not in another", function() { - write("a.js", `var b = require("./b").toString()\nvar c = require("./c")`) - write("b.js", `module.exports = []`) - write("c.js", `var b = require("./b")\nmodule.exports = function() {return b}`) + write("a.js", 'var b = require("./b").toString()\nvar c = require("./c")') + write("b.js", "module.exports = []") + write("c.js", 'var b = require("./b")\nmodule.exports = function() {return b}') bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar _0 = []\nvar b = _0.toString()\nvar b0 = _0\nvar c = function() {return b0}\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar _0 = []\nvar b = _0.toString()\nvar b0 = _0\nvar c = function() {return b0}\n}());") + remove("a.js") remove("b.js") remove("c.js") remove("out.js") }) o("works if used in sequence", function() { - write("a.js", `var b = require("./b"), c = require("./c")`) - write("b.js", `module.exports = 1`) - write("c.js", `var x\nmodule.exports = 2`) + write("a.js", 'var b = require("./b"), c = require("./c")') + write("b.js", "module.exports = 1") + write("c.js", "var x\nmodule.exports = 2") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar b = 1\nvar x\nvar c = 2\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar b = 1\nvar x\nvar c = 2\n}());") + remove("a.js") remove("b.js") remove("c.js") remove("out.js") }) o("works if assigned to property", function() { - write("a.js", `var x = {}\nx.b = require("./b")\nx.c = require("./c")`) - write("b.js", `var bb = 1\nmodule.exports = bb`) - write("c.js", `var cc = 2\nmodule.exports = cc`) + write("a.js", 'var x = {}\nx.b = require("./b")\nx.c = require("./c")') + write("b.js", "var bb = 1\nmodule.exports = bb") + write("c.js", "var cc = 2\nmodule.exports = cc") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar x = {}\nvar bb = 1\nx.b = bb\nvar cc = 2\nx.c = cc\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar x = {}\nvar bb = 1\nx.b = bb\nvar cc = 2\nx.c = cc\n}());") + remove("a.js") remove("b.js") remove("c.js") remove("out.js") }) o("works if assigned to property using bracket notation", function() { - write("a.js", `var x = {}\nx["b"] = require("./b")\nx["c"] = require("./c")`) - write("b.js", `var bb = 1\nmodule.exports = bb`) - write("c.js", `var cc = 2\nmodule.exports = cc`) + write("a.js", 'var x = {}\nx["b"] = require("./b")\nx["c"] = require("./c")') + write("b.js", "var bb = 1\nmodule.exports = bb") + write("c.js", "var cc = 2\nmodule.exports = cc") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar x = {}\nvar bb = 1\nx["b"] = bb\nvar cc = 2\nx["c"] = cc\n}());`) - + + o(read("out.js")).equals(';(function() {\nvar x = {}\nvar bb = 1\nx["b"] = bb\nvar cc = 2\nx["c"] = cc\n}());') + remove("a.js") remove("b.js") remove("c.js") remove("out.js") }) o("works if collision", function() { - write("a.js", `var b = require("./b")`) - write("b.js", `var b = 1\nmodule.exports = 2`) + write("a.js", 'var b = require("./b")') + write("b.js", "var b = 1\nmodule.exports = 2") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar b0 = 1\nvar b = 2\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar b0 = 1\nvar b = 2\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("works if multiple aliases", function() { - write("a.js", `var b = require("./b")\n`) - write("b.js", `var b = require("./c")\nb.x = 1\nmodule.exports = b`) - write("c.js", `var b = {}\nmodule.exports = b`) + write("a.js", 'var b = require("./b")\n') + write("b.js", 'var b = require("./c")\nb.x = 1\nmodule.exports = b') + write("c.js", "var b = {}\nmodule.exports = b") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar b = {}\nb.x = 1\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar b = {}\nb.x = 1\n}());") + remove("a.js") remove("b.js") remove("c.js") remove("out.js") }) o("works if multiple collision", function() { - write("a.js", `var b = require("./b")\nvar c = require("./c")\nvar d = require("./d")`) - write("b.js", `var a = 1\nmodule.exports = a`) - write("c.js", `var a = 2\nmodule.exports = a`) - write("d.js", `var a = 3\nmodule.exports = a`) + write("a.js", 'var b = require("./b")\nvar c = require("./c")\nvar d = require("./d")') + write("b.js", "var a = 1\nmodule.exports = a") + write("c.js", "var a = 2\nmodule.exports = a") + write("d.js", "var a = 3\nmodule.exports = a") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar a = 1\nvar b = a\nvar a0 = 2\nvar c = a0\nvar a1 = 3\nvar d = a1\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar a = 1\nvar b = a\nvar a0 = 2\nvar c = a0\nvar a1 = 3\nvar d = a1\n}());") + remove("a.js") remove("b.js") remove("c.js") @@ -273,38 +276,38 @@ o.spec("bundler", function() { remove("out.js") }) o("works if included multiple times", function() { - write("a.js", `module.exports = 123`) - write("b.js", `var a = require("./a").toString()\nmodule.exports = a`) - write("c.js", `var a = require("./a").toString()\nvar b = require("./b")`) + write("a.js", "module.exports = 123") + write("b.js", 'var a = require("./a").toString()\nmodule.exports = a') + write("c.js", 'var a = require("./a").toString()\nvar b = require("./b")') bundle(ns + "c.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar _0 = 123\nvar a = _0.toString()\nvar a0 = _0.toString()\nvar b = a0\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar _0 = 123\nvar a = _0.toString()\nvar a0 = _0.toString()\nvar b = a0\n}());") + remove("a.js") remove("b.js") remove("c.js") }) o("works if included multiple times reverse", function() { - write("a.js", `module.exports = 123`) - write("b.js", `var a = require("./a").toString()\nmodule.exports = a`) - write("c.js", `var b = require("./b")\nvar a = require("./a").toString()`) + write("a.js", "module.exports = 123") + write("b.js", 'var a = require("./a").toString()\nmodule.exports = a') + write("c.js", 'var b = require("./b")\nvar a = require("./a").toString()') bundle(ns + "c.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar _0 = 123\nvar a0 = _0.toString()\nvar b = a0\nvar a = _0.toString()\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar _0 = 123\nvar a0 = _0.toString()\nvar b = a0\nvar a = _0.toString()\n}());") + remove("a.js") remove("b.js") remove("c.js") }) o("reuses binding if possible", function() { - write("a.js", `var b = require("./b")\nvar c = require("./c")`) - write("b.js", `var d = require("./d")\nmodule.exports = function() {return d + 1}`) - write("c.js", `var d = require("./d")\nmodule.exports = function() {return d + 2}`) - write("d.js", `module.exports = 1`) + write("a.js", 'var b = require("./b")\nvar c = require("./c")') + write("b.js", 'var d = require("./d")\nmodule.exports = function() {return d + 1}') + write("c.js", 'var d = require("./d")\nmodule.exports = function() {return d + 2}') + write("d.js", "module.exports = 1") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar d = 1\nvar b = function() {return d + 1}\nvar c = function() {return d + 2}\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar d = 1\nvar b = function() {return d + 1}\nvar c = function() {return d + 2}\n}());") + remove("a.js") remove("b.js") remove("c.js") @@ -312,71 +315,71 @@ o.spec("bundler", function() { remove("out.js") }) o("disambiguates conflicts if imported collides with itself", function() { - write("a.js", `var b = require("./b")`) - write("b.js", `var b = 1\nmodule.exports = function() {return b}`) + write("a.js", 'var b = require("./b")') + write("b.js", "var b = 1\nmodule.exports = function() {return b}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar b0 = 1\nvar b = function() {return b0}\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar b0 = 1\nvar b = function() {return b0}\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("disambiguates conflicts if imported collides with something else", function() { - write("a.js", `var a = 1\nvar b = require("./b")`) - write("b.js", `var a = 2\nmodule.exports = function() {return a}`) + write("a.js", 'var a = 1\nvar b = require("./b")') + write("b.js", "var a = 2\nmodule.exports = function() {return a}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar a = 1\nvar a0 = 2\nvar b = function() {return a0}\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar a = 1\nvar a0 = 2\nvar b = function() {return a0}\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("disambiguates conflicts if imported collides with function declaration", function() { - write("a.js", `function a() {}\nvar b = require("./b")`) - write("b.js", `var a = 2\nmodule.exports = function() {return a}`) + write("a.js", 'function a() {}\nvar b = require("./b")') + write("b.js", "var a = 2\nmodule.exports = function() {return a}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nfunction a() {}\nvar a0 = 2\nvar b = function() {return a0}\n}());`) - + + o(read("out.js")).equals(";(function() {\nfunction a() {}\nvar a0 = 2\nvar b = function() {return a0}\n}());") + remove("a.js") remove("b.js") remove("out.js") }) o("disambiguates conflicts if imported collides with another module's private", function() { - write("a.js", `var b = require("./b")\nvar c = require("./c")`) - write("b.js", `var a = 1\nmodule.exports = function() {return a}`) - write("c.js", `var a = 2\nmodule.exports = function() {return a}`) + write("a.js", 'var b = require("./b")\nvar c = require("./c")') + write("b.js", "var a = 1\nmodule.exports = function() {return a}") + write("c.js", "var a = 2\nmodule.exports = function() {return a}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar a = 1\nvar b = function() {return a}\nvar a0 = 2\nvar c = function() {return a0}\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar a = 1\nvar b = function() {return a}\nvar a0 = 2\nvar c = function() {return a0}\n}());") + remove("a.js") remove("b.js") remove("c.js") remove("out.js") }) o("does not mess up strings", function() { - write("a.js", `var b = require("./b")`) - write("b.js", `var b = "b b b \\\" b"\nmodule.exports = function() {return b}`) + write("a.js", 'var b = require("./b")') + write("b.js", 'var b = "b b b \\" b"\nmodule.exports = function() {return b}') bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar b0 = "b b b \\\" b"\nvar b = function() {return b0}\n}());`) - + + o(read("out.js")).equals(';(function() {\nvar b0 = "b b b \\\" b"\nvar b = function() {return b0}\n}());') + remove("a.js") remove("b.js") remove("out.js") }) o("does not mess up properties", function() { - write("a.js", `var b = require("./b")`) - write("b.js", `var b = {b: 1}\nmodule.exports = function() {return b.b}`) + write("a.js", 'var b = require("./b")') + write("b.js", "var b = {b: 1}\nmodule.exports = function() {return b.b}") bundle(ns + "a.js", ns + "out.js") - - o(read("out.js")).equals(`;(function() {\nvar b0 = {b: 1}\nvar b = function() {return b0.b}\n}());`) - + + o(read("out.js")).equals(";(function() {\nvar b0 = {b: 1}\nvar b = function() {return b0.b}\n}());") + remove("a.js") remove("b.js") remove("out.js") }) -}) \ No newline at end of file +}) diff --git a/docs/CNAME b/docs/CNAME new file mode 100644 index 00000000..5c153480 --- /dev/null +++ b/docs/CNAME @@ -0,0 +1 @@ +mithril.js.org diff --git a/docs/generate.js b/docs/generate.js index bcf5465e..438b8343 100644 --- a/docs/generate.js +++ b/docs/generate.js @@ -1,15 +1,17 @@ +"use strict" + var fs = require("fs") var path = require("path") var marked = require("marked") var layout = fs.readFileSync("./docs/layout.html", "utf-8") var version = JSON.parse(fs.readFileSync("./package.json", "utf-8")).version -try {fs.mkdirSync("../mithril")} catch (e) {} -try {fs.mkdirSync("../mithril/archive")} catch (e) {} -try {fs.mkdirSync("../mithril/archive/v" + version)} catch (e) {} -try {fs.mkdirSync("../mithril/archive/v" + version + "/lib")} catch (e) {} -try {fs.mkdirSync("../mithril/archive/v" + version + "/lib/prism")} catch (e) {} -try {fs.mkdirSync("../mithril/lib")} catch (e) {} -try {fs.mkdirSync("../mithril/lib/prism")} catch (e) {} +try {fs.mkdirSync("./dist")} catch (e) {/* ignore */} +try {fs.mkdirSync("./dist/archive")} catch (e) {/* ignore */} +try {fs.mkdirSync("./dist/archive/v" + version)} catch (e) {/* ignore */} +try {fs.mkdirSync("./dist/archive/v" + version + "/lib")} catch (e) {/* ignore */} +try {fs.mkdirSync("./dist/archive/v" + version + "/lib/prism")} catch (e) {/* ignore */} +try {fs.mkdirSync("./dist/lib")} catch (e) {/* ignore */} +try {fs.mkdirSync("./dist/lib/prism")} catch (e) {/* ignore */} var guides = fs.readFileSync("docs/guides.md", "utf-8") var methods = fs.readFileSync("docs/methods.md", "utf-8") @@ -33,7 +35,7 @@ function generate(pathname) { .replace(/`((?:\S| -> |, )+)(\|)(\S+)`/gim, function(match, a, b, c) { // fix pipes in code tags return "" + (a + b + c).replace(/\|/g, "|") + "" }) - .replace(/(^# .+?(?:\r?\n){2,}?)(?:(-(?:.|\r|\n)+?)((?:\r?\n){2,})|)/m, function(match, title, nav, space) { // inject menu + .replace(/(^# .+?(?:\r?\n){2,}?)(?:(-(?:.|\r|\n)+?)((?:\r?\n){2,})|)/m, function(match, title, nav) { // inject menu var file = path.basename(pathname) var link = new RegExp("([ \t]*)(- )(\\[.+?\\]\\(" + file + "\\))") var replace = function(match, space, li, link) { @@ -53,14 +55,14 @@ function generate(pathname) { .replace(/\[version\]/, version) // update version .replace(/\[body\]/, markedHtml) .replace(/(.+?)<\/h.>/gim, function(match, n, id, text) { // fix anchors - return "/g, "").replace(/.+?<\/a>/g, "").replace(/\.|\[|\]|"|\/|\(|\)/g, "").replace(/\s/g, "-") + "\">" + text + "" + return ".+?<\/a>/g, "").replace(/\.|\[|\]|"|\/|\(|\)/g, "").replace(/\s/g, "-") + '">' + text + "" }) - fs.writeFileSync("../mithril/archive/v" + version + "/" + outputFilename.replace(/^docs\//, ""), html, "utf-8") - fs.writeFileSync("../mithril/" + outputFilename.replace(/^docs\//, ""), html, "utf-8") + fs.writeFileSync("./dist/archive/v" + version + "/" + outputFilename.replace(/^docs\//, ""), html, "utf-8") + fs.writeFileSync("./dist/" + outputFilename.replace(/^docs\//, ""), html, "utf-8") } else if (!pathname.match(/lint|generate/)) { - fs.writeFileSync("../mithril/archive/v" + version + "/" + pathname.replace(/^docs\//, ""), fs.readFileSync(pathname, "utf-8"), "utf-8") - fs.writeFileSync("../mithril/" + pathname.replace(/^docs\//, ""), fs.readFileSync(pathname, "utf-8"), "utf-8") + fs.writeFileSync("./dist/archive/v" + version + "/" + pathname.replace(/^docs\//, ""), fs.readFileSync(pathname, "utf-8"), "utf-8") + fs.writeFileSync("./dist/" + pathname.replace(/^docs\//, ""), fs.readFileSync(pathname, "utf-8"), "utf-8") } } } diff --git a/docs/jsx.md b/docs/jsx.md index a299c4d4..9ce6163c 100644 --- a/docs/jsx.md +++ b/docs/jsx.md @@ -45,8 +45,8 @@ var link = {greeting + "!"} Components can be used by using a convention of uppercasing the first letter of the component name: ```jsx -m.mount(document.body, ) -// equivalent to m.mount(document.body, m(MyComponent)) +m.render(document.body, ) +// equivalent to m.render(document.body, m(MyComponent)) ``` --- diff --git a/docs/lint.js b/docs/lint.js index 3ab0d559..2fb39e3b 100644 --- a/docs/lint.js +++ b/docs/lint.js @@ -1,4 +1,5 @@ #!/usr/bin/env node +"use strict" var fs = require("fs") var path = require("path") @@ -100,11 +101,11 @@ function ensureLinkIsValid(file, data) { } function initMocks() { - global.window = require("../test-utils/browserMock")() + global.window = require("../test-utils/browserMock")() // eslint-disable-line global-require global.document = window.document - global.m = require("../index") - global.o = require("../ospec/ospec") - global.stream = require("../stream") + global.m = require("../index") // eslint-disable-line global-require + global.o = require("../ospec/ospec") // eslint-disable-line global-require + global.stream = require("../stream") // eslint-disable-line global-require global.alert = function() {} //routes consumed by request.md @@ -121,7 +122,7 @@ function initMocks() { "GET /api/v1/todos": function() { return {status: 200, responseText: JSON.stringify([])} }, - "PUT /api/v1/users/1": function() { + "PUT /api/v1/users/1": function(request) { return {status: 200, responseText: request.query.callback ? request.query.callback + "([])" : "[]"} }, "POST /api/v1/upload": function() { diff --git a/docs/vnodes.md b/docs/vnodes.md index e8df0199..317b9c47 100644 --- a/docs/vnodes.md +++ b/docs/vnodes.md @@ -73,9 +73,11 @@ Property | Type | Description `text` | `(String|Number|Boolean)?` | This is used instead of `children` if a vnode contains a text node as its only child. This is done for performance reasons. Component vnodes never use the `text` property even if they have a text node as their only child. `dom` | `Element?` | Points to the element that corresponds to the vnode. This property is `undefined` in the `oninit` lifecycle method. In fragments and trusted HTML vnodes, `dom` points to the first element in the range. `domSize` | `Number?` | This is only set in fragment and trusted HTML vnodes, and it's `undefined` in all other vnode types. It defines the number of DOM elements that the vnode represents (starting from the element referenced by the `dom` property). -`state` | `Object` | An object that is persisted between redraws. In component vnodes, `state` is a shallow clone of the component object. +`state` | `Object`? | An object that is persisted between redraws. It is provided by the core engine when needed. In component vnodes, the `state` inherits prototypically from the component object/class. `events` | `Object?` | An object that is persisted between redraws and that stores event handlers so that they can be removed using the DOM API. The `events` property is `undefined` if there are no event handlers defined. This property is only used internally by Mithril, do not use it. + + --- ### Vnode types diff --git a/examples/todomvc/todomvc.js b/examples/todomvc/todomvc.js index 1f1f257a..83d2a822 100644 --- a/examples/todomvc/todomvc.js +++ b/examples/todomvc/todomvc.js @@ -38,7 +38,7 @@ var state = { update: function(title) { if (state.editing != null) { state.editing.title = title.trim() - if (state.editing.title === "") destroy(state.editing) + if (state.editing.title === "") state.destroy(state.editing) state.editing = null } }, @@ -104,7 +104,7 @@ var Todos = { m("label", {ondblclick: function() {state.dispatch("edit", [todo])}}, todo.title), m("button.destroy", {onclick: function() {state.dispatch("destroy", [todo])}}), ]), - m("input.edit", {onupdate: function(vnode) {ui.focus(vnode, todo)}, onkeypress: ui.save, onblur: ui.save}) + m("input.edit", {onupdate: function(vnode) {ui.focus(vnode, todo)}, onkeyup: ui.save, onblur: ui.save}) ]) }), ]), diff --git a/hyperscript.js b/hyperscript.js index 880a1594..16bf033a 100644 --- a/hyperscript.js +++ b/hyperscript.js @@ -1,3 +1,5 @@ +"use strict" + var hyperscript = require("./render/hyperscript") hyperscript.trust = require("./render/trust") diff --git a/mithril.d.ts b/mithril.d.ts deleted file mode 100644 index 8864d60a..00000000 --- a/mithril.d.ts +++ /dev/null @@ -1,308 +0,0 @@ -// Type definitions for mithril.js 1.0 -// Project: https://github.com/lhorie/mithril.js -// Definitions by: Mike Linkovich - -declare namespace Mithril { - - interface Lifecycle { - /** The oninit hook is called before a vnode is touched by the virtual DOM engine. */ - oninit?: (this: S, vnode: Vnode) => void; - /** The oncreate hook is called after a DOM element is created and attached to the document. */ - oncreate?: (this: S, vnode: VnodeDOM) => void; - /** The onbeforeupdate hook is called before a vnode is diffed in a update. */ - onbeforeupdate?: (this: S, vnode: Vnode, old: Vnode) => boolean; - /** The onupdate hook is called after a DOM element is updated, while attached to the document. */ - onupdate?: (this: S, vnode: VnodeDOM) => void; - /** The onbeforeremove hook is called before a DOM element is detached from the document. If a Promise is returned, Mithril only detaches the DOM element after the promise completes. */ - onbeforeremove?: (this: S, vnode: VnodeDOM) => Promise | void; - /** The onremove hook is called before a DOM element is removed from the document. */ - onremove?: (this: S, vnode: VnodeDOM) => void; - } - - interface Hyperscript { - /** Creates a virtual element (Vnode). */ - (selector: string, ...children: any[]): Vnode; - /** Creates a virtual element (Vnode). */ - (component: Component | {new(vnode: CVnode): ClassComponent} | FactoryComponent, a?: (A & Lifecycle) | Children, ...children: Children[]): Vnode; - /** Creates a fragment virtual element (Vnode). */ - fragment(attrs: any, children: Children[]): Vnode; - /** Turns an HTML string into a virtual element (Vnode). Do not use trust on unsanitized user input. */ - trust(html: string): Vnode; - } - - interface RouteResolver { - /** The onmatch hook is called when the router needs to find a component to render. */ - onmatch?: (args: any, requestedPath: string) => Mithril.Component | {new(vnode: CVnode): ClassComponent} | FactoryComponent | Promise | {new(): Component} | FactoryComponent> | void; - /** The render method is called on every redraw for a matching route. */ - render?: (vnode: Mithril.Vnode) => Children; - } - - interface RouteDefs { - [url: string]: Component | {new(vnode: CVnode): ClassComponent} | FactoryComponent | RouteResolver; - } - - interface RouteOptions { - replace?: boolean; - state?: any; - title?: string; - } - - interface Route { - /** Creates application routes and mounts Components and/or RouteResolvers to a DOM element. */ - (element: HTMLElement, defaultRoute: string, routes: RouteDefs): void; - /** Returns the last fully resolved routing path, without the prefix. */ - get(): string; - /** Redirects to a matching route or to the default route if no matching routes can be found. */ - set(route: string, data?: any, options?: RouteOptions): void; - /** Defines a router prefix which is a fragment of the URL that dictates the underlying strategy used by the router. */ - prefix(urlFragment: string): void; - /** This method is meant to be used in conjunction with an Vnode's oncreate hook. */ - link(vnode: Vnode): (e: Event) => void; - /** Returns the named parameter value from the current route. */ - param(name?: string): any; - } - - interface Mount { - /** Mounts a component to a DOM element, enabling it to autoredraw on user events. */ - (element: Element, component: Component | {new(vnode: CVnode): ClassComponent} | FactoryComponent | null): void; - } - - interface WithAttr { - /** Creates an event handler which takes the value of the specified DOM element property and calls a function with it as the argument. */ - (name: string, callback: (value: any) => void, thisArg?: any): (e: {currentTarget: any, [p: string]: any}) => boolean; - } - - interface ParseQueryString { - /** Returns an object with key/value pairs parsed from a string of the form: ?a=1&b=2 */ - (queryString: string): any; - } - - interface BuildQueryString { - /** Turns the key/value pairs of an object into a string of the form: a=1&b=2 */ - (values: {[p: string]: any}): string; - } - - interface RequestOptions { - method?: string; - data?: any; - async?: boolean; - user?: string; - password?: string; - withCredentials?: boolean; - config?: (xhr: XMLHttpRequest) => void; - headers?: any; - type?: any; - serialize?: (data: any) => string; - deserialize?: (str: string) => T; - extract?: (xhr: XMLHttpRequest, options: RequestOptions) => string; - useBody?: boolean; - background?: boolean; - } - - interface RequestOptionsAll extends RequestOptions { - url: string; - } - - interface Request { - /** Makes an XHR request and returns a promise. */ - (options: RequestOptionsAll): Promise; - /** Makes an XHR request and returns a promise. */ - (url: string, options?: RequestOptions): Promise; - } - - interface JsonpOptions { - data?: any; - type?: any; - callbackName?: string; - callbackKey?: string; - background?: boolean; - } - - interface JsonpOptionsAll extends JsonpOptions { - url: string; - } - - interface Jsonp { - /** Makes a JSON-P request and returns a promise. */ - (options: JsonpOptionsAll): Promise; - /** Makes a JSON-P request and returns a promise. */ - (url: string, options?: JsonpOptions): Promise; - } - - interface RequestService { - request: Request; - jsonp: Jsonp; - } - - interface Render { - /** Renders a vnode structure into a DOM element. */ - (el: Element, vnodes: Children): void; - } - - interface RenderService { - render: Render - } - - interface Redraw { - /** Manually triggers a redraw of mounted components. */ - (): void; - } - - interface RedrawService { - redraw: Redraw - render: Render - } - - interface Static extends Hyperscript { - route: Route; - mount: Mount; - withAttr: WithAttr; - render: Render; - redraw: Redraw; - request: Request; - jsonp: Jsonp; - parseQueryString: ParseQueryString; - buildQueryString: BuildQueryString; - version: string; - } - - // Vnode children types - type Child = Vnode | string | number | boolean | null | undefined; - interface ChildArray extends Array {} - type Children = Child | ChildArray; - - interface Vnode> { - tag: string | Component; - attrs: A; - state: S; - key?: string; - children?: Vnode[]; - events?: any; - } - - // In some lifecycle methods, Vnode will have a dom property - // and possibly a domSize property. - interface VnodeDOM extends Vnode { - dom: Element; - domSize?: number; - } - - interface CVnode extends Vnode> {} - - interface CVnodeDOM extends VnodeDOM> {} - - interface Component> extends Lifecycle { - view (this: S, vnode: Vnode): Vnode | null | void | (Vnode | null | void)[]; - } - - interface ClassComponent extends Lifecycle> { - view (this: ClassComponent, vnode: CVnode): Vnode | null | void | (Vnode | null | void)[]; - } - - // Factory component - type FactoryComponent = (vnode: Vnode) => Component - - type Unary = (input: T) => U; - - interface Functor { - map(f: Unary): Functor; - ap?(f: Functor): Functor; - } - - interface Stream { - /** Returns the value of the stream. */ - (): T; - /** Sets the value of the stream. */ - (value: T): this; - /** Creates a dependent stream whose value is set to the result of the callback function. */ - map(f: (current: T) => Stream | T | void): Stream; - /** Creates a dependent stream whose value is set to the result of the callback function. */ - map(f: (current: T) => Stream | U): Stream; - /** This method is functionally identical to stream. It exists to conform to Fantasy Land's Applicative specification. */ - of(val?: T): Stream; - /** Apply. */ - ap(f: Stream<(value: T) => U>): Stream; - /** A co-dependent stream that unregisters dependent streams when set to true. */ - end: Stream; - } - - type StreamCombiner = (...streams: any[]) => T - - interface StreamFactory { - /** Creates a stream. */ - (val?: T): Stream; - /** Creates a computed stream that reactively updates if any of its upstreams are updated. */ - combine(combiner: StreamCombiner, streams: Stream[]): Stream; - /** Creates a stream whose value is the array of values from an array of streams. */ - merge(streams: Stream[]): Stream; - /** A special value that can be returned to stream callbacks to halt execution of downstreams. */ - HALT: any; - } - - interface StreamScan { - /** Creates a new stream with the results of calling the function on every incoming stream with and accumulator and the incoming value. */ - (fn: (acc: U, value: T) => U, acc: U, stream: Stream): Stream; - } - - interface StreamScanMerge { - /** Takes an array of pairs of streams and scan functions and merges all those streams using the given functions into a single stream. */ - (pairs: [Stream, (acc: U, value: T) => U][], acc: U): Stream; - /** Takes an array of pairs of streams and scan functions and merges all those streams using the given functions into a single stream. */ - (pairs: [Stream, (acc: U, value: any) => U][], acc: U): Stream; - } -} - -declare module 'mithril' { - const m: Mithril.Static; - export = m; -} - -declare module 'mithril/hyperscript' { - const h: Mithril.Hyperscript; - export = h; -} - -declare module 'mithril/mount' { - const m: Mithril.Mount; - export = m; -} - -declare module 'mithril/route' { - const r: Mithril.Route; - export = r; -} - -declare module 'mithril/request' { - const r: Mithril.RequestService; - export = r; -} - -declare module 'mithril/render' { - const r: Mithril.RenderService; - export = r; -} - -declare module 'mithril/redraw' { - const r: Mithril.RedrawService; - export = r; -} - -declare module 'mithril/util/withAttr' { - const withAttr: Mithril.WithAttr; - export = withAttr; -} - -declare module 'mithril/stream' { - const s: Mithril.StreamFactory; - export = s; -} - -declare module 'mithril/stream/scan' { - const s: Mithril.StreamScan; - export = s; -} - -declare module 'mithril/stream/scanMerge' { - const sm: Mithril.StreamScanMerge; - export = sm; -} diff --git a/mithril.js b/mithril.js index 12f5bba3..fe9db874 100644 --- a/mithril.js +++ b/mithril.js @@ -1,7 +1,7 @@ ;(function() { - +"use strict" function Vnode(tag, key, attrs0, children, text, dom) { - return {tag: tag, key: key, attrs: attrs0, children: children, text: text, dom: dom, domSize: undefined, state: {}, events: undefined, instance: undefined, skip: false} + return {tag: tag, key: key, attrs: attrs0, children: children, text: text, dom: dom, domSize: undefined, state: undefined, events: undefined, instance: undefined, skip: false} } Vnode.normalize = function(node) { if (Array.isArray(node)) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined) @@ -389,6 +389,7 @@ var coreRenderer = function($window) { function createNode(parent, vnode, hooks, ns, nextSibling) { var tag = vnode.tag if (typeof tag === "string") { + vnode.state = {} if (vnode.attrs != null) initLifecycle(vnode.attrs, vnode, hooks) switch (tag) { case "#": return createText(parent, vnode, nextSibling) @@ -597,7 +598,10 @@ var coreRenderer = function($window) { if (!recycling && shouldNotUpdate(vnode, old)) return if (typeof oldTag === "string") { if (vnode.attrs != null) { - if (recycling) initLifecycle(vnode.attrs, vnode, hooks) + if (recycling) { + vnode.state = {} + initLifecycle(vnode.attrs, vnode, hooks) + } else updateLifecycle(vnode.attrs, vnode, hooks) } switch (oldTag) { @@ -990,11 +994,11 @@ var _11 = function($window) { var index = callbacks.indexOf(key1) if (index > -1) callbacks.splice(index, 2) } - function redraw() { - for (var i = 1; i < callbacks.length; i += 2) { - callbacks[i]() - } - } + function redraw() { + for (var i = 1; i < callbacks.length; i += 2) { + callbacks[i]() + } + } return {subscribe: subscribe, unsubscribe: unsubscribe, redraw: redraw, render: renderService.render} } var redrawService = _11(window) diff --git a/mithril.min.js b/mithril.min.js index 1443cf2a..168bea22 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,43 +1,43 @@ -(function(){function B(b,d,f,g,e,p){return{tag:b,key:d,attrs:f,children:g,text:e,dom:p,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function C(b){var d=arguments[1],f=2,g;if(null==b||"string"!==typeof b&&"function"!==typeof b&&"function"!==typeof b.view)throw Error("The selector must be either a string or a component.");if("string"===typeof b){var e;if(!(e=M[b])){g="div";for(var p=[],k={};e=P.exec(b);){var q=e[1],m=e[2];""===q&&""!==m?g=m:"#"===q?k.id=m:"."===q?p.push(m):"["===e[3][0]&& -((q=e[6])&&(q=q.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),"class"===e[4]?p.push(q):k[e[4]]=q||!0)}0a.indexOf("?")?"?":"&";a+=e+d}return a}function k(a){try{return""!==a?JSON.parse(a):null}catch(w){throw Error(a); -}}function q(a){return a.responseText}function m(a,b){if("function"===typeof a)if(Array.isArray(b))for(var d=0;dl.status||304===l.status||S.test(a.url))d(m(a.type, -h));else{var c=Error(l.responseText),n;for(n in h)c[n]=h[n];f(c)}}catch(v){f(v)}};g&&null!=a.data?l.send(a.data):l.send()});return!0===a.background?w:u(w)},jsonp:function(a,k){var u=f();a=g(a,k);var q=new d(function(d,f){var g=a.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+l++,k=b.document.createElement("script");b[g]=function(e){k.parentNode.removeChild(k);d(m(a.type,e));delete b[g]};k.onerror=function(){k.parentNode.removeChild(k);f(Error("JSONP request failed"));delete b[g]};null== -a.data&&(a.data={});a.url=e(a.url,a.data);a.data[a.callbackKey||"callback"]=g;k.src=p(a.url,a.data);b.document.documentElement.appendChild(k)});return!0===a.background?q:u(q)},setCompletionCallback:function(a){u=a}}}(window,x),O=function(b){function d(h,c,n,a,b,d,e){for(;n=v&&y>=t;){var r=c[v],z=n[t];if(r!==z||b)if(null==r)v++;else if(null==z)t++;else if(r.key===z.key){var A=null!=u&&v>=c.length-u.length||null==u&&b;v++;t++;k(h,r,z,e,m(c,v,g),A,p);b&&r.tag===z.tag&&l(h,q(r),g)}else if(r=c[w],r!==z||b)if(null==r)w--;else if(null==z)t++;else if(r.key===z.key)A= -null!=u&&w>=c.length-u.length||null==u&&b,k(h,r,z,e,m(c,w+1,g),A,p),(b||t=v&&y>=t;){r=c[w];z=n[y];if(r!==z||b)if(null==r)w--;else{if(null!=z)if(r.key===z.key)A=null!=u&&w>=c.length-u.length||null==u&&b,k(h,r,z,e,m(c,w+1,g),A,p),b&&r.tag===z.tag&&l(h,q(r),g),null!=r.dom&&(g=r.dom),w--;else{if(!G){G=c;var r=w,A={},E;for(E=0;Eb.indexOf("?")?"?":"&";b+=e+d}return b}function k(b){try{return""!==b?JSON.parse(b):null}catch(w){throw Error(b); +}}function q(b){return b.responseText}function n(b,a){if("function"===typeof b)if(Array.isArray(a))for(var d=0;dl.status||304===l.status||S.test(b.url))d(n(b.type, +h));else{var c=Error(l.responseText),m;for(m in h)c[m]=h[m];f(c)}}catch(v){f(v)}};g&&null!=b.data?l.send(b.data):l.send()});return!0===b.background?w:u(w)},jsonp:function(b,k){var u=f();b=g(b,k);var q=new d(function(d,f){var g=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+l++,k=a.document.createElement("script");a[g]=function(e){k.parentNode.removeChild(k);d(n(b.type,e));delete a[g]};k.onerror=function(){k.parentNode.removeChild(k);f(Error("JSONP request failed"));delete a[g]};null== +b.data&&(b.data={});b.url=e(b.url,b.data);b.data[b.callbackKey||"callback"]=g;k.src=p(b.url,b.data);a.document.documentElement.appendChild(k)});return!0===b.background?q:u(q)},setCompletionCallback:function(b){u=b}}}(window,x),O=function(a){function d(h,c,m,b,a,d,e){for(;m=v&&y>=t;){var r=c[v],z=m[t];if(r!==z||a)if(null==r)v++;else if(null==z)t++;else if(r.key===z.key){var A=null!=u&&v>=c.length-u.length||null==u&&a;v++;t++;k(h,r,z,e,n(c,v,g),A,p);a&&r.tag===z.tag&&l(h,q(r),g)}else if(r=c[w],r!==z||a)if(null==r)w--;else if(null==z)t++;else if(r.key===z.key)A= +null!=u&&w>=c.length-u.length||null==u&&a,k(h,r,z,e,n(c,w+1,g),A,p),(a||t=v&&y>=t;){r=c[w];z=m[y];if(r!==z||a)if(null==r)w--;else{if(null!=z)if(r.key===z.key)A=null!=u&&w>=c.length-u.length||null==u&&a,k(h,r,z,e,n(c,w+1,g),A,p),a&&r.tag===z.tag&&l(h,q(r),g),null!=r.dom&&(g=r.dom),w--;else{if(!G){G=c;var r=w,A={},E;for(E=0;E -1) events[type].splice(index, 1) @@ -241,7 +241,6 @@ module.exports = function() { } if (element.nodeName === "A") { - var href Object.defineProperty(element, "href", { get: function() {return this.attributes["href"] === undefined ? "" : "[FIXME implement]"}, set: function(value) {this.setAttribute("href", value)}, @@ -271,7 +270,9 @@ module.exports = function() { enumerable: true, }) } - + + /* eslint-disable radix */ + if (element.nodeName === "CANVAS") { Object.defineProperty(element, "width", { get: function() {return this.attributes["width"] ? Math.floor(parseInt(this.attributes["width"].nodeValue) || 0) : 300}, @@ -283,6 +284,8 @@ module.exports = function() { }) } + /* eslint-enable radix */ + function getOptions(element) { var options = [] for (var i = 0; i < element.childNodes.length; i++) { @@ -297,17 +300,18 @@ module.exports = function() { element.firstChild != null ? element.firstChild.nodeValue : "" } if (element.nodeName === "SELECT") { - var selectedValue, selectedIndex = 0 + // var selectedValue + var selectedIndex = 0 Object.defineProperty(element, "selectedIndex", { get: function() {return getOptions(this).length > 0 ? selectedIndex : -1}, set: function(value) { var options = getOptions(this) if (value >= 0 && value < options.length) { - selectedValue = getOptionValue(options[selectedIndex]) + // selectedValue = getOptionValue(options[selectedIndex]) selectedIndex = value } else { - selectedValue = "" + // selectedValue = "" selectedIndex = -1 } }, @@ -323,12 +327,12 @@ module.exports = function() { var stringValue = String(value) for (var i = 0; i < options.length; i++) { if (getOptionValue(options[i]) === stringValue) { - selectedValue = stringValue + // selectedValue = stringValue selectedIndex = i return } } - selectedValue = stringValue + // selectedValue = stringValue selectedIndex = -1 }, enumerable: true, diff --git a/test-utils/parseURL.js b/test-utils/parseURL.js index f5e76e8d..e60cc531 100644 --- a/test-utils/parseURL.js +++ b/test-utils/parseURL.js @@ -3,7 +3,7 @@ module.exports = function parseURL(url, root) { var data = {} var protocolIndex = url.indexOf("://") - var pathnameIndex = protocolIndex > - 1 ? url.indexOf("/", protocolIndex + 3) : url.indexOf("/") + var pathnameIndex = protocolIndex > -1 ? url.indexOf("/", protocolIndex + 3) : url.indexOf("/") var searchIndex = url.indexOf("?") var hashIndex = url.indexOf("#") if ((pathnameIndex > searchIndex && searchIndex > -1) || (pathnameIndex > hashIndex && hashIndex > -1)) pathnameIndex = -1 diff --git a/test-utils/pushStateMock.js b/test-utils/pushStateMock.js index 91e7a136..ebd963fd 100644 --- a/test-utils/pushStateMock.js +++ b/test-utils/pushStateMock.js @@ -4,7 +4,7 @@ var parseURL = require("../test-utils/parseURL") module.exports = function(options) { if (options == null) options = {} - + var $window = options.window || {} var protocol = options.protocol || "http:" var hostname = options.hostname || "localhost" @@ -33,7 +33,7 @@ module.exports = function(options) { } return isNew } - + function prefix(prefix, value) { if (value === "") return "" return (value.charAt(0) !== prefix ? prefix : "") + value diff --git a/test-utils/tests/test-browserMock.js b/test-utils/tests/test-browserMock.js index d47c58ce..861f1ef0 100644 --- a/test-utils/tests/test-browserMock.js +++ b/test-utils/tests/test-browserMock.js @@ -17,7 +17,7 @@ o.spec("browserMock", function() { }) o("$window.onhashchange can be reached from the pushStateMock functions", function(done) { $window.onhashchange = o.spy() - $window.location.hash = '#a' + $window.location.hash = "#a" callAsync(function(){ o($window.onhashchange.callCount).equals(1) @@ -33,7 +33,7 @@ o.spec("browserMock", function() { }) o("$window.onunload can be reached from the pushStateMock functions", function() { $window.onunload = o.spy() - $window.location.href = '/a' + $window.location.href = "/a" o($window.onunload.callCount).equals(1) }) diff --git a/test-utils/tests/test-components.js b/test-utils/tests/test-components.js index cc9a091b..e0ede703 100644 --- a/test-utils/tests/test-components.js +++ b/test-utils/tests/test-components.js @@ -4,51 +4,51 @@ var o = require("../../ospec/ospec") var components = require("../../test-utils/components") o.spec("test-utils/components", function() { - var test = o.spy(function(component) { - return function() { - o('works', function() { - o(typeof component.kind).equals('string') + var test = o.spy(function(component) { + return function() { + o("works", function() { + o(typeof component.kind).equals("string") - var methods = {oninit: function(){}, view: function(){}} + var methods = {oninit: function(){}, view: function(){}} - var cmp1, cmp2 + var cmp1, cmp2 - if (component.kind === "POJO") { - cmp1 = component.create() - cmp2 = component.create(methods) - } else if (component.kind === "constructible") { - cmp1 = new (component.create()) - cmp2 = new (component.create(methods)) - } else if (component.kind === "closure") { - cmp1 = component.create()() - cmp2 = component.create(methods)() - } else { - throw new Error("unexpected component kind") - } + if (component.kind === "POJO") { + cmp1 = component.create() + cmp2 = component.create(methods) + } else if (component.kind === "constructible") { + cmp1 = new (component.create()) + cmp2 = new (component.create(methods)) + } else if (component.kind === "closure") { + cmp1 = component.create()() + cmp2 = component.create(methods)() + } else { + throw new Error("unexpected component kind") + } - o(cmp1 != null).equals(true) - o(typeof cmp1.view).equals("function") + o(cmp1 != null).equals(true) + o(typeof cmp1.view).equals("function") - var vnode = cmp1.view() + var vnode = cmp1.view() - o(vnode != null).equals(true) - o(vnode).deepEquals({tag: "div"}) + o(vnode != null).equals(true) + o(vnode).deepEquals({tag: "div"}) - if (component.kind !== 'constructible') { - o(cmp2).deepEquals(methods) - } else { + if (component.kind !== "constructible") { + o(cmp2).deepEquals(methods) + } else { // deepEquals doesn't search the prototype, do it manually - o(cmp2 != null).equals(true) - o(cmp2.view).equals(methods.view) - o(cmp2.oninit).equals(methods.oninit) - } - }) - } - }) - o.after(function(){ - o(test.callCount).equals(3) - }) - components.forEach(function(component) { - o.spec(component.kind, test(component)) - }) + o(cmp2 != null).equals(true) + o(cmp2.view).equals(methods.view) + o(cmp2.oninit).equals(methods.oninit) + } + }) + } + }) + o.after(function(){ + o(test.callCount).equals(3) + }) + components.forEach(function(component) { + o.spec(component.kind, test(component)) + }) }) diff --git a/test-utils/tests/test-domMock.js b/test-utils/tests/test-domMock.js index edd896d5..aee68832 100644 --- a/test-utils/tests/test-domMock.js +++ b/test-utils/tests/test-domMock.js @@ -321,7 +321,7 @@ o.spec("domMock", function() { o(div.getAttribute("id")).equals("aaa") }) }) - + o.spec("setAttribute", function() { o("works", function() { var div = $document.createElement("div") @@ -393,7 +393,6 @@ o.spec("domMock", function() { o.spec("textContent", function() { o("works", function() { var div = $document.createElement("div") - var a = $document.createElement("a") div.textContent = "aaa" o(div.childNodes.length).equals(1) @@ -402,7 +401,6 @@ o.spec("domMock", function() { }) o("works with empty string", function() { var div = $document.createElement("div") - var a = $document.createElement("a") div.textContent = "" o(div.childNodes.length).equals(0) @@ -514,8 +512,8 @@ o.spec("domMock", function() { var div = $document.createElement("div") div.style.cssText = "background: url(';'); font-family: \";\"" - o(div.style.background).equals("url(';')") - o(div.style.fontFamily).equals("\";\"") + o(div.style.background).equals("url(';')") + o(div.style.fontFamily).equals('";"') o(div.style.cssText).equals("background: url(';'); font-family: \";\";") }) o("comments in style.cssText are stripped", function(){ @@ -534,9 +532,10 @@ o.spec("domMock", function() { }) o("setting style throws", function () { + var div = $document.createElement("div") var err = false try { - div.style = '' + div.style = "" } catch (e) { err = e } @@ -919,55 +918,55 @@ o.spec("domMock", function() { o.spec("canvas width and height", function() { o("setting property works", function() { var canvas = $document.createElement("canvas") - + canvas.width = 100 o(canvas.attributes["width"].nodeValue).equals("100") o(canvas.width).equals(100) - + canvas.height = 100 o(canvas.attributes["height"].nodeValue).equals("100") o(canvas.height).equals(100) }) o("setting string casts to number", function() { var canvas = $document.createElement("canvas") - + canvas.width = "100" o(canvas.attributes["width"].nodeValue).equals("100") o(canvas.width).equals(100) - + canvas.height = "100" o(canvas.attributes["height"].nodeValue).equals("100") o(canvas.height).equals(100) }) o("setting float casts to int", function() { var canvas = $document.createElement("canvas") - + canvas.width = 1.2 o(canvas.attributes["width"].nodeValue).equals("1") o(canvas.width).equals(1) - + canvas.height = 1.2 o(canvas.attributes["height"].nodeValue).equals("1") o(canvas.height).equals(1) }) o("setting percentage fails", function() { var canvas = $document.createElement("canvas") - + canvas.width = "100%" o(canvas.attributes["width"].nodeValue).equals("0") o(canvas.width).equals(0) - + canvas.height = "100%" o(canvas.attributes["height"].nodeValue).equals("0") o(canvas.height).equals(0) }) o("setting attribute works", function() { var canvas = $document.createElement("canvas") - + canvas.setAttribute("width", "100%") o(canvas.attributes["width"].nodeValue).equals("100%") o(canvas.width).equals(100) - + canvas.setAttribute("height", "100%") o(canvas.attributes["height"].nodeValue).equals("100%") o(canvas.height).equals(100) diff --git a/test-utils/tests/test-pushStateMock.js b/test-utils/tests/test-pushStateMock.js index 3cb51716..41efacab 100644 --- a/test-utils/tests/test-pushStateMock.js +++ b/test-utils/tests/test-pushStateMock.js @@ -168,13 +168,13 @@ o.spec("pushStateMock", function() { }) o.spec("set protocol", function() { o("setting protocol throws", function(done) { - var old = $window.location.href try { $window.location.protocol = "https://" } catch (e) { - done() + return done() } + throw new Error("Expected an error") }) }) o.spec("set port", function() { @@ -413,17 +413,17 @@ o.spec("pushStateMock", function() { }) o("replaceState does not break forward history", function() { $window.onpopstate = o.spy() - + $window.history.pushState(null, null, "b") $window.history.back() o($window.onpopstate.callCount).equals(1) o($window.location.href).equals("http://localhost/") - + $window.history.replaceState(null, null, "a") - + o($window.location.href).equals("http://localhost/a") - + $window.history.forward() o($window.onpopstate.callCount).equals(2) @@ -431,46 +431,46 @@ o.spec("pushStateMock", function() { }) o("pushstate retains state", function() { $window.onpopstate = o.spy() - + $window.history.pushState({a: 1}, null, "#a") $window.history.pushState({b: 2}, null, "#b") - + o($window.onpopstate.callCount).equals(0) $window.history.back() - + o($window.onpopstate.callCount).equals(1) o($window.onpopstate.args[0].type).equals("popstate") o($window.onpopstate.args[0].state).deepEquals({a: 1}) $window.history.back() - + o($window.onpopstate.callCount).equals(2) o($window.onpopstate.args[0].type).equals("popstate") o($window.onpopstate.args[0].state).equals(null) $window.history.forward() - + o($window.onpopstate.callCount).equals(3) o($window.onpopstate.args[0].type).equals("popstate") o($window.onpopstate.args[0].state).deepEquals({a: 1}) $window.history.forward() - + o($window.onpopstate.callCount).equals(4) o($window.onpopstate.args[0].type).equals("popstate") o($window.onpopstate.args[0].state).deepEquals({b: 2}) }) o("replacestate replaces state", function() { $window.onpopstate = o.spy(pop) - + $window.history.replaceState({a: 1}, null, "a") - + o($window.history.state).deepEquals({a: 1}) - + $window.history.pushState(null, null, "a") $window.history.back() - + function pop(e) { o(e.state).deepEquals({a: 1}) o($window.history.state).deepEquals({a: 1}) diff --git a/test-utils/tests/test-xhrMock.js b/test-utils/tests/test-xhrMock.js index cef2d9ca..8bdfcf21 100644 --- a/test-utils/tests/test-xhrMock.js +++ b/test-utils/tests/test-xhrMock.js @@ -5,13 +5,13 @@ var xhrMock = require("../../test-utils/xhrMock") var parseQueryString = require("../../querystring/parse") o.spec("xhrMock", function() { - var $window, ajax + var $window o.beforeEach(function() { $window = xhrMock() }) o.spec("xhr", function() { - o("works", function(done, timeout) { + o("works", function(done) { $window.$defineRoutes({ "GET /item": function(request) { o(request.url).equals("/item") @@ -29,7 +29,7 @@ o.spec("xhrMock", function() { } xhr.send() }) - o("works w/ search", function(done, timeout) { + o("works w/ search", function(done) { $window.$defineRoutes({ "GET /item": function(request) { o(request.query).equals("?a=b") @@ -45,7 +45,7 @@ o.spec("xhrMock", function() { } xhr.send() }) - o("works w/ body", function(done, timeout) { + o("works w/ body", function(done) { $window.$defineRoutes({ "POST /item": function(request) { o(request.body).equals("a=b") @@ -61,7 +61,7 @@ o.spec("xhrMock", function() { } xhr.send("a=b") }) - o("handles routing error", function(done, timeout) { + o("handles routing error", function(done) { var xhr = new $window.XMLHttpRequest() xhr.open("GET", "/nonexistent") xhr.onreadystatechange = function() { @@ -113,7 +113,7 @@ o.spec("xhrMock", function() { done() } }) - o("works with other querystring params", function(done, timeout) { + o("works with other querystring params", function(done) { $window.$defineRoutes({ "GET /test": function(request) { var queryData = parseQueryString(request.query) diff --git a/test-utils/xhrMock.js b/test-utils/xhrMock.js index 57c2887f..d3bbf5b8 100644 --- a/test-utils/xhrMock.js +++ b/test-utils/xhrMock.js @@ -6,7 +6,7 @@ var parseQueryString = require("../querystring/parse") module.exports = function() { var routes = {} - var callback = "callback" + // var callback = "callback" var serverErrorHandler = function(url) { return {status: 500, responseText: "server error, most likely the URL was not defined " + url} } @@ -43,7 +43,6 @@ module.exports = function() { } self.readyState = 4 if (args.async === true) { - var s = new Date callAsync(function() { if (typeof self.onreadystatechange === "function") self.onreadystatechange() }) @@ -64,7 +63,7 @@ module.exports = function() { var urlData = parseURL(element.src, {protocol: "http:", hostname: "localhost", port: "", pathname: "/"}) var handler = routes["GET " + urlData.pathname] || serverErrorHandler.bind(null, element.src) var data = handler({url: urlData.pathname, query: urlData.search, body: null}) - var query = parseQueryString(urlData.search) + parseQueryString(urlData.search) callAsync(function() { if (data.status === 200) { new Function("$window", "with ($window) return " + data.responseText).call($window, $window) @@ -83,8 +82,8 @@ module.exports = function() { $defineRoutes: function(rules) { routes = rules }, - $defineJSONPCallbackKey: function(key) { - callback = key + $defineJSONPCallbackKey: function(/* key */) { + // callback = key }, } return $window diff --git a/tests/test-api.js b/tests/test-api.js index ec57a0f3..3240141c 100644 --- a/tests/test-api.js +++ b/tests/test-api.js @@ -10,7 +10,7 @@ o.spec("api", function() { o.beforeEach(function() { var mock = browserMock() if (typeof global !== "undefined") global.window = mock - m = require("../mithril") + m = require("../mithril") // eslint-disable-line global-require }) o.spec("m", function() { @@ -174,4 +174,4 @@ o.spec("api", function() { }) }) }) -}) \ No newline at end of file +})