Skip to content

Commit

Permalink
upgrade deps
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Nov 10, 2019
1 parent c7098d0 commit 36d8521
Show file tree
Hide file tree
Showing 4 changed files with 609 additions and 488 deletions.
50 changes: 25 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,36 @@
"build-storybook": "build-storybook --config-dir stories"
},
"dependencies": {
"@repeaterjs/repeater": "^2.0.0"
"@repeaterjs/repeater": "^3.0.1"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@storybook/addon-actions": "^5.2.0-rc.0",
"@storybook/addon-links": "^5.2.0-rc.0",
"@storybook/addon-storysource": "^5.2.0-rc.0",
"@storybook/addons": "^5.2.0-rc.0",
"@storybook/react": "^5.2.0-rc.0",
"@testing-library/react-hooks": "^2.0.1",
"@types/jest": "^24.0.18",
"@types/react": "^16.9.2",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"@babel/core": "^7.7.2",
"@storybook/addon-actions": "^5.2.6",
"@storybook/addon-links": "^5.2.6",
"@storybook/addon-storysource": "^5.2.6",
"@storybook/addons": "^5.2.6",
"@storybook/react": "^5.2.6",
"@testing-library/react-hooks": "^3.2.1",
"@types/jest": "^24.0.22",
"@types/react": "^16.9.11",
"@typescript-eslint/eslint-plugin": "^2.6.1",
"@typescript-eslint/parser": "^2.6.1",
"babel-loader": "^8.0.6",
"eslint": "^6.2.1",
"eslint-config-prettier": "^6.1.0",
"eslint-plugin-jest": "^22.15.2",
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-react-hooks": "^2.0.1",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.5.0",
"eslint-plugin-jest": "^23.0.3",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-react": "^7.16.0",
"eslint-plugin-react-hooks": "^2.2.0",
"jest": "^24.9.0",
"prettier": "^1.18.2",
"react": "^16.9.0",
"react-test-renderer": "^16.9.0",
"rollup": "^1.20.0",
"rollup-plugin-typescript2": "^0.22.1",
"prettier": "^1.19.1",
"react": "^16.11.0",
"react-test-renderer": "^16.11.0",
"rollup": "^1.26.4",
"rollup-plugin-typescript2": "^0.25.2",
"shx": "^0.3.2",
"ts-jest": "^24.0.0",
"typescript": "^3.5.3",
"ts-jest": "^24.1.0",
"typescript": "^3.7.2",
"weak": "^1.0.1"
},
"peerDependencies": {
Expand Down
48 changes: 19 additions & 29 deletions src/__tests__/react-hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act } from "react-test-renderer";
import { Repeater } from "@repeaterjs/repeater";
import { Push, Repeater, Stop } from "@repeaterjs/repeater";
import { renderHook } from "@testing-library/react-hooks";
import { useAsyncIter, useRepeater, useResult, useValue } from "../react-hooks";

