Redux: μ§€μ—°λœ 파일 μ—…λ‘œλ“œ... 파일 개체λ₯Ό 어디에 λ‘˜ 것인가?

에 λ§Œλ“  2016λ…„ 07μ›” 18일  Β·  3μ½”λ©˜νŠΈ  Β·  좜처: reduxjs/redux

파일 μ—…λ‘œλ“œ μ²˜λ¦¬μ— λŒ€ν•œ μ œμ•ˆμ„ μ°Ύκ³  μžˆμŠ΅λ‹ˆλ‹€. μ‚¬μš©μžκ°€ νŒŒμΌμ„ λŒμ–΄λ‹€ 놓을 수 있고 파일 μ—…λ‘œλ“œκ°€ μ‹œμž‘λ˜κΈ° 전에 κ°€μž…ν•˜λΌλŠ” λ©”μ‹œμ§€κ°€ ν‘œμ‹œλ˜λŠ” λ°©λ¬Έ νŽ˜μ΄μ§€κ°€ μžˆμŠ΅λ‹ˆλ‹€. λ“œλž˜κ·Έν•œ 파일 개체λ₯Ό μ–΄λ”˜κ°€μ— 보관해야 ν•˜μ§€λ§Œ Redux μƒνƒœλŠ” 일반 JS 개체만 보관해야 ν•˜λ―€λ‘œ ν•΄λ‹Ή 파일 개체λ₯Ό 어디에 λ‘˜μ§€ λͺ¨λ₯΄κ² μŠ΅λ‹ˆλ‹€. 일뢀 React μƒνƒœ/μ†Œν’ˆμ— 보관할 수 μžˆμ§€λ§Œ κ²°κ΅­ μ˜¬λ°”λ₯Έ ꡬ성 μš”μ†Œ 등에 μ „λ‹¬λ˜μ—ˆλŠ”μ§€ 확인해야 ν•©λ‹ˆλ‹€.

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

@olalonde μƒνƒœκ°€ 직렬화 κ°€λŠ₯ν•΄μ•Ό ν•œλ‹€λŠ” ꢌμž₯ 사항은 λΆ€λ“œλŸ¬μš΄ κ²ƒμž…λ‹ˆλ‹€. ν΄λΌμ΄μ–ΈνŠΈμ—μ„œ μƒνƒœλ₯Ό μˆ˜ν™”ν•˜κ±°λ‚˜ μ–΄λ”˜κ°€λ‘œ 보내기 μœ„ν•΄ μƒνƒœλ₯Ό 직렬화할 수 μžˆμ–΄μ•Ό ν•˜κΈ° λ•Œλ¬Έμ— 주둜 μ‰¬μš΄ μ„œλ²„ μΈ‘ λ Œλ”λ§ 및 μƒνƒœ μŠ€λƒ…μƒ·μ„ μš©μ΄ν•˜κ²Œ ν•˜κΈ° μœ„ν•΄ μ‘΄μž¬ν•©λ‹ˆλ‹€. 이것은 μˆœμ „νžˆ ν΄λΌμ΄μ–ΈνŠΈμ—μ„œ μˆ˜ν–‰λ˜λ―€λ‘œ μΆ”κ°€ 처리λ₯Ό μœ„ν•΄ ν•΄λ‹Ή 파일 개체λ₯Ό λ‹¨κΈ°μ μœΌλ‘œ μ €μž₯ν•˜λŠ” 것이 λ‚˜μ˜μ§€ μ•Šμ„ 수 μžˆμŠ΅λ‹ˆλ‹€.

그리고 μƒνƒœλ₯Ό μ§λ ¬ν™”ν•˜λ”λΌλ„ File μ„€λͺ…μžλŠ” 개체 개체둜 μ§λ ¬ν™”λ˜λ―€λ‘œ 직렬화 였λ₯˜κ°€ λ°œμƒν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

λͺ¨λ“  3 λŒ“κΈ€

