Skip to content

Commit

Permalink
lint stories
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Aug 31, 2019
1 parent c23fd5b commit 258a5de
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 65 deletions.
4 changes: 2 additions & 2 deletions stories/addons.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import '@storybook/addon-actions/register';
import '@storybook/addon-links/register';
import "@storybook/addon-actions/register";
import "@storybook/addon-links/register";
import "@storybook/addon-storysource/register";
6 changes: 3 additions & 3 deletions stories/config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { configure } from '@storybook/react';
import { configure } from "@storybook/react";

// automatically import all files ending in *.stories.js
const req = require.context('.', true, /\.stories\.js$/);
const req = require.context(".", true, /\.stories\.js$/);
function loadStories() {
req.keys().forEach(filename => req(filename));
req.keys().forEach((filename) => req(filename));
}

configure(loadStories, module);
113 changes: 55 additions & 58 deletions stories/react-hooks.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,59 @@ import { Repeater } from "@repeaterjs/repeater";
import { useResult } from "../lib/react-hooks.esm";

storiesOf("useResult", module)
.add("counter", () => {
const result = useResult(async function*() {
let i = 0;
while (true) {
yield i++;
await new Promise((resolve) => setTimeout(resolve, 1000));
}
});
.add("counter", () => {
const result = useResult(async function*() {
let i = 0;
while (true) {
yield i++;
await new Promise((resolve) => setTimeout(resolve, 1000));
}
});

return (
<div>Current value: {result && result.value}</div>
);
})
.add("websocket", () => {
const [socket] = useState(() => {
return new WebSocket("wss://echo.websocket.org");
});
const [open] = useState(() => {
return new Promise((resolve) => (socket.onopen = resolve));
});
const messages = new Repeater(async (push, stop) => {
socket.onmessage = (ev) => push(ev.data);
socket.onerror = () => stop(new Error("WebSocket error"));
socket.onclose = () => stop();
await stop;
socket.close();
});
const [value, setValue] = useState("");
const result = useResult(async function*() {
const value = [];
yield value;
for await (const message of messages) {
value.push(message);
yield value;
}
});
return (
<div>
<input
type="text"
value={value}
onChange={(ev) => {
setValue(ev.target.value);
}}
onKeyPress={(ev) => {
if (ev.key === "Enter") {
open.then(() => {
socket.send(value);
setValue("");
});
}
}}
/>
{result && result.value.map((message, i) => (
<div key={i}>{message}</div>
))}
</div>
);
});
return <div>Current value: {result && result.value}</div>;
})
.add("websocket", () => {
const [socket] = useState(() => {
return new WebSocket("wss://echo.websocket.org");
});
const [open] = useState(() => {
return new Promise((resolve) => (socket.onopen = resolve));
});
const messages = new Repeater(async (push, stop) => {
socket.onmessage = (ev) => push(ev.data);
socket.onerror = () => stop(new Error("WebSocket error"));
socket.onclose = () => stop();
await stop;
socket.close();
});
const [value, setValue] = useState("");
const result = useResult(async function*() {
const value = [];
yield value;
for await (const message of messages) {
value.push(message);
yield value;
}
});
return (
<div>
<input
type="text"
value={value}
onChange={(ev) => {
setValue(ev.target.value);
}}
onKeyPress={(ev) => {
if (ev.key === "Enter") {
open.then(() => {
socket.send(value);
setValue("");
});
}
}}
/>
{result &&
result.value.map((message, i) => <div key={i}>{message}</div>)}
</div>
);
});
4 changes: 2 additions & 2 deletions stories/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = function({ config }) {
config.module.rules.push({
test: /\.stories\.jsx?$/,
loaders: [require.resolve('@storybook/source-loader')],
enforce: 'pre',
loaders: [require.resolve("@storybook/source-loader")],
enforce: "pre",
});

return config;
Expand Down

0 comments on commit 258a5de

Please sign in to comment.