์ „์ฒด ๊ธ€

Front-end Developer
Design Pattern

Observer Pattern

๐Ÿ“Œ ๋ชฉ์ฐจ Introduction What is Observer Pattern? Implementation Conclusion Reference ๐Ÿ“Œ Introduction ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” Observer Pattern์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๐Ÿ“Œ What is Observer Pattern? ์˜ต์ €๋ฒ„ ํŒจํ„ด์€ ๊ฐ์ฒด์˜ ์ƒํƒœ ๋ณ€ํ™”๋ฅผ ๊ด€์ฐฐ ํ•˜๋Š” ๊ด€์ฐฐ์ž๋ฅผ ๋“ฑ๋กํ•˜์—ฌ ์ƒํƒœ ๋ณ€ํ™”๊ฐ€ ์žˆ์„๋•Œ noti๋ฅผ ์ฃผ๋Š” ๋””์ž์ธ ํŒจํ„ด์ž…๋‹ˆ๋‹ค. ๐Ÿ“Œ Implementation ๋จผ์ € subjectํด๋ž˜์Šค๋ฅผ ์ •์˜ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. class Subject { constructor() { this.observers = []; return this; } addObserver(observer) { this.observers.push(observe..

Javascript Study

call, apply, bind

๐Ÿ“Œ ๋ชฉ์ฐจ Introduction What is call? What is apply? What is bind? Usage Conclusion Reference ๐Ÿ“Œ Introduction ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ๊ฐ€์žฅ ํ—ท๊ฐˆ๋ฆฌ๋Š” call, apply, bind์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๐Ÿ“Œ What is call? ๋จผ์ € call์„ ์ •์˜ํ•˜๊ธฐ ์ „์— ํ•ด๋‹น ์˜ˆ์ œ๋ฅผ ๋ด์ฃผ์„ธ์š”. const example = (a, b, c) => { console.log(a + b + c); }; example(1, 2, 3); // 6 example.call(null, 1, 2, 3); // 6 example์„ ์‹คํ–‰์‹œํ‚จ ๊ฒƒ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ example.call๋„ ๋˜‘๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ƒ…๋‹ˆ๋‹ค. ๋ˆˆ์น˜๋ฅผ ์ฑ„์‹ ๋ถ„๋„ ์žˆ๊ฒ ์ง€๋งŒ call์˜ ์ฒซ๋ฒˆ ์งธ ์ธ..

Vue BDD

Vue BDD - Cypress Mock Api

๐Ÿ“Œ ๋ชฉ์ฐจ Introduction Cypress api mock ํ•˜๊ธฐ Conclusion Reference ๐Ÿ“Œ Introduction ์•ˆ๋…•ํ•˜์„ธ์š”. BDD๋งˆ์ง€๋ง‰ ์‹œ๊ฐ„์œผ๋กœ ์ด์ œ Cypress์—์„œ api call๋ฅผ mock ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ํ•ด๋‹น ์ฝ”๋“œ๋Š” ์—ฌ๊ธฐ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•ด๋‹น ์˜ˆ์ œ๋Š” jsonplaceholder์—์„œ todo๋ฅผ ํ•˜๋‚˜ ๋ฐ˜ํ™˜ํ•˜๋Š” ์˜ˆ์ œ ์ž…๋‹ˆ๋‹ค. ๐Ÿ“Œ Cypress api mock ํ•˜๊ธฐ API๋ฅผ mock ํ•˜๊ธฐ์ „์— ๋จผ์ € ํ–‰๋™์„ ์ •์˜ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. Todo์˜ ์ œ๋ชฉ์€ 'hello'๋ผ๊ณ  ์“ฐ์—ฌ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Feature: Todo Background: Given I am on the main page Scenario: Todo display Then I can see Todo with..

Vue BDD

Vue BDD - Cypress ์ ์šฉํ•˜๊ธฐ

๐Ÿ“Œ ๋ชฉ์ฐจ Introduction Gherkin ์‚ฌ์šฉ Gherkin + Cypress Vuex store mocking ํ•˜๊ธฐ Conclusion Reference ๐Ÿ“Œ Introduction ์•ˆ๋…•ํ•˜์„ธ์š”! ์˜ค๋Š˜์€ ์ง€๋‚œ ํฌ์ŠคํŒ…์—์„œ ๋‹ค๋ค˜๋˜ Gherkin์„ ์‹ค์ œ๋กœ Cypress์— ์ ์šฉํ•˜๋Š” ํฌ์ŠคํŒ…์ž…๋‹ˆ๋‹ค. ํ•ด๋‹น ์ฝ”๋“œ๋Š” ์—ฌ๊ธฐ์—์„œ ํ™•์ธ ํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๐Ÿšง ํ•ด๋‹น ํฌ์ŠคํŒ…์˜ ์˜ˆ์ œ๋Š” ๊ฐ„๋‹จํ•œ counter ๊ตฌํ˜„์ž…๋‹ˆ๋‹ค. ๐Ÿ“Œ Gherkin ์‚ฌ์šฉ Counter๋Š” ์„ธ๊ฐ€์ง€ ์‹œ๋‚˜๋ฆฌ์˜ค์— ๋Œ€ํ•ด์„œ ์ž‘๋™์ด ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. count์˜ ์‹œ์ž‘ ๊ฐ’์€ 0์ž…๋‹ˆ๋‹ค. ํ”Œ๋Ÿฌ์Šค ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด count๊ฐ€ 1 ์ฆ๊ฐ€ ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ๋งˆ์ด๋„ˆ์Šค ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด count๊ฐ€ 1 ๊ฐ์†Œ ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ์ด์ œ ํ•ด๋‹น ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ Gherkin์œผ๋กœ ์˜ฎ๊ฒจ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. # Counter.featu..

Design Pattern

Module Pattern

๐Ÿ“Œ ๋ชฉ์ฐจ Introduction Module Pattern ์ด๋ž€? Moudle Pattern ๊ตฌํ˜„ Module Pattern์˜ ์žฅ๋‹จ์  Conclusion Reference ๐Ÿ“Œ Introduction ์•ˆ๋…•ํ•˜์„ธ์š”! ์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ module pattern์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.๐ŸŽ‰ Singleton ํŒจํ„ด๊ณผ๋Š” ๋น„์Šทํ•˜์ง€๋งŒ Singleton์ฒ˜๋Ÿผ ํ•˜๋‚˜์˜ instance๋งŒ ๋งŒ๋“œ๋Š”๊ฒƒ์ด ์•„๋‹Œ ๋‹ค์ˆ˜์˜ instance๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด module pattern ์ž…๋‹ˆ๋‹ค! ๐Ÿ“Œ Module Pattern ์ด๋ž€? Module pattern์ด๋ž€ ์ „์ฒด ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ผ๋ถ€๋ฅผ ๋…๋ฆฝ๋œ ์ฝ”๋“œ๋กœ ๋ถ„๋ฆฌํ•˜์—ฌ ๋งŒ๋“œ๋Š” ๊ฒƒ ์ž…๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์—ฌํƒ€ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ฒ˜๋Ÿผ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ์ ‘๊ทผ ์ œํ•œ์ž(public, private,...)๊ฐ€ ์—†๊ธฐ ..

Vue BDD

Vue BDD - Gherkin

๐Ÿ“Œ ๋ชฉ์ฐจ Introduction Gherkin?์ด ๋ญ”๋ฐ? Gherkin ํ‚ค์›Œ๋“œ Good And Bad Gherkin example Conclusion Reference ๐Ÿ“Œ Introduction ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ํฌ์ŠคํŒ…์€ ๋“œ๋””์–ด BDD๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ์ฒซ๊ฑธ์Œ ์ž…๋‹ˆ๋‹ค. ๋ฐ”๋กœ Gherkin์ธ๋ฐ์š”. ๊ทธ๋Ÿผ ์ง€๊ธˆ๋ถ€ํ„ฐ Gherkin์ด ๋ญ”์ง€ ์‚ฌ์šฉ์€ ์–ด๋–ป๊ฒŒ ํ•˜๋Š”์ง€์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๐Ÿ‘ ๐Ÿ“Œ Gherkin?์ด ๋ญ”๋ฐ? Gherkin์ด๋ž€ cucumber์˜ ํ‘œํ˜„ ํ˜•์‹์ž…๋‹ˆ๋‹ค. ์•„๋ž˜ ๊ทธ๋ฆผ์„ ๋ด์ฃผ์„ธ์š”. Gherkin์€ ๋ฐ”๋กœ ์ด๋ ‡๊ฒŒ Given, When, Then์œผ๋กœ ์ •์˜๋ฅผ ํ•ฉ๋‹ˆ๋‹ค. Before Gerkin์„ ๋ณด๋ฉด ๊ธฐํš์ž๋กœ ๋ณด์ด๋Š” ์‚ฌ๋žŒ๊ณผ ๊ฐœ๋ฐœ์ž๋กœ ๋ณด์ด๋Š” ์‚ฌ๋žŒ์ด ์„œ๋กœ ๋Œ€ํ™”๋ฅผ ํ•ฉ๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ์ž์˜ ๋ง์„ ๊ธฐํš์ž๋Š” ์ดํ•ด๋ฅผ ๋ชปํ•˜์ฃ . ํ•˜์ง€๋งŒ Ghe..

Vue BDD

Vue BDD - Setting

๐Ÿ“Œ ๋ชฉ์ฐจ Introduction Setting์„ ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ๊นŒ? Conclusion Reference ๐Ÿ“Œ Introduction ์•ˆ๋…•ํ•˜์„ธ์š” ์ด๋ฒˆ ํฌ์ŠคํŒ…์€ ์ง€๋‚œ๋ฒˆ์— ์•Œ๋ ค๋“œ๋ฆฐ๋Œ€๋กœ BDD๋ฅผ ์„ธํŒ…ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ๋ ค๋“œ๋ฆฌ๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์‹ค์ œ ์ฝ”๋“œ๋Š” ์—ฌ๊ธฐ๋ฅผ ์ฐธ๊ณ ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๐ŸŽ‰ ๐Ÿ“Œ Setting์„ ํ•˜๋Š” ๋ฐฉ๋ฒ• ๋จผ์ € cypress-cucumber-preprocessor๋ฅผ ์„ค์น˜ํ•ด์ฃผ์„ธ์š” npm i -D cypress-cucumber-preprocessor package.json package.json์— ํ•ด๋‹น ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”. "cypress-cucumber-preprocessor": { "nonGlobalStepDefinitions": true, "stepDefinitions": "tests/e2e/specs",..

Design Pattern

Singleton Pattern

๐Ÿ“Œ ๋ชฉ์ฐจ Introduction Singleton ํŒจํ„ด์ด๋ž€? Singleton ํŒจํ„ด ๊ตฌํ˜„ Conclusion Reference ๐Ÿ“Œ Introduction ์•ˆ๋…•ํ•˜์„ธ์š” ์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” design pattern์ค‘ singleton ํŒจํ„ด์— ๋Œ€ํ•ด์„œ ๋ฐฐ์›Œ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค! ๐Ÿ“Œ Singleton ํŒจํ„ด์ด๋ž€? ์ด๋ฆ„์—์„œ single์ด ๋“ค์–ด๊ฐ€๋Š” ๊ฒƒ์œผ๋กœ ์œ ์ถ”ํ•  ์ˆ˜ ์žˆ๋“ฏ์ด ์ „์ฒด ์‹œ์Šคํ…œ์—์„œ์˜ ํ•˜๋‚˜์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์กด์žฌํ•˜๋„๋ก ๋ณด์žฅํ•˜๋Š” ๊ฐ์ฒด ์ƒ์„ฑํŒจํ„ด์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ, ๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด๋„ ๋ชจ๋‘ ์‹ฑ๊ธ€ํ†ค ํŒจํ„ด์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋ชจ๋“  ์†์„ฑ์ด ๋‹ค ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด์žˆ๊ธฐ์— ๋น„๊ณต๊ฐœ๋ฅผ ๋งŒ๋“ค๋•Œ ์ œ๋Œ€๋กœ ๋œ singleton ํŒจํ„ด ์ž…๋‹ˆ๋‹ค. ๐Ÿ“Œ Singleton ํŒจํ„ด ๊ตฌํ˜„ Singleton์€ ๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด + ํด๋กœ์ €๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ๋ด์ฃผ์„ธ์š”. ..

eddie0329
Eddie Sunny's Blog