Expand Down Expand Up @@ -98,8 +98,8 @@ describe("useAsyncIter", () => {

describe("useResult", () => {
test("basic", async () => {
let push: (value: number) => Promise<void>;
let stop: (() => void) & Promise<void>;
let push: Push<number>;
let stop: Stop;
const repeater = new Repeater(async (push1, stop1) => {
push = push1;
stop = stop1;
Expand All @@ -115,22 +115,21 @@ describe("useResult", () => {
});

expect(result.current).toBeUndefined();
await act(() => push(1));
await act(async () => void (await push(1)));
expect(result.current).toEqual({ value: 1, done: false });
await act(() => push(2));
await act(async () => void (await push(2)));
expect(result.current).toEqual({ value: 2, done: false });
await act(() => push(3));
await act(async () => void (await push(3)));
expect(result.current).toEqual({ value: 3, done: false });
await act(() => push(4));
await act(async () => void (await push(4)));
expect(result.current).toEqual({ value: 4, done: false });
// we have to return stop here to stop act from yelling at us
await act(async () => (stop(), stop));
expect(result.current).toEqual({ value: -1, done: true });
expect(callback).toHaveBeenCalledTimes(1);
});

test("unmount", async () => {
let push: (value: number) => Promise<void>;
let push: Push<number>;
const repeater = new Repeater(async (push1) => {
push = push1;
return -1;
Expand All @@ -145,7 +144,7 @@ describe("useResult", () => {
});

expect(result.current).toBeUndefined();
await act(() => push(1));
await act(async () => void (await push(1)));
expect(result.current).toEqual({ value: 1, done: false });
unmount();
expect(callback).toHaveBeenCalledTimes(1);
Expand All @@ -154,11 +153,7 @@ describe("useResult", () => {

test("deps", async () => {
const callback = jest.fn((deps) => {
return new Repeater<number>(async (push1) => {
const push = async (num: number) => {
return act(() => push1(num));
};

return new Repeater<number>(async (push) => {
for await (const [num] of deps) {
await push(num);
}
Expand Down Expand Up @@ -191,8 +186,8 @@ describe("useResult", () => {

describe("useValue", () => {
test("basic", async () => {
let push: (value: number) => Promise<void>;
let stop: (() => void) & Promise<void>;
let push: Push<number>;
let stop: Stop;
const repeater = new Repeater(async (push1, stop1) => {
push = push1;
stop = stop1;
Expand All @@ -208,15 +203,14 @@ describe("useValue", () => {
});

expect(result.current).toBeUndefined();
await act(() => push(1));
await act(async () => void (await push(1)));
expect(result.current).toBe(1);
await act(() => push(2));
await act(async () => void (await push(2)));
expect(result.current).toBe(2);
await act(() => push(3));
await act(async () => void (await push(3)));
expect(result.current).toBe(3);
await act(() => push(4));
await act(async () => void (await push(4)));
expect(result.current).toBe(4);
// we have to return stop here to stop act from yelling at us
await act(async () => (stop(), stop));
expect(result.current).toBe(-1);
rerender();
Expand All @@ -225,7 +219,7 @@ describe("useValue", () => {
});

test("unmount", async () => {
let push: (value: number) => Promise<void>;
let push: Push<number>;
const repeater = new Repeater(async (push1) => {
push = push1;
return -1;
Expand All @@ -241,7 +235,7 @@ describe("useValue", () => {
});

expect(result.current).toBeUndefined();
await act(() => push(1));
await act(async () => void (await push(1)));
expect(result.current).toBe(1);
unmount();
expect(callback).toHaveBeenCalledTimes(1);
Expand All @@ -250,11 +244,7 @@ describe("useValue", () => {

test("deps", async () => {
const callback = jest.fn((deps) => {
return new Repeater<number>(async (push1) => {
const push = async (num: number) => {
return act(() => push1(num));
};

return new Repeater<number>(async (push) => {
for await (const [num] of deps) {
await push(num);
}
Expand Down
8 changes: 4 additions & 4 deletions src/react-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { Push, Repeater, RepeaterBuffer, Stop } from "@repeaterjs/repeater";
// We need to return push and stop synchronously from the useRepeater hook so
// we prime the repeater by calling next immediately.
function createPrimedRepeater<T>(
buffer?: RepeaterBuffer<T>,
buffer?: RepeaterBuffer,
): [Repeater<T>, Push<T>, Stop] {
let push: Push<T>;
let stop: Stop;
const repeater = new Repeater((push1, stop1) => {
const repeater = new Repeater<T>((push1, stop1) => {
push = push1;
stop = stop1;
// this value is thrown away
Expand All @@ -21,9 +21,9 @@ function createPrimedRepeater<T>(
}

export function useRepeater<T>(
buffer?: RepeaterBuffer<T>,
buffer?: RepeaterBuffer,
): [Repeater<T>, Push<T>, Stop] {
const [tuple] = useState(() => createPrimedRepeater(buffer));
const [tuple] = useState(() => createPrimedRepeater<T>(buffer));
return tuple;
}

Expand Down
Loading

0 comments on commit 36d8521

Please sign in to comment.