Add editorconfig, resolve differences

This includes newlines, tabs, among other things.
This commit is contained in:
impinball 2016-06-18 02:59:42 -04:00
parent 80d0a69dab
commit b4fb21475c
90 changed files with 1707 additions and 1701 deletions

View file

@ -9,11 +9,11 @@ module.exports = function(root, renderer, pubsub, callback) {
if (e.redraw !== false) run()
})
}
if (pubsub != null) {
if (root.redraw) pubsub.unsubscribe(root.redraw)
pubsub.subscribe(run)
}
return root.redraw = run
}
}

View file

@ -8,7 +8,7 @@ module.exports = function(renderer, pubsub) {
var run = autoredraw(root, renderer, pubsub, function() {
renderer.render(root, {tag: component})
})
run()
}
}

View file

@ -18,6 +18,6 @@ module.exports = function($window, renderer, pubsub) {
route.prefix = router.setPrefix
route.setPath = router.setPath
route.getPath = router.getPath
return route
}

View file

@ -24,13 +24,13 @@
<script src="../../api/autoredraw.js"></script>
<script src="../../api/mount.js"></script>
<script src="../../api/router.js"></script>
<script src="./test-throttle.js"></script>
<script src="./test-pubsub.js"></script>
<script src="./test-autoredraw.js"></script>
<script src="./test-mount.js"></script>
<script src="./test-router.js"></script>
<script>require("../../ospec/ospec").run()</script>
</body>
</html>

View file

@ -17,79 +17,79 @@ o.spec("autoredraw", function() {
pubsub = apiPubSub()
spy = o.spy()
})
o("returns self-trigger", function() {
var run = autoredraw(root, renderer, pubsub, spy)
run()
o(spy.callCount).equals(1)
})
o("null renderer doesn't throw", function(done) {
autoredraw(root, null, pubsub, spy)
done()
})
o("null pubsub doesn't throw", function(done) {
autoredraw(root, renderer, null, spy)
done()
})
o("registers onevent", function() {
autoredraw(root, renderer, pubsub, spy)
renderer.render(root, {tag: "div", attrs: {onclick: function() {}}})
var e = $window.document.createEvent("MouseEvents")
e.initEvent("click", true, true)
root.firstChild.dispatchEvent(e)
o(spy.callCount).equals(1)
})
o("registers pubsub", function() {
autoredraw(root, renderer, pubsub, spy)
pubsub.publish()
o(spy.callCount).equals(1)
})
o("re-registering pubsub works", function() {
autoredraw(root, renderer, pubsub, spy)
autoredraw(root, renderer, pubsub, spy)
pubsub.publish()
o(spy.callCount).equals(1)
})
o("throttles", function(done) {
var run = autoredraw(root, renderer, pubsub, spy)
run()
run()
o(spy.callCount).equals(1)
setTimeout(function() {
o(spy.callCount).equals(2)
done()
}, FRAME_BUDGET)
})
o("does not redraw if e.redraw is false", function() {
autoredraw(root, renderer, pubsub, spy)
renderer.render(root, {tag: "div", attrs: {onclick: function(e) {e.redraw = false}}})
var e = $window.document.createEvent("MouseEvents")
e.initEvent("click", true, true)
root.firstChild.dispatchEvent(e)
o(spy.callCount).equals(0)
})
})
})

View file

