Skip to content

Commit

Permalink
Merge pull request #14 from openscript/develop
Browse files Browse the repository at this point in the history
Enhance typing
  • Loading branch information
openscript committed May 26, 2020
2 parents 103b4ef + 90a2473 commit 39660b6
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 51 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"react"
],
"homepage": "https://openscript.github.io/react-dsv-import/",
"version": "0.3.1",
"version": "0.3.2",
"main": "dist/index.js",
"module": "dist/es/index.js",
"types": "dist/index.d.ts",
Expand All @@ -32,8 +32,8 @@
"@types/node": "^14.0.5",
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.8",
"@typescript-eslint/eslint-plugin": "^3.0.0",
"@typescript-eslint/parser": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^3.0.1",
"@typescript-eslint/parser": "^3.0.1",
"babel-loader": "^8.1.0",
"babel-preset-react-app": "^9.1.2",
"eslint": "^7.1.0",
Expand Down
6 changes: 3 additions & 3 deletions src/DSVImport.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { PropsWithChildren, useReducer, useEffect } from 'react';
import { ColumnType } from './models/column';
import { ColumnType, GenericColumnType } from './models/column';
import { getDSVImportContext, useDSVImport, createReducer } from './features/context';
import { createParserMiddleware } from './middlewares/parserMiddleware';
import { State } from './models/state';
Expand All @@ -14,7 +14,7 @@ interface EventListenerProps<T> {
onValidation?: (errors: ValidationError<T>[]) => void;
}

