chore: format all code (#2632)

This commit is contained in:
Julien Fontanet
2018-02-09 17:56:03 +01:00
committed by GitHub
parent 8bf35b2a63
commit 7cb720b11f
170 changed files with 5802 additions and 4801 deletions
+12 -14
View File
@@ -1,17 +1,14 @@
import kindOf from 'kindof'
import {BaseError} from 'make-error'
import {EventEmitter} from 'events'
import {forEach} from 'lodash'
import { BaseError } from 'make-error'
import { EventEmitter } from 'events'
import { forEach } from 'lodash'
import isEmpty from './is-empty'
import isObject from './is-object'
// ===================================================================
const {
create: createObject,
prototype: { hasOwnProperty },
} = Object
const { create: createObject, prototype: { hasOwnProperty } } = Object
export const ACTION_ADD = 'add'
export const ACTION_UPDATE = 'update'
@@ -189,7 +186,7 @@ export default class Collection extends EventEmitter {
// -----------------------------------------------------------------
createIndex (name, index) {
const {_indexes: indexes} = this
const { _indexes: indexes } = this
if (hasOwnProperty.call(indexes, name)) {
throw new DuplicateIndex(name)
}
@@ -201,7 +198,7 @@ export default class Collection extends EventEmitter {
}
deleteIndex (name) {
const {_indexes: indexes} = this
const { _indexes: indexes } = this
if (!hasOwnProperty.call(indexes, name)) {
throw new NoSuchIndex(name)
}
@@ -218,7 +215,7 @@ export default class Collection extends EventEmitter {
// -----------------------------------------------------------------
* [Symbol.iterator] () {
const {_items: items} = this
const { _items: items } = this
for (const key in items) {
yield [key, items[key]]
@@ -226,7 +223,7 @@ export default class Collection extends EventEmitter {
}
* keys () {
const {_items: items} = this
const { _items: items } = this
for (const key in items) {
yield key
@@ -234,7 +231,7 @@ export default class Collection extends EventEmitter {
}
* values () {
const {_items: items} = this
const { _items: items } = this
for (const key in items) {
yield items[key]
@@ -259,7 +256,7 @@ export default class Collection extends EventEmitter {
return
}
const {_buffer: buffer} = this
const { _buffer: buffer } = this
// Due to deduplication there could be nothing in the buffer.
if (isEmpty(buffer)) {
@@ -354,7 +351,8 @@ export default class Collection extends EventEmitter {
} else {
this._buffer[key] = ACTION_REMOVE
}
} else { // update
} else {
// update
if (!this._buffer[key]) {
this._buffer[key] = ACTION_UPDATE
}
+65 -80
View File
@@ -3,15 +3,15 @@
import eventToPromise from 'event-to-promise'
import { forEach } from 'lodash'
import Collection, {DuplicateItem, NoSuchItem} from './collection'
import Collection, { DuplicateItem, NoSuchItem } from './collection'
// ===================================================================
function waitTicks (n = 2) {
const {nextTick} = process
const { nextTick } = process
return new Promise(function (resolve) {
(function waitNextTick () {
;(function waitNextTick () {
// The first tick is handled by Promise#then()
if (--n) {
nextTick(waitNextTick)
@@ -34,16 +34,16 @@ describe('Collection', function () {
it('is iterable', function () {
const iterator = col[Symbol.iterator]()
expect(iterator.next()).toEqual({done: false, value: ['bar', 0]})
expect(iterator.next()).toEqual({done: true, value: undefined})
expect(iterator.next()).toEqual({ done: false, value: ['bar', 0] })
expect(iterator.next()).toEqual({ done: true, value: undefined })
})
describe('#keys()', function () {
it('returns an iterator over the keys', function () {
const iterator = col.keys()
expect(iterator.next()).toEqual({done: false, value: 'bar'})
expect(iterator.next()).toEqual({done: true, value: undefined})
expect(iterator.next()).toEqual({ done: false, value: 'bar' })
expect(iterator.next()).toEqual({ done: true, value: undefined })
})
})
@@ -51,8 +51,8 @@ describe('Collection', function () {
it('returns an iterator over the values', function () {
const iterator = col.values()
expect(iterator.next()).toEqual({done: false, value: 0})
expect(iterator.next()).toEqual({done: true, value: undefined})
expect(iterator.next()).toEqual({ done: false, value: 0 })
expect(iterator.next()).toEqual({ done: true, value: undefined })
})
})
@@ -70,7 +70,7 @@ describe('Collection', function () {
// Async event.
return eventToPromise(col, 'add').then(function (added) {
expect(Object.keys(added)).toEqual([ 'foo' ])
expect(Object.keys(added)).toEqual(['foo'])
expect(added.foo).toBe(true)
})
})
@@ -216,7 +216,7 @@ describe('Collection', function () {
})
it('accepts an object with an id property', function () {
col.unset({id: 'bar'})
col.unset({ id: 'bar' })
expect(col.has('bar')).toBe(false)
@@ -235,7 +235,7 @@ describe('Collection', function () {
return waitTicks().then(() => {
col.touch(foo)
return eventToPromise(col, 'update', (items) => {
return eventToPromise(col, 'update', items => {
expect(Object.keys(items)).toEqual(['foo'])
expect(items.foo).toBe(foo)
})
@@ -249,7 +249,7 @@ describe('Collection', function () {
expect(col.size).toBe(0)
return eventToPromise(col, 'remove').then((items) => {
return eventToPromise(col, 'remove').then(items => {
expect(Object.keys(items)).toEqual(['bar'])
expect(items.bar).toBeUndefined()
})
@@ -257,84 +257,69 @@ describe('Collection', function () {
})
describe('deduplicates events', function () {
forEach({
'add & update → add': [
[
['add', 'foo', 0],
['update', 'foo', 1],
],
{
add: {
foo: 1,
forEach(
{
'add & update → add': [
[['add', 'foo', 0], ['update', 'foo', 1]],
{
add: {
foo: 1,
},
},
},
],
'add & remove → ∅': [
[
['add', 'foo', 0],
['remove', 'foo'],
],
{},
],
'update & update → update': [
[
['update', 'bar', 1],
['update', 'bar', 2],
],
{
update: {
bar: 2,
'add & remove → ∅': [[['add', 'foo', 0], ['remove', 'foo']], {}],
'update & update → update': [
[['update', 'bar', 1], ['update', 'bar', 2]],
{
update: {
bar: 2,
},
},
},
],
'update & remove → remove': [
[
['update', 'bar', 1],
['remove', 'bar'],
],
{
remove: {
bar: undefined,
},
},
],
'remove & add → update': [
[
['remove', 'bar'],
['add', 'bar', 0],
'update & remove → remove': [
[['update', 'bar', 1], ['remove', 'bar']],
{
remove: {
bar: undefined,
},
},
],
{
update: {
bar: 0,
'remove & add → update': [
[['remove', 'bar'], ['add', 'bar', 0]],
{
update: {
bar: 0,
},
},
},
],
}, ([operations, results], label) => {
it(label, function () {
forEach(operations, ([method, ...args]) => {
col[method](...args)
})
],
},
([operations, results], label) => {
it(label, function () {
forEach(operations, ([method, ...args]) => {
col[method](...args)
})
const spies = Object.create(null)
forEach(['add', 'update', 'remove'], event => {
col.on(event, (spies[event] = jest.fn()))
})
const spies = Object.create(null)
forEach(['add', 'update', 'remove'], event => {
col.on(event, (spies[event] = jest.fn()))
})
return waitTicks().then(() => {
forEach(spies, (spy, event) => {
const items = results[event]
if (items) {
expect(spy.mock.calls).toEqual([ [ items ] ])
} else {
expect(spy).not.toHaveBeenCalled()
}
return waitTicks().then(() => {
forEach(spies, (spy, event) => {
const items = results[event]
if (items) {
expect(spy.mock.calls).toEqual([[items]])
} else {
expect(spy).not.toHaveBeenCalled()
}
})
})
})
})
})
}
)
})
})
+7 -20
View File
@@ -3,11 +3,7 @@ import { bind, iteratee } from 'lodash'
import clearObject from './clear-object'
import isEmpty from './is-empty'
import NotImplemented from './not-implemented'
import {
ACTION_ADD,
ACTION_UPDATE,
ACTION_REMOVE,
} from './collection'
import { ACTION_ADD, ACTION_UPDATE, ACTION_REMOVE } from './collection'
// ===================================================================
@@ -34,7 +30,7 @@ export default class Index {
// Remove empty items lists.
sweep () {
const {_itemsByHash: itemsByHash} = this
const { _itemsByHash: itemsByHash } = this
for (const hash in itemsByHash) {
if (isEmpty(itemsByHash[hash])) {
delete itemsByHash[hash]
@@ -86,14 +82,11 @@ export default class Index {
const hash = computeHash(value, key)
if (hash != null) {
(
itemsByHash[hash] ||
;(itemsByHash[hash] ||
// FIXME: We do not use objects without prototype for now
// because it breaks Angular in xo-web, change it back when
// this is fixed.
(itemsByHash[hash] = {})
)[key] = value
(itemsByHash[hash] = {}))[key] = value
keysToHash[key] = hash
}
@@ -118,12 +111,9 @@ export default class Index {
// Inserts item into the new hash's list if any.
if (hash != null) {
(
itemsByHash[hash] ||
;(itemsByHash[hash] ||
// FIXME: idem: change back to Object.create(null)
(itemsByHash[hash] = {})
)[key] = value
(itemsByHash[hash] = {}))[key] = value
keysToHash[key] = hash
} else {
@@ -133,10 +123,7 @@ export default class Index {
}
_onRemove (items) {
const {
_itemsByHash: itemsByHash,
_keysToHash: keysToHash,
} = this
const { _itemsByHash: itemsByHash, _keysToHash: keysToHash } = this
for (const key in items) {
const prev = keysToHash[key]
+2 -2
View File
@@ -9,10 +9,10 @@ import Index from './index'
// ===================================================================
const waitTicks = (n = 2) => {
const {nextTick} = process
const { nextTick } = process
return new Promise(resolve => {
(function waitNextTick () {
;(function waitNextTick () {
// The first tick is handled by Promise#then()
if (--n) {
nextTick(waitNextTick)
+1 -1
View File
@@ -1,3 +1,3 @@
export default function isObject (value) {
return (value !== null) && (typeof value === 'object')
return value !== null && typeof value === 'object'
}
@@ -1,4 +1,4 @@
import {BaseError} from 'make-error'
import { BaseError } from 'make-error'
export default class NotImplemented extends BaseError {
constructor (message) {
+2 -9
View File
@@ -2,11 +2,7 @@ import { bind, iteratee } from 'lodash'
import clearObject from './clear-object'
import NotImplemented from './not-implemented'
import {
ACTION_ADD,
ACTION_UPDATE,
ACTION_REMOVE,
} from './collection'
import { ACTION_ADD, ACTION_UPDATE, ACTION_REMOVE } from './collection'
// ===================================================================
@@ -108,10 +104,7 @@ export default class UniqueIndex {
}
_onRemove (items) {
const {
_itemByHash: itemByHash,
_keysToHash: keysToHash,
} = this
const { _itemByHash: itemByHash, _keysToHash: keysToHash } = this
for (const key in items) {
const prev = keysToHash[key]
@@ -9,10 +9,10 @@ import Index from './unique-index'
// ===================================================================
const waitTicks = (n = 2) => {
const {nextTick} = process
const { nextTick } = process
return new Promise(resolve => {
(function waitNextTick () {
;(function waitNextTick () {
// The first tick is handled by Promise#then()
if (--n) {
nextTick(waitNextTick)
+1 -1
View File
@@ -7,7 +7,7 @@ import View from './view'
// Create the collection.
const users = new Collection()
users.getKey = (user) => user.name
users.getKey = user => user.name
// Inserts some data.
users.add({
+2 -2
View File
@@ -54,7 +54,7 @@ export default class View extends Collection {
}
_onAdd (items) {
const {_predicate: predicate} = this
const { _predicate: predicate } = this
forEach(items, (value, key) => {
if (predicate(value, key, this)) {
@@ -67,7 +67,7 @@ export default class View extends Collection {
}
_onUpdate (items) {
const {_predicate: predicate} = this
const { _predicate: predicate } = this
forEach(items, (value, key) => {
if (predicate(value, key, this)) {