Skip to content

Commit

Permalink
Fix up Flow types and add check script (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten authored Jan 10, 2020
1 parent afde108 commit 9c914d8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
11 changes: 11 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[ignore]

[include]

[libs]

[lints]

[options]

[strict]
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion scripts/generate-flow-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
Expand Down
28 changes: 16 additions & 12 deletions src/helpers/Wonka_deriving.ts
Original file line number Diff line number Diff line change
@@ -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 = <a>(tb: talkbackCb): types.signalT<a> => block(0, [tb]) as any;
export const push = <a>(x: a): types.signalT<a> => block(1, [x]) as any;
export const end = <a>(): types.signalT<a> => 0 as any;
export const pull = (0 as any as talkbackT);
export const close = (1 as any as talkbackT);

export const isStart = <a>(s: types.signalT<a>) =>
export const start = <a>(tb: talkbackCb): signalT<a> => block(0, [tb]) as any;
export const push = <a>(x: a): signalT<a> => block(1, [x]) as any;
export const end = <a>(): signalT<a> => 0 as any;

export const isStart = <a>(s: signalT<a>) =>
typeof s !== 'number' && (s as any).tag === 0;
export const isPush = <a>(s: types.signalT<a>) =>
export const isPush = <a>(s: signalT<a>) =>
typeof s !== 'number' && (s as any).tag === 1;
export const isEnd = <a>(s: types.signalT<a>) =>
export const isEnd = <a>(s: signalT<a>) =>
typeof s === 'number' && (s as any) === 0;

export const unboxPush = <a>(s: types.signalT<a>): a | null =>
export const unboxPush = <a>(s: signalT<a>): a | null =>
isPush(s) ? (s as any)[0] : null;
export const unboxStart = <a>(s: types.signalT<a>): talkbackCb =>
export const unboxStart = <a>(s: signalT<a>): talkbackCb =>
isStart(s) ? (s as any)[0] : (talkbackPlaceholder as any);
9 changes: 9 additions & 0 deletions src/helpers/Wonka_flow_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @flow

import * as Wonka from '../../';

Wonka.pipe(
Wonka.fromArray([1, 2, 3]),
Wonka.map(x => x * 2),
Wonka.publish
);
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9c914d8

Please sign in to comment.