const EventListener = <T extends { [key: string]: string }>(props: EventListenerProps<T>) => {
const EventListener = <T extends GenericColumnType>(props: EventListenerProps<T>) => {
const [context] = useDSVImport<T>();

useEffect(() => {
Expand All @@ -39,7 +39,7 @@ export interface Props<T> {
transformers?: Transformer[];
}

export const DSVImport = <T extends { [key: string]: string }>(props: PropsWithChildren<Props<T>>) => {
export const DSVImport = <T extends GenericColumnType>(props: PropsWithChildren<Props<T>>) => {
const DSVImportContext = getDSVImportContext<T>();
const initialValues: State<T> = { columns: props.columns, transformers: props.transformers };
const [state, dispatch] = useReducer(createReducer<T>(), initialValues);
Expand Down
3 changes: 2 additions & 1 deletion src/features/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { State, emptyState } from '../models/state';
import { createContext, Dispatch, useContext } from 'react';
import { Actions } from '../models/actions';
import { GenericColumnType } from '../models/column';

export const reducer = <T>(state: State<T>, action: Actions<T>) => {
switch (action.type) {
Expand Down Expand Up @@ -34,4 +35,4 @@ export const getDSVImportContext = <T>() => {
}
return contextSingleton as React.Context<[State<T>, Dispatch<Actions<T>>]>;
};
export const useDSVImport = <T = { [key: string]: string }>() => useContext(getDSVImportContext<T>());
export const useDSVImport = <T = GenericColumnType>() => useContext(getDSVImportContext<T>());
10 changes: 6 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { PropsWithChildren } from 'react';
import { DSVImport as Import, Props } from './DSVImport';
import { GenericColumnType } from './models/column';
import { TextareaInput } from './components/inputs/TextareaInput';
import { TablePreview } from './components/previews/TablePreview';
import { DSVImport as Import, Props } from './DSVImport';
import { PropsWithChildren } from 'react';

export function DSVImport<T extends { [key: string]: string }>(props: PropsWithChildren<Props<T>>) {
export function DSVImport<T extends GenericColumnType>(props: PropsWithChildren<Props<T>>) {
return Import<T>(props);
}

DSVImport.TextareaInput = TextareaInput;
DSVImport.TablePreview = TablePreview;

export { ColumnType } from './models/column';
export { ColumnType, GenericColumnType } from './models/column';
export { useDSVImport } from './features/context';
export { Rule } from './models/rule';
export { Transformer } from './models/transformer';
export { ValidationError } from './models/validation';
1 change: 1 addition & 0 deletions src/models/column.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Rule } from './rule';
import { Transformer } from './transformer';

export type GenericColumnType = { [key: string]: string };
export type ColumnType<T> = { key: keyof T; label: string; rules?: Rule[]; transformers?: Transformer[] };
4 changes: 2 additions & 2 deletions src/models/state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ColumnType } from './column';
import { ColumnType, GenericColumnType } from './column';
import { ValidationError } from './validation';
import { Transformer } from './transformer';

Expand All @@ -10,6 +10,6 @@ export interface State<T> {
columns: ColumnType<T>[];
}

export const emptyState: State<{ [key: string]: string }> = {
export const emptyState: State<GenericColumnType> = {
columns: []
};
76 changes: 38 additions & 38 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2135,9 +2135,9 @@
loader-utils "^1.2.3"

"@testing-library/dom@^7.2.2":
version "7.5.7"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.5.7.tgz#c4bf683a65083d4a78644588cfa4ad684c113fc7"
integrity sha512-835MiwAxQE7xjSrhpeJbv41UQRmsPJQ0tGfzWiJMdZj2LBbdG5cT8Z44Viv11/XucCmJHr/v8q7VpZnuSimscg==
version "7.5.8"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.5.8.tgz#35eb20f1cfd90629a09728954fd916ea142e5de5"
integrity sha512-aEK4GDeIk3sHuuF8NNvZrmZg5xfF7llvdlVfjely/fPg/GE4yLa0cVZEBWpS6oVUBk2tEXjwTDPFnMOe/M0GTQ==
dependencies:
"@babel/runtime" "^7.9.6"
aria-query "^4.0.2"
Expand Down Expand Up @@ -2485,41 +2485,41 @@
dependencies:
"@types/yargs-parser" "*"

"@typescript-eslint/eslint-plugin@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.0.0.tgz#02f8ec6b5ce814bda80dfc22463f108bed1f699b"
integrity sha512-lcZ0M6jD4cqGccYOERKdMtg+VWpoq3NSnWVxpc/AwAy0zhkUYVioOUZmfNqiNH8/eBNGhCn6HXd6mKIGRgNc1Q==
"@typescript-eslint/eslint-plugin@^3.0.1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.0.1.tgz#368fe7d4c3d927e9fd27b7ba150b4b7e83ddfabe"
integrity sha512-RxGldRQD3hgOK2xtBfNfA5MMV3rn5gVChe+MIf14hKm51jO2urqF64xOyVrGtzThkrd4rS1Kihqx2nkSxkXHvA==
dependencies:
"@typescript-eslint/experimental-utils" "3.0.0"
"@typescript-eslint/experimental-utils" "3.0.1"
functional-red-black-tree "^1.0.1"
regexpp "^3.0.0"
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/[email protected].0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.0.0.tgz#1ddf53eeb61ac8eaa9a77072722790ac4f641c03"
integrity sha512-BN0vmr9N79M9s2ctITtChRuP1+Dls0x/wlg0RXW1yQ7WJKPurg6X3Xirv61J2sjPif4F8SLsFMs5Nzte0WYoTQ==
"@typescript-eslint/[email protected].1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.0.1.tgz#e2721c970068fabd6621709234809c98cd3343ad"
integrity sha512-GdwOVz80MOWxbc/br1DC30eeqlxfpVzexHgHtf3L0hcbOu1xAs1wSCNcaBTLMOMZbh1gj/cKZt0eB207FxWfFA==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/typescript-estree" "3.0.0"
"@typescript-eslint/typescript-estree" "3.0.1"
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"

"@typescript-eslint/parser@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.0.0.tgz#fe9fdf18a1155c02c04220c14506a320cb6c6944"
integrity sha512-8RRCA9KLxoFNO0mQlrLZA0reGPd/MsobxZS/yPFj+0/XgMdS8+mO8mF3BDj2ZYQj03rkayhSJtF1HAohQ3iylw==
"@typescript-eslint/parser@^3.0.1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.0.1.tgz#f5163e3a789422f5c62f4daf822bfa03b7e4472d"
integrity sha512-Pn2tDmOc4Ri93VQnT70W0pqQr6i/pEZqIPXfWXm4RuiIprL0t6SG13ViVXHgfScknL2Fm2G4IqXhUzxSRCWXCw==
dependencies:
"@types/eslint-visitor-keys" "^1.0.0"
"@typescript-eslint/experimental-utils" "3.0.0"
"@typescript-eslint/typescript-estree" "3.0.0"
"@typescript-eslint/experimental-utils" "3.0.1"
"@typescript-eslint/typescript-estree" "3.0.1"
eslint-visitor-keys "^1.1.0"

"@typescript-eslint/[email protected].0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.0.0.tgz#fa40e1b76ccff880130be054d9c398e96004bf42"
integrity sha512-nevQvHyNghsfLrrByzVIH4ZG3NROgJ8LZlfh3ddwPPH4CH7W4GAiSx5qu+xHuX5pWsq6q/eqMc1io840ZhAnUg==
"@typescript-eslint/[email protected].1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.0.1.tgz#8c0cfb7cda64bd6f54185a7b7d1923d25d36b2a8"
integrity sha512-FrbMdgVCeIGHKaP9OYTttFTlF8Ds7AkjMca2GzYCE7pVch10PAJc1mmAFt+DfQPgu/2TrLAprg2vI0PK/WTdcg==
dependencies:
debug "^4.1.1"
eslint-visitor-keys "^1.1.0"
Expand Down Expand Up @@ -3933,9 +3933,9 @@ can-use-dom@^0.1.0:
integrity sha1-IsxKNKCrxDlQ9CxkEQJKP2NmtFo=

caniuse-lite@^1.0.30000989, caniuse-lite@^1.0.30001043, caniuse-lite@^1.0.30001061:
version "1.0.30001065"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001065.tgz#e8d7fef61cdfd8a7107493ad6bf551a4eb59c68f"
integrity sha512-DDxCLgJ266YnAHQv0jS1wdOaihRFF52Zgmlag39sQJVy2H46oROpJp4hITstqhdB8qnHSrKNoAEkQA9L/oYF9A==
version "1.0.30001066"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001066.tgz#0a8a58a10108f2b9bf38e7b65c237b12fd9c5f04"
integrity sha512-Gfj/WAastBtfxLws0RCh2sDbTK/8rJuSeZMecrSkNGYxPcv7EzblmDGfWQCFEQcSqYE2BRgQiJh8HOD07N5hIw==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -4502,9 +4502,9 @@ [email protected], cross-spawn@^6.0.0:
which "^1.2.9"

cross-spawn@^7.0.0, cross-spawn@^7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.2.tgz#d0d7dcfa74e89115c7619f4f721a94e1fdb716d6"
integrity sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw==
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
dependencies:
path-key "^3.1.0"
shebang-command "^2.0.0"
Expand Down Expand Up @@ -5022,9 +5022,9 @@ ejs@^2.7.4:
integrity sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA==

electron-to-chromium@^1.3.247, electron-to-chromium@^1.3.413:
version "1.3.451"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.451.tgz#0c075af3e2f06d706670bde0279432802ca8c83f"
integrity sha512-2fvco0F2bBIgqzO8GRP0Jt/91pdrf9KfZ5FsmkYkjERmIJG585cFeFZV4+CO6oTmU3HmCTgfcZuEa7kW8VUh3A==
version "1.3.452"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.452.tgz#ef6877702722471aa044a2429336cd450629934d"
integrity sha512-IdbjgCEqDvcU/1kUQa6C49I2NZOY3SBmU9Eus7mdFdJJBqn0Lg1Epfi/T4nqVcxTNBEGhcjwMhY1EysMBsXZrw==

element-resize-detector@^1.2.1:
version "1.2.1"
Expand Down Expand Up @@ -5812,9 +5812,9 @@ [email protected]:
worker-rpc "^0.1.0"

fork-ts-checker-webpack-plugin@^4.1.0:
version "4.1.4"
resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-4.1.4.tgz#f0dc3ece19ec5b792d7b8ecd2a7f43509a5285ce"
integrity sha512-R0nTlZSyV0uCCzYe1kgR7Ve8mXyDvMm1pJwUFb6zzRVF5rTNb24G6gn2DFQy+W5aJYp2eq8aexpCOO+1SCyCSA==
version "4.1.5"
resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-4.1.5.tgz#780d52c65183742d8c885fff42a9ec9ea7006672"
integrity sha512-nuD4IDqoOfkEIlS6shhjLGaLBDSNyVJulAlr5lFbPe0saGqlsTo+/HmhtIrs/cNLFtmaudL10byivhxr+Qhh4w==
dependencies:
"@babel/code-frame" "^7.5.5"
chalk "^2.4.1"
Expand Down Expand Up @@ -9216,9 +9216,9 @@ postcss-value-parser@^4.0.0, postcss-value-parser@^4.0.3, postcss-value-parser@^
integrity sha512-97DXOFbQJhk71ne5/Mt6cOu6yxsSfM0QGQyl0L25Gca4yGWEGJaig7l7gbCX623VqTBNGLRLaVUCnNkcedlRSQ==

postcss@^7.0.0, postcss@^7.0.14, postcss@^7.0.16, postcss@^7.0.26, postcss@^7.0.27, postcss@^7.0.30, postcss@^7.0.5, postcss@^7.0.6:
version "7.0.30"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.30.tgz#cc9378beffe46a02cbc4506a0477d05fcea9a8e2"
integrity sha512-nu/0m+NtIzoubO+xdAlwZl/u5S5vi/y6BCsoL8D+8IxsD3XvBS8X4YEADNIVXKVuQvduiucnRv+vPIqj56EGMQ==
version "7.0.31"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.31.tgz#332af45cb73e26c0ee2614d7c7fb02dfcc2bd6dd"
integrity sha512-a937VDHE1ftkjk+8/7nj/mrjtmkn69xxzJgRETXdAUU+IgOYPQNJF17haGWbeDxSyk++HA14UA98FurvPyBJOA==
dependencies:
chalk "^2.4.2"
source-map "^0.6.1"
Expand Down

0 comments on commit 39660b6

Please sign in to comment.