@ -11,34 +11,34 @@ var apiMounter = require("../../api/mount")
o.spec("mount", function() {
var FRAME_BUDGET = Math.floor(1000 / 60)
var $window, root, redraw, mount
o.beforeEach(function() {
$window = domMock()
root = $window.document.body
redraw = apiPubSub()
mount = apiMounter(coreRenderer($window), redraw)
})
o("renders into `root`", function() {
mount(root, {
view : function() {
return m("div")
}
})
o(root.firstChild.nodeName).equals("DIV")
})
o("redraws on events", 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)
mount(root, {
view : function() {
return m("div", {
@ -48,32 +48,32 @@ o.spec("mount", function() {
})
}
})
root.firstChild.dispatchEvent(e)
o(oninit.callCount).equals(1)
o(onupdate.callCount).equals(0)
o(onclick.callCount).equals(1)
o(onclick.this).equals(root.firstChild)
o(onclick.args[0].type).equals("click")
o(onclick.args[0].target).equals(root.firstChild)
// Wrapped to give time for the rate-limited redraw to fire
setTimeout(function() {
o(onupdate.callCount).equals(1)
done()
}, FRAME_BUDGET)
})
o("event handlers can skip redraw", function(done) {
var onupdate = o.spy()
var oninit = o.spy()
var e = $window.document.createEvent("MouseEvents")
e.initEvent("click", true, true)
mount(root, {
view: function() {
return m("div", {
@ -85,23 +85,23 @@ o.spec("mount", function() {
})
}
})
root.firstChild.dispatchEvent(e)
o(oninit.callCount).equals(1)
// Wrapped to ensure no redraw fired
setTimeout(function() {
o(onupdate.callCount).equals(0)
done()
}, FRAME_BUDGET)
})
o("redraws when the render function is run", function(done) {
var onupdate = o.spy()
var oninit = o.spy()
mount(root, {
view : function() {
return m("div", {
@ -110,16 +110,16 @@ o.spec("mount", function() {
})
}
})
o(oninit.callCount).equals(1)
o(onupdate.callCount).equals(0)
redraw.publish()
// Wrapped to give time for the rate-limited redraw to fire
setTimeout(function() {
o(onupdate.callCount).equals(1)
done()
}, FRAME_BUDGET)
})

View file

@ -8,68 +8,68 @@ o.spec("pubsub", function() {
o.beforeEach(function() {
pubsub = apiPubSub()
})
o("shouldn't error if there are no renderers", function() {
pubsub.publish()
})
o("should run a single renderer entry", function() {
var spy = o.spy()
pubsub.subscribe(spy)
pubsub.publish()
o(spy.callCount).equals(1)
pubsub.publish()
pubsub.publish()
pubsub.publish()
o(spy.callCount).equals(4)
})
o("should run all renderer entries", function() {
var spy1 = o.spy()
var spy2 = o.spy()
var spy3 = o.spy()
pubsub.subscribe(spy1)
pubsub.subscribe(spy2)
pubsub.subscribe(spy3)
pubsub.publish()
o(spy1.callCount).equals(1)
o(spy2.callCount).equals(1)
o(spy3.callCount).equals(1)
pubsub.publish()
o(spy1.callCount).equals(2)
o(spy2.callCount).equals(2)
o(spy3.callCount).equals(2)
})
o("should stop running after unsubscribe", function() {
var spy = o.spy()
pubsub.subscribe(spy)
pubsub.unsubscribe(spy)
pubsub.publish()
o(spy.callCount).equals(0)
})
o("does nothing on invalid unsubscribe", function() {
var spy = o.spy()
pubsub.subscribe(spy)
pubsub.unsubscribe(null)
pubsub.publish()
o(spy.callCount).equals(1)
})
})

View file

@ -1,170 +1,170 @@
"use strict"
var o = require("../../ospec/ospec")
var pushStateMock = require("../../test-utils/pushStateMock")
var domMock = require("../../test-utils/domMock")
var m = require("../../render/hyperscript")
var coreRenderer = require("../../render/render")
var apiPubSub = require("../../api/pubsub")
var apiRouter = require("../../api/router")
o.spec("route", function() {
var FRAME_BUDGET = Math.floor(1000 / 60)
var $window, root, redraw, route
o.beforeEach(function() {
$window = {}
var dom = domMock()
for (var key in dom) $window[key] = dom[key]
var loc = pushStateMock()
for (var key in loc) $window[key] = loc[key]
root = $window.document.body
redraw = apiPubSub()
route = apiRouter($window, coreRenderer($window), redraw)
})
o("renders into `root`", function() {
route(root, "/", {
"/" : {
view: function() {
return m("div")
}
}
})
o(root.firstChild.nodeName).equals("DIV")
})
o("redraws when render function is executed", function(done) {
var onupdate = o.spy()
var oninit = o.spy()
route(root, "/", {
"/" : {
view: function() {
return m("div", {
oninit: oninit,
onupdate: onupdate
})
}
}
})
o(oninit.callCount).equals(1)
redraw.publish()
// Wrapped to give time for the rate-limited redraw to fire
setTimeout(function() {
o(onupdate.callCount).equals(1)
done()
}, FRAME_BUDGET)
})
o("redraws on events", function(done, timeout) {
var onupdate = o.spy()
var oninit = o.spy()
var onclick = o.spy()
var e = $window.document.createEvent("MouseEvents")
e.initEvent("click", true, true)
route(root, "/", {
"/" : {
view: function() {
return m("div", {
oninit: oninit,
onupdate: onupdate,
onclick: onclick,
})
}
}
})
root.firstChild.dispatchEvent(e)
o(oninit.callCount).equals(1)
o(onclick.callCount).equals(1)
o(onclick.this).equals(root.firstChild)
o(onclick.args[0].type).equals("click")
o(onclick.args[0].target).equals(root.firstChild)
// Wrapped to give time for the rate-limited redraw to fire
setTimeout(function() {
o(onupdate.callCount).equals(1)
done()
}, FRAME_BUDGET)
})
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)
route(root, "/", {
"/" : {
view: function() {
return m("div", {
oninit: oninit,
onupdate: onupdate,
onclick: function(e) {
e.redraw = false
},
})
}
}
})
root.firstChild.dispatchEvent(e)
o(oninit.callCount).equals(1)
// Wrapped to ensure no redraw fired
setTimeout(function() {
o(onupdate.callCount).equals(0)
done()
}, FRAME_BUDGET)
})
o("changes location on route.link", function() {
var e = $window.document.createEvent("MouseEvents")
e.initEvent("click", true, true)
route.prefix("?")
route(root, "/", {
"/" : {
view: function() {
return m("a", {
href: "/test",
oncreate: route.link
})
}
},
"/test" : {
view : function() {
return m("div")
}
}
})
o($window.location.href).equals("http://localhost/?/")
root.firstChild.dispatchEvent(e)
o($window.location.href).equals("http://localhost/?/test")
})
})
"use strict"
var o = require("../../ospec/ospec")
var pushStateMock = require("../../test-utils/pushStateMock")
var domMock = require("../../test-utils/domMock")
var m = require("../../render/hyperscript")
var coreRenderer = require("../../render/render")
var apiPubSub = require("../../api/pubsub")
var apiRouter = require("../../api/router")
o.spec("route", function() {
var FRAME_BUDGET = Math.floor(1000 / 60)
var $window, root, redraw, route
o.beforeEach(function() {
$window = {}
var dom = domMock()
for (var key in dom) $window[key] = dom[key]
var loc = pushStateMock()
for (var key in loc) $window[key] = loc[key]
root = $window.document.body
redraw = apiPubSub()
route = apiRouter($window, coreRenderer($window), redraw)
})
o("renders into `root`", function() {
route(root, "/", {
"/" : {
view: function() {
return m("div")
}
}
})
o(root.firstChild.nodeName).equals("DIV")
})
o("redraws when render function is executed", function(done) {
var onupdate = o.spy()
var oninit = o.spy()
route(root, "/", {
"/" : {
view: function() {
return m("div", {
oninit: oninit,
onupdate: onupdate
})
}
}
})
o(oninit.callCount).equals(1)
redraw.publish()
// Wrapped to give time for the rate-limited redraw to fire
setTimeout(function() {
o(onupdate.callCount).equals(1)
done()
}, FRAME_BUDGET)
})
o("redraws on events", function(done, timeout) {
var onupdate = o.spy()
var oninit = o.spy()
var onclick = o.spy()
var e = $window.document.createEvent("MouseEvents")
e.initEvent("click", true, true)
route(root, "/", {
"/" : {
view: function() {
return m("div", {
oninit: oninit,
onupdate: onupdate,
onclick: onclick,
})
}
}
})
root.firstChild.dispatchEvent(e)
o(oninit.callCount).equals(1)
o(onclick.callCount).equals(1)
o(onclick.this).equals(root.firstChild)
o(onclick.args[0].type).equals("click")
o(onclick.args[0].target).equals(root.firstChild)
// Wrapped to give time for the rate-limited redraw to fire
setTimeout(function() {
o(onupdate.callCount).equals(1)
done()
}, FRAME_BUDGET)
})
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)
route(root, "/", {
"/" : {
view: function() {
return m("div", {
oninit: oninit,
onupdate: onupdate,
onclick: function(e) {
e.redraw = false
},
})
}
}
})
root.firstChild.dispatchEvent(e)
o(oninit.callCount).equals(1)
// Wrapped to ensure no redraw fired
setTimeout(function() {
o(onupdate.callCount).equals(0)
done()
}, FRAME_BUDGET)
})
o("changes location on route.link", function() {
var e = $window.document.createEvent("MouseEvents")
e.initEvent("click", true, true)
route.prefix("?")
route(root, "/", {
"/" : {
view: function() {
return m("a", {
href: "/test",
oncreate: route.link
})
}
},
"/test" : {
view : function() {
return m("div")
}
}
})
o($window.location.href).equals("http://localhost/?/")
root.firstChild.dispatchEvent(e)
o($window.location.href).equals("http://localhost/?/test")
})
})

