Skip to content

Commit

Permalink
using eslint with strictly es5 config
Browse files Browse the repository at this point in the history
  • Loading branch information
refractalize committed Apr 20, 2017
1 parent 392822e commit cf57efe
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
6 changes: 6 additions & 0 deletions .eslintrc
@@ -0,0 +1,6 @@
{
"extends": [
"standard",
"plugin:es5/no-es2015"
]
}
3 changes: 0 additions & 3 deletions .vimrc

This file was deleted.

10 changes: 8 additions & 2 deletions package.json
Expand Up @@ -16,6 +16,13 @@
"detect-browser": "1.6.2",
"electron": "1.6.2",
"electron-mocha": "3.4.0",
"eslint": "3.19.0",
"eslint-config-standard": "10.2.1",
"eslint-plugin-es5": "1.0.1",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-node": "4.2.2",
"eslint-plugin-promise": "3.5.0",
"eslint-plugin-standard": "3.0.1",
"hyperx": "2.3.0",
"jquery": "2.1.3",
"jquery-sendkeys": "4.0.0",
Expand All @@ -34,15 +41,14 @@
"lie": "3.1.1",
"lowscore": "1.12.1",
"mocha": "3.2.0",
"standard": "10.0.1",
"trytryagain": "1.2.0",
"uglify-js": "2.4.16",
"vdom-to-html": "2.3.1",
"watchify": "3.9.0",
"webpack": "2.3.3"
},
"scripts": {
"test": "npm run karma && npm run mocha && standard",
"test": "npm run karma && npm run mocha && eslint .",
"test-all": "BROWSERS=all npm test",
"karma": "karma start --single-run",
"mocha": "mocha test/server/*Spec.js",
Expand Down
15 changes: 9 additions & 6 deletions serverRender.js
Expand Up @@ -15,14 +15,17 @@ module.exports.render = function (app, url) {
var cache = new StoreCache()
var mount = new Mount(app, {window: {},
router: router.create({history: new ServerHistory(url)}),
requestRender: () => {
requestRender: function () {
renderRequested = true
}})

mount.serverRenderCache = cache
mount.refreshify = cache.refreshify

function renderUntilAllLoaded (mount, cache, {maxRenders, renders = 0} = {}) {
function renderUntilAllLoaded (mount, cache, options) {
var maxRenders = typeof options === 'object' && options.hasOwnProperty('maxRenders') ? options.maxRenders : undefined
var renders = typeof options === 'object' && options.hasOwnProperty('renders') ? options.renders : 0

if (renders >= maxRenders) {
throw new Error('page could not load all resources')
}
Expand All @@ -32,17 +35,17 @@ module.exports.render = function (app, url) {

renderRequested = false

runRender(mount, () => {
runRender(mount, function () {
vdom = toVdom(mount.render())
html = vdomToHtml(vdom)
})

if (cache.loadPromises.length) {
return cache.loaded().then(() => {
return renderUntilAllLoaded(mount, cache, {maxRenders, renders: renders + 1})
return cache.loaded().then(function () {
return renderUntilAllLoaded(mount, cache, {maxRenders: maxRenders, renders: renders + 1})
})
} else if (renderRequested) {
return renderUntilAllLoaded(mount, cache, {maxRenders, renders: renders + 1})
return renderUntilAllLoaded(mount, cache, {maxRenders: maxRenders, renders: renders + 1})
} else {
return Promise.resolve({
vdom: vdom,
Expand Down
13 changes: 7 additions & 6 deletions storeCache.js
Expand Up @@ -22,9 +22,9 @@ StoreCache.prototype.cache = function (key, loadFn) {
return (self.data[key] = data)
})

return modifyPromiseChain(loadPromise, p => {
if (!this.waitingForLoad) {
this.loadPromises.push(p)
return modifyPromiseChain(loadPromise, function (p) {
if (!self.waitingForLoad) {
self.loadPromises.push(p)
}
})
}
Expand All @@ -51,9 +51,10 @@ function modifyPromiseChain (promise, modify) {
}

StoreCache.prototype.loaded = function () {
var self = this
this.waitingForLoad = true
return Promise.all(this.loadPromises).then(() => {
this.waitingForLoad = false
this.loadPromises = []
return Promise.all(this.loadPromises).then(function () {
self.waitingForLoad = false
self.loadPromises = []
})
}
2 changes: 1 addition & 1 deletion test/server/hyperxSpec.js
Expand Up @@ -6,6 +6,6 @@ var expect = require('chai').expect

describe('hyperx', function () {
it('can render with hyperx', function () {
expect(toHtml(hx`<div>hi</div>`)).to.equal('<div>hi</div>')
expect(toHtml(hx`<div>hi</div>`)).to.equal('<div>hi</div>') // eslint-disable-line es5/no-template-literals
})
})
14 changes: 7 additions & 7 deletions test/server/storeCacheSpec.js
Expand Up @@ -27,11 +27,11 @@ describe('store cache', function () {
})

function load (data) {
return wait(10).then(() => data)
return wait(10).then(function () { return data })
}

function wait (n) {
return new Promise((resolve) => {
return new Promise(function (resolve) {
setTimeout(resolve, 10)
})
}
Expand All @@ -41,15 +41,15 @@ describe('store cache', function () {
var setData2

refreshify(function () {
return serverRenderCache('key', () => load('some data')).then(data => {
return serverRenderCache('key', function () { return load('some data') }).then(function (data) {
expect(data).to.equal('some data')
return (setData1 = data)
}).then(data => {
}).then(function (data) {
return (setData2 = data)
})
})()

return storeCache.loaded().then(() => {
return storeCache.loaded().then(function () {
expect(storeCache.data).to.eql({
key: 'some data'
})
Expand All @@ -62,13 +62,13 @@ describe('store cache', function () {
var setData

refreshify(function () {
serverRenderCache('key', () => load('some data')).then(data => {
serverRenderCache('key', function () { return load('some data') }).then(function (data) {
expect(data).to.equal('some data')
setData = data
})
})()

return storeCache.loaded().then(() => {
return storeCache.loaded().then(function () {
expect(storeCache.data).to.eql({key: 'some data'})
expect(setData).to.equal('some data')
})
Expand Down
4 changes: 2 additions & 2 deletions test/server/toHtmlSpec.js
Expand Up @@ -43,7 +43,7 @@ describe('to html', function () {

it('can render view components to HTML', function () {
var vdom = h('div',
hyperdom.component({
hyperdom.viewComponent({
render: function () {
return h('div', 'component')
}
Expand All @@ -55,7 +55,7 @@ describe('to html', function () {
})

it('can render top-level view components to HTML', function () {
var vdom = hyperdom.component({
var vdom = hyperdom.viewComponent({
render: function () {
return h('div', 'component')
}
Expand Down

0 comments on commit cf57efe

Please sign in to comment.