Vue Connect Tech 2019 - ChoDragon9/posts GitHub Wiki

Composing functionality With the New Vue Apis

https://www.vuemastery.com/conferences/connect-tech-2019/composing-functionality-with-the-new-vue-apis

What is the goal of the composition API?

  • Portable functionality
  • Composable abstractions

The Main Benefits

  • Explicit extraction of logic, including stateful logic
  • Feature based organization vs. Option-based organization

μƒνƒœκ΄€λ¦¬

https://www.vuemastery.com/conferences/connect-tech-2019/managing-state-in-vuejs

What is Vuex?

  • Store Model for State
  • Reduces the paths where data is mutated
  • Introduces more concepts (complexity)

Flow

Vue Components =[Dispatch]=> Actions =[Commit]=> 
Mutations =[Mutate]=> State =[Render]=> Vue Components

Vue μ»΄ν¬λ„ŒνŠΈμ˜ μƒνƒœκ΄€λ¦¬λŠ” Vuexλ₯Ό ν†΅ν•΄μ„œ ν•œλ‹€.

μ»΄ν¬λ„ŒνŠΈ λ””μžμΈ νŒ¨ν„΄

https://www.vuemastery.com/conferences/connect-tech-2019/fundamental-component-design-patterns/

[Props-based solution] Problems

  • New requirements increase complexity
  • Multiple responsibilities
  • Lots of conditionals in the template
  • Low flexibility
  • Hard to maintain

Use slots for:

  • Content distribution (like layouts)
  • Creating larger components by combining smaller components
  • Default content in Multi-page Apps
  • Providing a wrapper for other components
  • Replace default component fragments

Use scoped slots for:

  • Applying custom formatting/template to fragments of a component
  • Creating wrapper components
  • Exposing its own data and methods to child components

Slots(Composition) > Props(Configuration)

  • Slots: With composition, you're less restricted by what you are building at first.
  • Props: With configuration, you have to document everything and new requirements means new configuration

Container (What is it doing?)

Examples: UserProfile, Product, TheShoppingCart, Login

  • Application logic
  • Application state
  • Use Vuex
  • Usually Router views

Presentational (How does it look?)

Examples: AppButton, AppModal, TheSidebar, ProductCard

  • Application UI and styles
  • UI-related state only
  • Receive data from props
  • Emit events to containers
  • Reusable and composable
  • Not relying on global state

Propsλ₯Ό ν†΅ν•œ μ»΄ν¬λ„ŒνŠΈ λ””μžμΈμ€ λ³΅μž‘ν•˜λ‹€. Slot을 톡해 ν•΄κ²°ν•  수 μžˆλ‹€.

Scoped slots을 μ‚¬μš©ν•˜λ©΄ μžμ‹ μ»΄ν¬λ„ŒνŠΈμ— μ „λ‹¬ν•œ μƒνƒœλ₯Ό λΆ€λͺ¨μ—μ„œ μ‚¬μš©ν•  μˆ˜μžˆλ‹€. λ°˜λ³΅μ— λŒ€ν•œ 처리λ₯Ό μžμ‹μ—μ„œ ν•˜κ³  λΆ€λͺ¨λŠ” μ–΄λ–€ 것을 ν‘œμ‹œν• μ§€ 선택할 수 μžˆλ‹€.

λ§ˆμ§€λ§‰μž₯μ―€μ—λŠ” μ–Έμ œ λ¦¬νŒ©ν† λ§μ΄ ν•„μš”ν•œκ°€μ— λŒ€ν•œ λ‚΄μš©λ„ 닀룬닀.