From 258a5de53878e8ddb1c9960e98000a1efa3889d9 Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Sat, 31 Aug 2019 18:05:35 -0400 Subject: [PATCH] lint stories --- stories/addons.js | 4 +- stories/config.js | 6 +- stories/react-hooks.stories.js | 113 ++++++++++++++++----------------- stories/webpack.config.js | 4 +- 4 files changed, 62 insertions(+), 65 deletions(-) diff --git a/stories/addons.js b/stories/addons.js index 8bc5b72..50f5dd5 100644 --- a/stories/addons.js +++ b/stories/addons.js @@ -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"; diff --git a/stories/config.js b/stories/config.js index 0ddb457..15a1e7f 100644 --- a/stories/config.js +++ b/stories/config.js @@ -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); diff --git a/stories/react-hooks.stories.js b/stories/react-hooks.stories.js index 19afeea..87eb8a1 100644 --- a/stories/react-hooks.stories.js +++ b/stories/react-hooks.stories.js @@ -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 ( -
Current value: {result && result.value}
- ); - }) - .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 ( -
- { - setValue(ev.target.value); - }} - onKeyPress={(ev) => { - if (ev.key === "Enter") { - open.then(() => { - socket.send(value); - setValue(""); - }); - } - }} - /> - {result && result.value.map((message, i) => ( -
{message}
- ))} -
- ); - }); + return
Current value: {result && result.value}
; + }) + .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 ( +
+ { + setValue(ev.target.value); + }} + onKeyPress={(ev) => { + if (ev.key === "Enter") { + open.then(() => { + socket.send(value); + setValue(""); + }); + } + }} + /> + {result && + result.value.map((message, i) =>
{message}
)} +
+ ); + }); diff --git a/stories/webpack.config.js b/stories/webpack.config.js index b20782f..2d1d2ab 100644 --- a/stories/webpack.config.js +++ b/stories/webpack.config.js @@ -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;