From 3327cbc7fdc8fd2d9c90a902d764a7f62b1d5288 Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Thu, 24 Mar 2022 23:33:14 +0300 Subject: [PATCH 01/15] feat(ts): compose types --- .../template/src/shared/lib/fp/compose.js | 10 ---------- .../template/src/shared/lib/fp/compose.ts | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) delete mode 100644 typescript/template/src/shared/lib/fp/compose.js create mode 100644 typescript/template/src/shared/lib/fp/compose.ts diff --git a/typescript/template/src/shared/lib/fp/compose.js b/typescript/template/src/shared/lib/fp/compose.js deleted file mode 100644 index 7d23e4f..0000000 --- a/typescript/template/src/shared/lib/fp/compose.js +++ /dev/null @@ -1,10 +0,0 @@ -export function compose(...funcs) { - if (funcs.length === 0) return; - if (funcs.length === 1) return funcs[0]; - - return funcs.reduce( - (a, b) => - (...args) => - a(b(...args)) - ); -} diff --git a/typescript/template/src/shared/lib/fp/compose.ts b/typescript/template/src/shared/lib/fp/compose.ts new file mode 100644 index 0000000..a5bf606 --- /dev/null +++ b/typescript/template/src/shared/lib/fp/compose.ts @@ -0,0 +1,18 @@ +function compose (): (arg: A) => A +function compose (fn: (arg: A) => B): (arg: A) => B +function compose (fn0: (arg: B) => C, fn1: (arg: A) => B): (arg: A) => C +function compose (fn0: (arg: C) => D, fn1: (arg: B) => C, fn2: (arg: A) => B): (arg: A) => D +function compose (fn0: (arg: D) => E, fn1: (arg: C) => D, fn2: (arg: B) => C, fn3: (arg: A) => B): (arg: A) => E +function compose (fn0: (arg: E) => F, fn1: (arg: D) => E, fn2: (arg: C) => D, fn3: (arg: B) => C, fn4: (arg: A) => B): (arg: A) => F +function compose (fn0: (arg: F) => G, fn1: (arg: E) => F, fn2: (arg: D) => E, fn3: (arg: C) => D, fn4: (arg: B) => C, fn5: (arg: A) => B): (arg: A) => G +function compose (fn0: (arg: G) => H, fn1: (arg: F) => G, fn2: (arg: E) => F, fn3: (arg: D) => E, fn4: (arg: C) => D, fn5: (arg: B) => C, fn6: (arg: A) => B): (arg: A) => H +function compose (fn0: (arg: H) => I, fn1: (arg: G) => H, fn2: (arg: F) => G, fn3: (arg: E) => F, fn4: (arg: D) => E, fn5: (arg: C) => D, fn6: (arg: B) => C, fn7: (arg: A) => B): (arg: A) => I + +function compose (...fns: any[]): any { + return (initial: any) => fns.reduceRight( + (arg, fn) => fn(arg), + initial + ) +} + +export { compose } \ No newline at end of file From f6f380e3884c53127bdf5634842a4326a65da973 Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Thu, 24 Mar 2022 23:34:15 +0300 Subject: [PATCH 02/15] feat(ts): loader types --- typescript/template/src/shared/ui/loader/loader.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/typescript/template/src/shared/ui/loader/loader.tsx b/typescript/template/src/shared/ui/loader/loader.tsx index abf5760..2b597e8 100644 --- a/typescript/template/src/shared/ui/loader/loader.tsx +++ b/typescript/template/src/shared/ui/loader/loader.tsx @@ -1,3 +1,5 @@ -export const Loader = () => { +import { FC } from 'react'; + +export const Loader: FC = () => { return
loading...
; }; From 7e38bd070acd0c46da89189269df32ab20226af3 Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Mon, 28 Mar 2022 23:11:58 +0300 Subject: [PATCH 03/15] chore(ts): compose types --- .../template/src/shared/lib/fp/compose.ts | 58 ++++++++++++++----- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/typescript/template/src/shared/lib/fp/compose.ts b/typescript/template/src/shared/lib/fp/compose.ts index a5bf606..80e56ba 100644 --- a/typescript/template/src/shared/lib/fp/compose.ts +++ b/typescript/template/src/shared/lib/fp/compose.ts @@ -1,18 +1,44 @@ -function compose
(): (arg: A) => A -function compose (fn: (arg: A) => B): (arg: A) => B -function compose (fn0: (arg: B) => C, fn1: (arg: A) => B): (arg: A) => C -function compose (fn0: (arg: C) => D, fn1: (arg: B) => C, fn2: (arg: A) => B): (arg: A) => D -function compose (fn0: (arg: D) => E, fn1: (arg: C) => D, fn2: (arg: B) => C, fn3: (arg: A) => B): (arg: A) => E -function compose (fn0: (arg: E) => F, fn1: (arg: D) => E, fn2: (arg: C) => D, fn3: (arg: B) => C, fn4: (arg: A) => B): (arg: A) => F -function compose (fn0: (arg: F) => G, fn1: (arg: E) => F, fn2: (arg: D) => E, fn3: (arg: C) => D, fn4: (arg: B) => C, fn5: (arg: A) => B): (arg: A) => G -function compose (fn0: (arg: G) => H, fn1: (arg: F) => G, fn2: (arg: E) => F, fn3: (arg: D) => E, fn4: (arg: C) => D, fn5: (arg: B) => C, fn6: (arg: A) => B): (arg: A) => H -function compose (fn0: (arg: H) => I, fn1: (arg: G) => H, fn2: (arg: F) => G, fn3: (arg: E) => F, fn4: (arg: D) => E, fn5: (arg: C) => D, fn6: (arg: B) => C, fn7: (arg: A) => B): (arg: A) => I - -function compose (...fns: any[]): any { - return (initial: any) => fns.reduceRight( - (arg, fn) => fn(arg), - initial +type Func = (...a: T) => R + +export default function compose(): (a: R) => R +export default function compose(f: F): F +export default function compose( + f1: (a: A) => R, + f2: Func +): Func + +export default function compose( + f1: (b: B) => R, + f2: (a: A) => B, + f3: Func +): Func + +export default function compose( + f1: (c: C) => R, + f2: (b: B) => C, + f3: (a: A) => B, + f4: Func +): Func + +export default function compose( + f1: (a: any) => R, + ...funcs: Function[] +): (...args: any[]) => R + +export default function compose(...funcs: Function[]): (...args: any[]) => R + +export default function compose(...funcs: Function[]) { + if (funcs.length === 0) { + return (arg: T) => arg + } + + if (funcs.length === 1) { + return funcs[0] + } + + return funcs.reduce( + (a, b) => + (...args: any) => + a(b(...args)) ) } - -export { compose } \ No newline at end of file From c327ba455d157cedc487278678a7605afe0ff4b1 Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Tue, 29 Mar 2022 01:15:56 +0300 Subject: [PATCH 04/15] chore(ts): remove redundant app --- typescript/template/src/app/App.jsx | 4 ---- typescript/template/src/app/App.tsx | 5 ----- 2 files changed, 9 deletions(-) delete mode 100644 typescript/template/src/app/App.jsx delete mode 100644 typescript/template/src/app/App.tsx diff --git a/typescript/template/src/app/App.jsx b/typescript/template/src/app/App.jsx deleted file mode 100644 index 56b48fe..0000000 --- a/typescript/template/src/app/App.jsx +++ /dev/null @@ -1,4 +0,0 @@ -import { PublicRoutes } from 'pages/router'; -import { withProviders } from './providers'; - -export const App = withProviders(() => ); diff --git a/typescript/template/src/app/App.tsx b/typescript/template/src/app/App.tsx deleted file mode 100644 index cef9398..0000000 --- a/typescript/template/src/app/App.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import { FC } from 'react'; -import { PublicRoutes } from 'pages/router'; -import { withProviders } from './providers'; - -export const App: FC = withProviders(() => ); From a240685733755006d99bc1598cbcc424c2b3bc32 Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Tue, 29 Mar 2022 01:16:15 +0300 Subject: [PATCH 05/15] chore(ts): withRouter types --- typescript/template/src/app/providers/with-router.jsx | 11 ----------- typescript/template/src/app/providers/with-router.tsx | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 typescript/template/src/app/providers/with-router.jsx create mode 100644 typescript/template/src/app/providers/with-router.tsx diff --git a/typescript/template/src/app/providers/with-router.jsx b/typescript/template/src/app/providers/with-router.jsx deleted file mode 100644 index de81659..0000000 --- a/typescript/template/src/app/providers/with-router.jsx +++ /dev/null @@ -1,11 +0,0 @@ -import { Suspense } from 'react'; -import { BrowserRouter } from 'react-router-dom'; -import { Loader } from 'shared/ui/loader'; - -export const withRouter = (component) => () => { - return ( - - }>{component()} - - ); -}; diff --git a/typescript/template/src/app/providers/with-router.tsx b/typescript/template/src/app/providers/with-router.tsx new file mode 100644 index 0000000..18569d4 --- /dev/null +++ b/typescript/template/src/app/providers/with-router.tsx @@ -0,0 +1,11 @@ +import React, { Suspense } from 'react'; +import { BrowserRouter } from 'react-router-dom'; +import { Loader } from 'shared/ui/loader'; + +export const withRouter = (Component: React.ComponentType) => (props: T) => ( + + }> + + + +); \ No newline at end of file From 05489865d8d88468ca0b5003a90fca2014fe23b6 Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Tue, 29 Mar 2022 01:16:47 +0300 Subject: [PATCH 06/15] chore(ts): counter with useCounter model --- typescript/template/src/pages/counter/ui.tsx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/typescript/template/src/pages/counter/ui.tsx b/typescript/template/src/pages/counter/ui.tsx index 87fb2ff..40aaca6 100644 --- a/typescript/template/src/pages/counter/ui.tsx +++ b/typescript/template/src/pages/counter/ui.tsx @@ -1,21 +1,19 @@ -import { useState } from 'react'; +import React from 'react'; import { Button } from 'shared/ui/button'; -import styles from './ui.module.css'; +import { useCounter } from './model'; +import styles from './styles.module.css'; -export const CounterPage = () => { - const [counter, setCounter] = useState(0); +export const CounterPage: React.FC = () => { + const { counter, increment, decrement } = useCounter(0); return (

Counter {counter}

- - +
); }; From 722157ddde858acea8828776d3ee3c80b19012cc Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Tue, 29 Mar 2022 01:17:09 +0300 Subject: [PATCH 07/15] fix(base): remove redundant ts --- base/template.json | 1 - 1 file changed, 1 deletion(-) diff --git a/base/template.json b/base/template.json index 2f6179f..d9f3810 100644 --- a/base/template.json +++ b/base/template.json @@ -9,7 +9,6 @@ "react": "^17.0.2", "react-dom": "^17.0.2", "react-scripts": "4.0.3", - "typescript": "^4.5.2", "web-vitals": "^1.1.2" } } From 55b757df24b3473488327b4cdad399dcf50d370f Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Tue, 29 Mar 2022 01:17:59 +0300 Subject: [PATCH 08/15] chore(ts): to same naming --- .../src/pages/counter/{ui.module.css => styles.module.css} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename typescript/template/src/pages/counter/{ui.module.css => styles.module.css} (100%) diff --git a/typescript/template/src/pages/counter/ui.module.css b/typescript/template/src/pages/counter/styles.module.css similarity index 100% rename from typescript/template/src/pages/counter/ui.module.css rename to typescript/template/src/pages/counter/styles.module.css From 178bc052f1575ca3d974f20942b0ce98b6e357b5 Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Tue, 29 Mar 2022 01:20:33 +0300 Subject: [PATCH 09/15] chore(ts): simplify publicRoutes --- typescript/template/src/pages/router/public-routes.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/typescript/template/src/pages/router/public-routes.tsx b/typescript/template/src/pages/router/public-routes.tsx index 428d67a..7fe3e98 100644 --- a/typescript/template/src/pages/router/public-routes.tsx +++ b/typescript/template/src/pages/router/public-routes.tsx @@ -1,9 +1,5 @@ -import { FC } from 'react'; +import React from 'react'; import { useRoutes } from 'react-router-dom'; import { publicRoutes } from './routes'; -export const PublicRoutes: FC = () => { - const routes = useRoutes(publicRoutes); - - return routes; -}; +export const PublicRoutes: React.FC = () => useRoutes(publicRoutes) From 1b94fc2887eb4d97184ea983f2b72ebc991edc2d Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Tue, 29 Mar 2022 01:20:52 +0300 Subject: [PATCH 10/15] fix(ts): wrong package.json path --- typescript/{template => }/package.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename typescript/{template => }/package.json (100%) diff --git a/typescript/template/package.json b/typescript/package.json similarity index 100% rename from typescript/template/package.json rename to typescript/package.json From b84be5ef2113eb62439a33587c0f7cae78bf08ab Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Tue, 29 Mar 2022 01:21:19 +0300 Subject: [PATCH 11/15] chore(ts): loader --- typescript/template/src/shared/ui/loader/index.tsx | 5 +++++ typescript/template/src/shared/ui/loader/loader.tsx | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 typescript/template/src/shared/ui/loader/index.tsx delete mode 100644 typescript/template/src/shared/ui/loader/loader.tsx diff --git a/typescript/template/src/shared/ui/loader/index.tsx b/typescript/template/src/shared/ui/loader/index.tsx new file mode 100644 index 0000000..12adaf9 --- /dev/null +++ b/typescript/template/src/shared/ui/loader/index.tsx @@ -0,0 +1,5 @@ +import React from 'react'; + +export const Loader: React.FC = () => ( +
loading...
+); \ No newline at end of file diff --git a/typescript/template/src/shared/ui/loader/loader.tsx b/typescript/template/src/shared/ui/loader/loader.tsx deleted file mode 100644 index 2b597e8..0000000 --- a/typescript/template/src/shared/ui/loader/loader.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import { FC } from 'react'; - -export const Loader: FC = () => { - return
loading...
; -}; From d2b916fcf0168bf15b336b2ad03dfc7eac6ba49e Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Tue, 29 Mar 2022 01:21:22 +0300 Subject: [PATCH 12/15] chore(ts): loader --- typescript/template/src/shared/ui/Loader/index.ts | 1 - 1 file changed, 1 deletion(-) delete mode 100644 typescript/template/src/shared/ui/Loader/index.ts diff --git a/typescript/template/src/shared/ui/Loader/index.ts b/typescript/template/src/shared/ui/Loader/index.ts deleted file mode 100644 index 0223844..0000000 --- a/typescript/template/src/shared/ui/Loader/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { Loader } from './loader'; From 4a76615d771be3418027779402dfdfb7ef1ff8a7 Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Tue, 29 Mar 2022 01:21:33 +0300 Subject: [PATCH 13/15] chore(ts): compose reexport --- typescript/template/src/shared/lib/fp/index.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 typescript/template/src/shared/lib/fp/index.ts diff --git a/typescript/template/src/shared/lib/fp/index.ts b/typescript/template/src/shared/lib/fp/index.ts new file mode 100644 index 0000000..a0fcc00 --- /dev/null +++ b/typescript/template/src/shared/lib/fp/index.ts @@ -0,0 +1 @@ +export { default as compose } from './compose'; From 947c31e49cc004e9825269f8862929f02907b85c Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Tue, 29 Mar 2022 01:22:01 +0300 Subject: [PATCH 14/15] chore(ts): button refinement --- .../template/src/shared/ui/button/button.tsx | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/typescript/template/src/shared/ui/button/button.tsx b/typescript/template/src/shared/ui/button/button.tsx index e1c14e7..a543aef 100644 --- a/typescript/template/src/shared/ui/button/button.tsx +++ b/typescript/template/src/shared/ui/button/button.tsx @@ -1,19 +1,17 @@ -import { FC, MouseEventHandler } from 'react'; +import React from 'react'; import styles from './button.module.css'; interface Props { className?: string; - onClick?: MouseEventHandler; + onClick?: React.MouseEventHandler; } -export const Button: FC = ({ className, children, onClick }) => { - return ( - - ); -}; +export const Button: React.FC = ({ className, children, onClick }) => ( + +); From 85eb3f439c521061f11158c797dc365153d85d87 Mon Sep 17 00:00:00 2001 From: Evgeniy Geraskin Date: Tue, 29 Mar 2022 01:22:18 +0300 Subject: [PATCH 15/15] chore(ts): final refinement --- typescript/template/src/app/index.ts | 1 - typescript/template/src/app/providers/{index.js => index.ts} | 0 typescript/template/src/shared/lib/fp/index.js | 1 - 3 files changed, 2 deletions(-) delete mode 100644 typescript/template/src/app/index.ts rename typescript/template/src/app/providers/{index.js => index.ts} (100%) delete mode 100644 typescript/template/src/shared/lib/fp/index.js diff --git a/typescript/template/src/app/index.ts b/typescript/template/src/app/index.ts deleted file mode 100644 index 36d0fd8..0000000 --- a/typescript/template/src/app/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { App } from './App'; diff --git a/typescript/template/src/app/providers/index.js b/typescript/template/src/app/providers/index.ts similarity index 100% rename from typescript/template/src/app/providers/index.js rename to typescript/template/src/app/providers/index.ts diff --git a/typescript/template/src/shared/lib/fp/index.js b/typescript/template/src/shared/lib/fp/index.js deleted file mode 100644 index f03e6f5..0000000 --- a/typescript/template/src/shared/lib/fp/index.js +++ /dev/null @@ -1 +0,0 @@ -export { compose } from './compose';