ν•œ 가지 κ°€λŠ₯ν•œ 해결책은 connect(...) μ‚¬μš©ν•˜μ—¬ store.subscribe 에 μ•‘μ„ΈμŠ€ν•˜λŠ” 방법을 잘 λͺ¨λ₯΄μ§€λ§Œ store.subscribe λ₯Ό μ‚¬μš©ν•˜μ—¬ μƒνƒœ 변경에 λŒ€ν•œ μ €μž₯μ†Œλ₯Ό μˆ˜μ‹ ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€. μ•„λ§ˆλ„ this.context.store.subscribe() ?

@olalonde μƒνƒœκ°€ 직렬화 κ°€λŠ₯ν•΄μ•Ό ν•œλ‹€λŠ” ꢌμž₯ 사항은 λΆ€λ“œλŸ¬μš΄ κ²ƒμž…λ‹ˆλ‹€. ν΄λΌμ΄μ–ΈνŠΈμ—μ„œ μƒνƒœλ₯Ό μˆ˜ν™”ν•˜κ±°λ‚˜ μ–΄λ”˜κ°€λ‘œ 보내기 μœ„ν•΄ μƒνƒœλ₯Ό 직렬화할 수 μžˆμ–΄μ•Ό ν•˜κΈ° λ•Œλ¬Έμ— 주둜 μ‰¬μš΄ μ„œλ²„ μΈ‘ λ Œλ”λ§ 및 μƒνƒœ μŠ€λƒ…μƒ·μ„ μš©μ΄ν•˜κ²Œ ν•˜κΈ° μœ„ν•΄ μ‘΄μž¬ν•©λ‹ˆλ‹€. 이것은 μˆœμ „νžˆ ν΄λΌμ΄μ–ΈνŠΈμ—μ„œ μˆ˜ν–‰λ˜λ―€λ‘œ μΆ”κ°€ 처리λ₯Ό μœ„ν•΄ ν•΄λ‹Ή 파일 개체λ₯Ό λ‹¨κΈ°μ μœΌλ‘œ μ €μž₯ν•˜λŠ” 것이 λ‚˜μ˜μ§€ μ•Šμ„ 수 μžˆμŠ΅λ‹ˆλ‹€.

그리고 μƒνƒœλ₯Ό μ§λ ¬ν™”ν•˜λ”λΌλ„ File μ„€λͺ…μžλŠ” 개체 개체둜 μ§λ ¬ν™”λ˜λ―€λ‘œ 직렬화 였λ₯˜κ°€ λ°œμƒν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

감사 ν•΄μš”. μ—…λ‘œλ“œ μž‘μ—… 생성기λ₯Ό λ‹€μŒ κΈ°λŠ₯으둜 λž˜ν•‘ν–ˆμŠ΅λ‹ˆλ‹€.

waitIntroMessageShowedActionCreator.js

// delays execution of `fn` until `state.session.user.ui.introMessageShowed === true`

export const initWaitIntroMessageShowed = ({ getState, subscribe }) => (fn) => () => (
  new Promise((resolve, reject) => {
    const handleChange = () => {
      const state = getState()
      if (!state.session.user.ui) return null
      if (!state.session.user.ui.introMessageShowed) return null
      /* eslint-disable no-use-before-define */
      unsubscribe()
      return Promise
        .resolve()
        .then(() => fn())
        .catch(reject)
        .then(resolve)
    }
    const unsubscribe = subscribe(handleChange)
    handleChange()
  })
)

λ‚΄ ꡬ성 μš”μ†Œμ—μ„œ :

class DragDropSignup extends Component {
  constructor(props) {
    super(props)
    const waitIntroMessageShowed = initWaitIntroMessageShowed(this.props.store)
    this.onSignupSuccess = waitIntroMessageShowed(this.onSignupSuccess.bind(this))
  }
 // ...
}
// ...

// pass store object as prop
const connectStore = () => (WrappedComponent) => {
  const ConnectStore = (props, context) => (
    <WrappedComponent store={context.store} {...props} />
  )
  ConnectStore.contextTypes = { store: React.PropTypes.object }
  return ConnectStore
}

export default connectStore()(connect()(DragDropSignup))

λˆ„κ΅°κ°€μ—κ²Œ μœ μš©ν•  경우λ₯Ό λŒ€λΉ„ν•˜μ—¬ 여기에 κ²Œμ‹œν•©λ‹ˆλ‹€.

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