1seok2

refactor: grap functions

1 -build/
2 -gulpfile.js
3 -gulp.js
4 -webpack.config.js
...@@ -11,7 +11,7 @@ import Body from "./views/body"; ...@@ -11,7 +11,7 @@ import Body from "./views/body";
11 import Footer from "./views/footer"; 11 import Footer from "./views/footer";
12 import { getState } from "@src/store/state"; 12 import { getState } from "@src/store/state";
13 import "./assets/style/App.scss"; 13 import "./assets/style/App.scss";
14 -import { getElement } from "./components/functions"; 14 +import { getElement } from "./shared/functions";
15 15
16 function App(pathname: string): string { 16 function App(pathname: string): string {
17 /* id 없을 시 id 입력으로 redirect */ 17 /* id 없을 시 id 입력으로 redirect */
......
1 -/**
2 - * @author : wonseog
3 - * @date : 2021/03/10
4 - * @description : 버튼 이벤트, Route 이벤트 등록 모음
5 - **/
6 -
7 -export default function addEventWithElementByType(
8 - element: HTMLElement,
9 - eventType: string,
10 - handler: (e: Event) => void
11 -) {
12 - element.addEventListener(eventType, handler);
13 -}
1 -export const formatNumber = (number : number) : string => {
2 - if(`${number}`.length > 6) {
3 - return `${Math.floor(number / 1000000)}m`
4 - }
5 - else if(`${number}`.length > 3) {
6 - return `${Math.floor(number / 1000)}k`
7 - } else {
8 - return `${number}`;
9 - }
10 -}
...\ No newline at end of file ...\ No newline at end of file
1 -export const togglePageLoader = (type: boolean): void => {
2 - const $loader = document.querySelector(".page-loader") as HTMLDivElement;
3 -
4 - if (type === true) {
5 - $loader.style.display = "block";
6 - $loader.style.zIndex = "1";
7 - } else {
8 - $loader.style.display = "none";
9 - $loader.style.zIndex = "-1";
10 - }
11 -};
12 -
13 -export default function createLoaderElement() {
14 - const $div = document.createElement("div");
15 - $div.className = "page-loader";
16 - document.body.appendChild($div);
17 -}
1 +export const updateHtml = (
2 + type: string = "literal",
3 + tag: string | HTMLElement = "<div></div>",
4 + target: string = "app"
5 +) => {
6 + const $target: null | HTMLElement = document.querySelector(target);
7 +
8 + $target && ($target.innerHTML = `${tag}`);
9 +};
1 -export const updateHtml = (
2 - type : string = 'literal',
3 - tag : string | HTMLElement = '<div></div>',
4 - target : string = 'app'
5 -) => {
6 - const $target : null | HTMLElement = document.querySelector(target);
7 -
8 - $target && ($target.innerHTML = `${tag}`)
9 -}
...\ No newline at end of file ...\ No newline at end of file
...@@ -7,13 +7,10 @@ ...@@ -7,13 +7,10 @@
7 import "./assets/style/PageTransition.scss"; 7 import "./assets/style/PageTransition.scss";
8 import "./assets/style/PageLoader.scss"; 8 import "./assets/style/PageLoader.scss";
9 9
10 -import animatePage from "@src/components/page.transition";
11 -import createLoaderElement from "@src/components/page.loader";
12 -import addEventWithElementByType from "@src/components/add.event";
13 -import { getPathname } from "@src/components/functions";
14 -import { linkEvent } from "@src/components/event.list";
15 -
16 import renderApp from "./App"; 10 import renderApp from "./App";
11 +import { animatePage, createLoaderElement } from "./shared/page";
12 +import { getPathname } from "./shared/functions";
13 +import { addEventWithElementByType, linkEvent } from "./shared/event";
17 14
18 window.addEventListener("DOMContentLoaded", () => { 15 window.addEventListener("DOMContentLoaded", () => {
19 createLoaderElement(); 16 createLoaderElement();
......
1 -import { randomTransition } from "@src/components/page.transition";
2 import renderApp from "@src/App"; 1 import renderApp from "@src/App";
3 import { 2 import {
4 getElement, 3 getElement,
...@@ -6,6 +5,7 @@ import { ...@@ -6,6 +5,7 @@ import {
6 warningEmptyId, 5 warningEmptyId,
7 fetchByURL, 6 fetchByURL,
8 } from "./functions"; 7 } from "./functions";
8 +import { randomTransition } from "./page";
9 9
10 export function linkEvent(e: Event) { 10 export function linkEvent(e: Event) {
11 e.preventDefault(); 11 e.preventDefault();
...@@ -33,3 +33,7 @@ export async function handleFetchById(url: string, cssSelector: string) { ...@@ -33,3 +33,7 @@ export async function handleFetchById(url: string, cssSelector: string) {
33 33
34 await fetchByURL(url + insta_id); 34 await fetchByURL(url + insta_id);
35 } 35 }
36 +
37 +export const addEventWithElementByType = (element, eventType, handler) => {
38 + element.addEventListener(eventType, handler);
39 +};
......
1 import { BASE_URL } from "@src/config/url"; 1 import { BASE_URL } from "@src/config/url";
2 import { setState } from "@src/store/state"; 2 import { setState } from "@src/store/state";
3 -import { togglePageLoader } from "@src/components/page.loader";
4 -import { randomTransition } from "@src/components/page.transition";
5 import renderApp from "@src/App"; 3 import renderApp from "@src/App";
4 +import { randomTransition, togglePageLoader } from "./page";
6 5
7 export function formatNumber(number: number): string { 6 export function formatNumber(number: number): string {
8 if (`${number}`.length > 6) { 7 if (`${number}`.length > 6) {
......
...@@ -43,10 +43,28 @@ export const randomTransition = () => { ...@@ -43,10 +43,28 @@ export const randomTransition = () => {
43 turnOnAndOff(randomIndex); 43 turnOnAndOff(randomIndex);
44 }; 44 };
45 45
46 -export default function animatePage() { 46 +export function animatePage() {
47 const $div = document.createElement("div"); 47 const $div = document.createElement("div");
48 $div.className = "page-transition"; 48 $div.className = "page-transition";
49 document.body.appendChild($div); 49 document.body.appendChild($div);
50 50
51 initialTrantition(); 51 initialTrantition();
52 } 52 }
53 +
54 +export const togglePageLoader = (type: boolean): void => {
55 + const $loader = document.querySelector(".page-loader") as HTMLDivElement;
56 +
57 + if (type === true) {
58 + $loader.style.display = "block";
59 + $loader.style.zIndex = "1";
60 + } else {
61 + $loader.style.display = "none";
62 + $loader.style.zIndex = "-1";
63 + }
64 +};
65 +
66 +export function createLoaderElement() {
67 + const $div = document.createElement("div");
68 + $div.className = "page-loader";
69 + document.body.appendChild($div);
70 +}
......
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
7 7
8 import Title from "@src/components/Title"; 8 import Title from "@src/components/Title";
9 import "@src/assets/style/Intro.scss"; 9 import "@src/assets/style/Intro.scss";
10 -import addEventWithElementByType from "@src/components/add.event"; 10 +import { addEventWithElementByType, handleFetchById } from "@src/shared/event";
11 -import { handleFetchById } from "@src/components/event.list";
12 11
13 const Intro = (): string => { 12 const Intro = (): string => {
14 addEventWithElementByType(document.body, "click", function (e: Event) { 13 addEventWithElementByType(document.body, "click", function (e: Event) {
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
6 * 다른 메뉴 보기 6 * 다른 메뉴 보기
7 **/ 7 **/
8 import "@src/assets/style/Main.scss"; 8 import "@src/assets/style/Main.scss";
9 +import { formatNumber } from "@src/shared/functions";
9 10
10 import { getState } from "@src/store/state"; 11 import { getState } from "@src/store/state";
11 -import { formatNumber } from "@src/components/functions";
12 12
13 const Main = () => { 13 const Main = () => {
14 const state = getState(); 14 const state = getState();
......
...@@ -7,10 +7,9 @@ ...@@ -7,10 +7,9 @@
7 import "@src/assets/style/Header.scss"; 7 import "@src/assets/style/Header.scss";
8 8
9 import renderApp from "@src/App"; 9 import renderApp from "@src/App";
10 -import addEventWithElementByType from "@src/components/add.event";
11 -import { handleFetchById } from "@src/components/event.list";
12 10
13 import { getState } from "@src/store/state"; 11 import { getState } from "@src/store/state";
12 +import { addEventWithElementByType, handleFetchById } from "@src/shared/event";
14 13
15 const Header = (): string => { 14 const Header = (): string => {
16 const { insta_id } = getState(); 15 const { insta_id } = getState();
......
...@@ -6,18 +6,14 @@ ...@@ -6,18 +6,14 @@
6 "outDir": "build", 6 "outDir": "build",
7 "target": "es6", 7 "target": "es6",
8 "module": "commonjs", 8 "module": "commonjs",
9 - "strict": true, 9 + "strict": false,
10 "removeComments": true, 10 "removeComments": true,
11 "esModuleInterop": true, 11 "esModuleInterop": true,
12 "baseUrl": ".", 12 "baseUrl": ".",
13 "paths": { 13 "paths": {
14 - "@src/*": [ 14 + "@src/*": ["src/*"]
15 - "src/*"
16 - ]
17 } 15 }
18 }, 16 },
19 - "include": [ 17 + "include": ["src/**/*.ts"],
20 - "src/**/*.ts"
21 - ],
22 "exclude": ["node_modules"] 18 "exclude": ["node_modules"]
23 } 19 }
......