Skip to content

Commit

Permalink
Bump eslint-plugin-coorpacademy to v5 (+ prettier reformat)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Apr 14, 2017
1 parent ef59656 commit 3b451f7
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 95 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"rxjs": "^5.0.0-beta.7"
},
"devDependencies": {
"@coorpacademy/eslint-plugin-coorpacademy": "^4.0.1",
"@coorpacademy/eslint-plugin-coorpacademy": "^5.0.0",
"ava": "^0.16.0",
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
Expand Down
9 changes: 3 additions & 6 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ const createAPI = (store, client, options = {cwd: '/'}) => {

return _get(
_path,
find(
function(child) {
return startsWith(child.key, _path);
},
node.nodes
)
find(function(child) {
return startsWith(child.key, _path);
}, node.nodes)
);
});

Expand Down
22 changes: 9 additions & 13 deletions src/build-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@ const buildIndex = (index, node) => {
)(node);
};

const updateIndexes = indexes =>
store => {
debug(`Update indexes ${indexes.join(',')}`);
return zipObject(
indexes,
map(
function(index) {
return buildIndex(index, store);
},
indexes
)
);
};
const updateIndexes = indexes => store => {
debug(`Update indexes ${indexes.join(',')}`);
return zipObject(
indexes,
map(function(index) {
return buildIndex(index, store);
}, indexes)
);
};

export default updateIndexes;
3 changes: 2 additions & 1 deletion src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const debug = createDebug('squirrel:etcd');
const createFetch$ = (client, cwd) => {
debug(`fetch: ${cwd}`);
const list = Observable.bindNodeCallback(cb =>
client.get(cwd, {recursive: true}, (err, data) => cb(err, data)));
client.get(cwd, {recursive: true}, (err, data) => cb(err, data))
);

return Observable.of(list).map(f => f()).mergeAll().retry(Infinity).map(parseAction);
};
Expand Down
23 changes: 11 additions & 12 deletions src/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ const debug = createDebug('squirrel:save');

const writeFile$ = Observable.bindNodeCallback(writeFile);

const createSave = filePath =>
event$ => {
if (!isString(filePath)) return event$;
const createSave = filePath => event$ => {
if (!isString(filePath)) return event$;

return event$
.map(event => {
debug(`saving ${filePath}`);
return writeFile$(filePath, stringify(event), {encoding: 'UTF8'})
.do(() => debug(`saved ${filePath}`))
.mapTo(event);
})
.concatAll();
};
return event$
.map(event => {
debug(`saving ${filePath}`);
return writeFile$(filePath, stringify(event), {encoding: 'UTF8'})
.do(() => debug(`saved ${filePath}`))
.mapTo(event);
})
.concatAll();
};

export default createSave;
3 changes: 2 additions & 1 deletion src/test/etcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ test('should composite events observable', async t => {
const eventsP = events$.take(6).toArray().toPromise();

[setEvent, deleteEvent, resyncEvent, deleteEvent, setEvent].forEach(event =>
watcher.emit(event.action, event));
watcher.emit(event.action, event)
);

const events = await eventsP;
t.deepEqual(events, expected);
Expand Down
17 changes: 4 additions & 13 deletions src/test/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import createStore from '../store';
test('should get node and indexes', t => {
const node$ = new Subject();

const {
store
} = createStore(node$, identity);
const {store} = createStore(node$, identity);

const assert = Promise.all([
store('node').then(node => t.deepEqual(node, 'foo')),
Expand All @@ -23,30 +21,23 @@ test('should get node and indexes', t => {
test('should wait first event', t => {
const node$ = new Subject();

const {
store
} = createStore(node$, identity);
const {store} = createStore(node$, identity);

t.throws(Promise.race([store('node'), Promise.reject(new Error())]));
});

test('should return subscription', t => {
const node$ = Observable.empty();

const {
subscription
} = createStore(node$, identity);
const {subscription} = createStore(node$, identity);

t.true(subscription instanceof Subscription);
});

test('should', async t => {
const node$ = Observable.of('foo', 'bar');

const {
store,
subscription
} = createStore(node$, identity);
const {store, subscription} = createStore(node$, identity);

const [node, indexes] = await Promise.all([store('node'), store('indexes')]);
t.deepEqual(node, 'bar');
Expand Down
12 changes: 5 additions & 7 deletions src/util/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ export const syncDirectory$ = (client, pathFS, pathETCD) => {
return entries
.toArray()
.flatMap(_entries => {
const nodeToDelete = filter(
_node => {
return !includes(join(pathFS, relative(pathETCD, _node.key)), _entries);
},
nodes
);
const nodeToDelete = filter(_node => {
return !includes(join(pathFS, relative(pathETCD, _node.key)), _entries);
}, nodes);
const nodeToDelete$ = Observable.from(nodeToDelete).flatMap(_node =>
delRecursive$(client, _node.key));
delRecursive$(client, _node.key)
);
return nodeToDelete$;
})
.toArray()
Expand Down
41 changes: 20 additions & 21 deletions src/util/etcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@ import makeDebug from 'debug';

const debug = makeDebug('squirrel:util:etcd');

const wrap = fnName =>
(client, ...argz) =>
debug(fnName, ...argz, client) ||
Observable.create(observer => {
const token = invokeArgs(
fnName,
[
...argz,
(err, value) => {
if (err) return observer.error(err);
observer.next(value);
observer.complete();
}
],
client
);

return () => {
token.abort();
};
});
const wrap = fnName => (client, ...argz) =>
debug(fnName, ...argz, client) ||
Observable.create(observer => {
const token = invokeArgs(
fnName,
[
...argz,
(err, value) => {
if (err) return observer.error(err);
observer.next(value);
observer.complete();
}
],
client
);

return () => {
token.abort();
};
});

export const compareAndSwap$ = wrap('compareAndSwap');

Expand Down
3 changes: 2 additions & 1 deletion src/util/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export const isFile$ = pathFS => stat$(pathFS).map(_stat => _stat.isFile());
export const isDirectory$ = pathFS => stat$(pathFS).map(_stat => _stat.isDirectory());

export const filter$ = curry((predicate, value) =>
predicate(value).filter(Boolean).map(() => value));
predicate(value).filter(Boolean).map(() => value)
);
36 changes: 17 additions & 19 deletions src/util/test/helpers/etcd.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import EventEmitter from 'events'; // eslint-disable-line fp/no-events
import {assign, mapValues, noop, pipe} from 'lodash/fp';

const createWatcher = () =>
() => {
const watcher = new EventEmitter();
watcher.stop = noop;
return watcher;
};
const createWatcher = () => () => {
const watcher = new EventEmitter();
watcher.stop = noop;
return watcher;
};

const createEtcdMock = (mock, watcher = createWatcher(), abort = noop) =>
pipe(
mapValues(mocks =>
(...argz) => {
let rets = mocks.shift();
if (rets.assert) {
rets.assert(...argz);
rets = rets.values;
}
const cb = argz.pop();
setTimeout(() => cb(...rets), 0);
return {
abort
};
}),
mapValues(mocks => (...argz) => {
let rets = mocks.shift();
if (rets.assert) {
rets.assert(...argz);
rets = rets.values;
}
const cb = argz.pop();
setTimeout(() => cb(...rets), 0);
return {
abort
};
}),
assign({
watcher
})
Expand Down

0 comments on commit 3b451f7

Please sign in to comment.