View file

@ -11,74 +11,74 @@ o.spec("throttle", function() {
spy = o.spy()
throttled = throttle(spy)
})
o("runs first call synchronously", function() {
throttled()
o(spy.callCount).equals(1)
})
o("throttles subsequent synchronous calls", function(done) {
throttled()
throttled()
o(spy.callCount).equals(1)
setTimeout(function() {
o(spy.callCount).equals(2)
done()
}, FRAME_BUDGET) //this delay is much higher than 16.6ms due to setTimeout clamp and other runtime costs
})
o("calls after threshold", function(done) {
throttled()
o(spy.callCount).equals(1)
setTimeout(function(t) {
throttled()
o(spy.callCount).equals(2)
done()
}, FRAME_BUDGET)
})
o("throttles before threshold", function(done) {
throttled()
o(spy.callCount).equals(1)
callAsync(function(t) {
throttled()
o(spy.callCount).equals(1)
done()
})
})
o("it only runs once per tick", function(done) {
throttled()
throttled()
throttled()
o(spy.callCount).equals(1)
setTimeout(function() {
o(spy.callCount).equals(2)
done()
}, FRAME_BUDGET)
})
o("it supports forcing a synchronous redraw", function() {
throttled()
throttled()
throttled(true)
o(spy.callCount).equals(2)
})
})