From 9c914d862ca39b044569864306588c0de67a58a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phil=20Pl=C3=BCckthun?= Date: Fri, 10 Jan 2020 18:00:42 +0000 Subject: [PATCH] Fix up Flow types and add check script (#68) --- .flowconfig | 11 +++++++++++ package.json | 5 ++++- scripts/generate-flow-files.js | 3 ++- src/helpers/Wonka_deriving.ts | 28 ++++++++++++++++------------ src/helpers/Wonka_flow_test.js | 9 +++++++++ yarn.lock | 5 +++++ 6 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 .flowconfig create mode 100644 src/helpers/Wonka_flow_test.js diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 0000000..1fed445 --- /dev/null +++ b/.flowconfig @@ -0,0 +1,11 @@ +[ignore] + +[include] + +[libs] + +[lints] + +[options] + +[strict] diff --git a/package.json b/package.json index 34b94e5..49f89da 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ "scripts": { "docs:dev": "gatsby develop", "docs:build": "gatsby build", - "check": "tsc --noEmit", + "check:ts": "tsc --noEmit", + "check:flow": "flow focus-check ./src/helpers/Wonka_flow_test.js", + "check": "run-s check:ts check:flow", "bs:clean": "bsb -clean-world", "bs:build": "bsb -make-world", "bs:watch": "bsb -make-world -w", @@ -72,6 +74,7 @@ "callbag-iterate": "^1.0.0", "callbag-take": "^1.4.0", "coveralls": "^3.0.9", + "flow-bin": "^0.115.0", "flowgen": "^1.10.0", "gatsby": "^2.18.17", "gatsby-plugin-netlify": "^2.1.30", diff --git a/scripts/generate-flow-files.js b/scripts/generate-flow-files.js index aa98989..33d669b 100755 --- a/scripts/generate-flow-files.js +++ b/scripts/generate-flow-files.js @@ -53,7 +53,8 @@ const gen = async () => { const basename = path.basename(fullpath, '.d.ts'); const filepath = path.dirname(fullpath); const newpath = path.join(filepath, basename + '.js.flow'); - return writeFile(newpath, preamble + flowdef); + const definition = flowdef.replace(/import/g, 'import type'); + return writeFile(newpath, preamble + definition); }); return Promise.all([...write, genEntry()]); diff --git a/src/helpers/Wonka_deriving.ts b/src/helpers/Wonka_deriving.ts index 09585b2..f5dd77f 100644 --- a/src/helpers/Wonka_deriving.ts +++ b/src/helpers/Wonka_deriving.ts @@ -1,24 +1,28 @@ import { __ as block } from 'bs-platform/lib/es6/block'; import { talkbackPlaceholder } from './Wonka_helpers.bs'; -import * as types from '../Wonka_types.gen'; -type talkbackCb = (tb: types.talkbackT) => void; +import { + talkbackT, + signalT +} from '../Wonka_types.gen'; -export const pull = (0 as any as types.talkbackT); -export const close = (1 as any as types.talkbackT); +type talkbackCb = (tb: talkbackT) => void; -export const start = (tb: talkbackCb): types.signalT => block(0, [tb]) as any; -export const push = (x: a): types.signalT => block(1, [x]) as any; -export const end = (): types.signalT => 0 as any; +export const pull = (0 as any as talkbackT); +export const close = (1 as any as talkbackT); -export const isStart = (s: types.signalT) => +export const start = (tb: talkbackCb): signalT => block(0, [tb]) as any; +export const push = (x: a): signalT => block(1, [x]) as any; +export const end = (): signalT => 0 as any; + +export const isStart = (s: signalT) => typeof s !== 'number' && (s as any).tag === 0; -export const isPush = (s: types.signalT) => +export const isPush = (s: signalT) => typeof s !== 'number' && (s as any).tag === 1; -export const isEnd = (s: types.signalT) => +export const isEnd = (s: signalT) => typeof s === 'number' && (s as any) === 0; -export const unboxPush = (s: types.signalT): a | null => +export const unboxPush = (s: signalT): a | null => isPush(s) ? (s as any)[0] : null; -export const unboxStart = (s: types.signalT): talkbackCb => +export const unboxStart = (s: signalT): talkbackCb => isStart(s) ? (s as any)[0] : (talkbackPlaceholder as any); diff --git a/src/helpers/Wonka_flow_test.js b/src/helpers/Wonka_flow_test.js new file mode 100644 index 0000000..2848a1b --- /dev/null +++ b/src/helpers/Wonka_flow_test.js @@ -0,0 +1,9 @@ +// @flow + +import * as Wonka from '../../'; + +Wonka.pipe( + Wonka.fromArray([1, 2, 3]), + Wonka.map(x => x * 2), + Wonka.publish +); diff --git a/yarn.lock b/yarn.lock index 3de0818..bc12bd5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6131,6 +6131,11 @@ flatted@^2.0.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.1.tgz#69e57caa8f0eacbc281d2e2cb458d46fdb449e08" integrity sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg== +flow-bin@^0.115.0: + version "0.115.0" + resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.115.0.tgz#22e3ad9e5c7198967de80138ba8a9154ff387960" + integrity sha512-xW+U2SrBaAr0EeLvKmXAmsdnrH6x0Io17P6yRJTNgrrV42G8KXhBAD00s6oGbTTqRyHD0nP47kyuU34zljZpaQ== + flowgen@^1.10.0: version "1.10.0" resolved "https://registry.yarnpkg.com/flowgen/-/flowgen-1.10.0.tgz#a041ae31d543d22166e7ba7c296b8445deb3c2e4"