Skip to content

Commit

Permalink
Merge pull request #22 from kouhin/feature/update_deps
Browse files Browse the repository at this point in the history
update deps
  • Loading branch information
kouhin authored Dec 1, 2016
2 parents 69efeec + 63210fd commit d541c15
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 40 deletions.
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

19 changes: 19 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
machine:
node:
version: 7
dependencies:
override:
- sudo apt-get install jq
- npm install
- npm run build
test:
override:
- npm test
deployment:
production:
branch: master
commands:
- git tag v`jq -r '.version' package.json`
- git push origin --tags
- echo -e "$NPM_USERNAME\n$NPM_PASSWORD\n$NPM_EMAIL" | npm login
- npm publish
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,13 @@
"babel-eslint": "^6.1.2",
"babel-loader": "^6.2.4",
"babel-plugin-transform-runtime": "^6.9.0",
"babel-preset-env": "0.0.9",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-0": "^6.5.0",
"chai": "^3.5.0",
"chai-as-promised": "^5.3.0",
"eslint": "^3.0.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.10.2",
"eslint-plugin-jsx-a11y": "^1.5.5",
"eslint-plugin-react": "^5.2.2",
"eslint-config-airbnb-deps": "^13.0.0",
"isparta": "^4.0.0",
"istanbul": "^0.4.4",
"mocha": "^2.5.3",
Expand Down
10 changes: 5 additions & 5 deletions src/data-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ class DataLoaderTask {
break;
} catch (ex) {
debug('Fetching failed, ex = ', ex);
currentRetry++;
currentRetry += 1;
if (options.retryTimes && currentRetry < opts.retryTimes) {
const sleepTime = opts.retryWait.next().value;
if (debug.enabled) {
debug(`Sleeping for ${sleepTime} ms..., and retry`);
}
await sleep(sleepTime);
continue;
} else {
error = ex;
break;
}
error = ex;
break;
}
}
if (!error) {
Expand All @@ -115,7 +115,7 @@ class DataLoaderTask {
if (successAction.type === this.context.action.type) {
const errorAction = this.params.error(
this.context,
new Error('Result action type equals origial action type', this.context.action)
new Error('Result action type equals origial action type', this.context.action),
);
this.context.dispatch(errorAction);
if (!disableInternalAction) {
Expand Down
11 changes: 6 additions & 5 deletions src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import { LOAD_DATA_REQUEST_ACTION } from './action';
const debug = new Debug('redux-dataloader:middleware');

function findRunningTaskKey(runningTasksMap, action) {
return findKey(runningTasksMap, (o) => isEqual(o.action, action));
return findKey(runningTasksMap, o => isEqual(o.action, action));
}

export default function createDataLoaderMiddleware(loaders, args, opts) {
const runningTasks = {};

let currentId = 1;
const uniqueId = (prefix) => `${prefix}${currentId++}`;
currentId += 1;
const uniqueId = prefix => `${prefix}${currentId}`;

const middleware = ({ dispatch, getState }) => {
const ctx = {
Expand All @@ -26,7 +27,7 @@ export default function createDataLoaderMiddleware(loaders, args, opts) {
getState,
};

return (next) => (receivedAction) => {
return next => (receivedAction) => {
if (!isPromise(receivedAction)) {
return next(receivedAction);
}
Expand All @@ -48,7 +49,7 @@ export default function createDataLoaderMiddleware(loaders, args, opts) {
return runningTasks[runningTaskKey].promise;
}

const taskDescriptor = find(loaders, (loader) => loader.supports(action));
const taskDescriptor = find(loaders, loader => loader.supports(action));
debug('Cache does not hit, finding task descriptor', taskDescriptor);

if (!taskDescriptor) {
Expand All @@ -63,7 +64,7 @@ export default function createDataLoaderMiddleware(loaders, args, opts) {
debug(
'Merge options from taskDescriptor and dispatched action',
taskDescriptor.options,
asyncAction.meta.options, options
asyncAction.meta.options, options,
);

const key = uniqueId(`${action.type}__`);
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function isAction(action) {
export function formatError(err) {
const error = (err instanceof Error) ? err : new Error(err);
const result = {};
Object.getOwnPropertyNames(error).forEach(key => {
Object.getOwnPropertyNames(error).forEach((key) => {
result[key] = error[key];
});
return result;
Expand Down
26 changes: 13 additions & 13 deletions src/wait-strategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Returns a wait strategy that sleeps a fixed amount of time before retrying (in millisecond).
*/
export function * fixedWait(sleepTime) {
export function* fixedWait(sleepTime) {
for (;;) {
yield sleepTime;
}
Expand All @@ -17,43 +17,43 @@ export function * fixedWait(sleepTime) {
* Returns a strategy which sleeps for an exponential amount of time after the first failed attempt,
* and in exponentially incrementing amounts after each failed attempt up to the maximumTime.
*/
export function * exponentialWait(multiplier = 1, max = Number.MAX_VALUE) {
export function* exponentialWait(multiplier = 1, max = Number.MAX_VALUE) {
let current = 2 * multiplier;
for (;;) {
const next = 2 * current;
if (next > max) {
yield current;
continue;
} else {
yield current;
current = next;
}
yield current;
current = next;
}
}

/**
* Returns a strategy which sleeps for an increasing amount of time after the first failed attempt
* and in Fibonacci increments after each failed attempt up to the maximumTime.
*/
export function * fibonacciWait(multiplier = 1, max = Number.MAX_VALUE) {
export function* fibonacciWait(multiplier = 1, max = Number.MAX_VALUE) {
let fn1 = 1 * multiplier;
let fn2 = 1 * multiplier;
for (;;) {
const current = fn2;
if (fn1 > max) {
yield current;
continue;
} else {
fn2 = fn1;
fn1 += current;
yield current;
}
fn2 = fn1;
fn1 = fn1 + current;
yield current;
}
}

/**
* Returns a strategy that sleeps a fixed amount of time after the first failed attempt
* and in incrementing amounts of time after each additional failed attempt.
*/
export function * incrementingWait(initialSleepTime = 0, increment = 1000, max = Number.MAX_VALUE) {
export function* incrementingWait(initialSleepTime = 0, increment = 1000, max = Number.MAX_VALUE) {
let current = initialSleepTime;
yield current;
for (;;) {
Expand All @@ -68,8 +68,8 @@ export function * incrementingWait(initialSleepTime = 0, increment = 1000, max =
/**
* Returns a strategy that sleeps a random amount of time before retrying.
*/
export function * randomWait(min, max) {
export function* randomWait(min, max) {
for (;;) {
yield parseInt(min + (max - min) * Math.random(), 10);
yield parseInt(min + ((max - min) * Math.random()), 10);
}
}
2 changes: 1 addition & 1 deletion test/data-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('test createLoader: action matcher', () => {
});

it('create a data loader that uses function to match', () => {
const descriptor = createLoader((action) =>
const descriptor = createLoader(action =>
(action.payload && action.type && action.type === 'USER_REQUEST'), loader);
expect(descriptor.supports(requestAction)).to.be.equal(true);
expect(descriptor.supports('USER_REQUEST')).to.not.be.equal(true);
Expand Down
2 changes: 1 addition & 1 deletion test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('utils', () => {
});

it('new Promise() is a Promise', () => {
expect(isPromise(new Promise((resolve) => resolve(false)))).to.be.true;
expect(isPromise(new Promise(resolve => resolve(false)))).to.be.true;
});
it('Function is not a Promise', () => {
expect(isPromise(() => true)).to.not.be.true;
Expand Down

0 comments on commit d541c15

Please sign in to comment.