Riot.Js5.2.0 ์ถœ์‹œ๐ŸŽ‰ ๊ตฌํ˜• ๊ตฌ๋ฌธ ์ง€์›

12666 ๋‹จ์–ด JavaScriptRiot.jsupdatetech
๋ฉฐ์น  ์ „Riot.js(์ดํ•˜ riot๋ผ๊ณ  ์•ฝ์นญ) ๋ฒ„์ „ v5.2.0 ์ถœ์‹œโ— ์ด ๋ฒ„์ „์˜ ๋ฐœํ‘œ๋Š” riot ๊ทผ์ฒ˜์—์„œ ํ™”์ œ๊ฐ€ ๋˜์—ˆ๋Š”๋ฐ, ์ด๋ฒˆ์—๋Š” ์ด ์—…๋ฐ์ดํŠธ๋ฅผ ์ ์–ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

๋…ธํŠธ ๋ฅผ ๋ฐœํ–‰ ํ•˜๋‹ค


๊ณต์‹ ์ฐฝ๊ณ ์˜ ๋ฐœํ–‰ ๋…ธํŠธv5.2.0๋ฅผ ๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
Some liked more the old RIot.js syntax so you can now write components also as follows
๊ทธ๋ ‡๊ตฐ์š”. ์˜ˆ์ „์—๋Š” v3ํ•™๊ณผ์˜ ๋ฌธ๋ฒ•์ด ์ƒ๊ฐ๋ณด๋‹ค ์ธ๊ธฐ๊ฐ€ ๋งŽ์•˜์–ด์š”.v4.0.0์‹œ์— ํŒŒ๊ดด์ ์ธ ๋ณ€๊ฒฝ์ด ๋ฐœ์ƒํ–ˆ๊ณ  ๋ฌธ๋ฒ•๋„ ๋“œ๋ผ๋งˆ๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— v4๊ณผ์—์„œ ๋ฆฌ์˜คํŠธ๋ฅผ ๋– ๋‚œ ์‚ฌ๋žŒ๋„ ์–ด๋Š ์ •๋„ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.
๊ทธ๋Ÿผ ์ด์ œ ๋ฐœ๋งค ๋…ธํŠธ์— ๋†“์ธ ์ฝ”๋“œ๋ฅผ ๋ด…์‹œ๋‹ค.
<old-syntax>
  <p>{ state.message }</p>
  <button onclick="{onClick}">Click Me</button>

  <script>
    this.onBeforeMount = () => {
      this.state.message = 'Hello'
    }

    this.onClick = () => {
      this.update({
        message: 'Goodbye',
      })
    }
  </script>
</old-syntax>
๊ทธ๋ ‡๊ตฌ๋‚˜.export default {} ์•ˆ ์จ๋„ ๋˜์ฃ .๋ฌผ๋ก  ์“ฐ๊ณ ๋„ ์กฐ์ž‘์„ ํ™•์ธํ–ˆ๋‹ค.์ฐธ๊ณ ๋กœ ํ˜„์žฌ์˜ ์ž‘๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋น„๊ต๋ฅผ ์œ„ํ•ด ์“ฐ๊ฒ ์Šต๋‹ˆ๋‹ค.
<current-syntax>
  <p>{ state.message }</p>
  <button onclick="{onClick}">Click Me</button>

  <script>
    export default {
      onBeforeMount() {
        this.state.message = 'Hello'
      },
      onClick() {
        this.update({
          message: 'Goodbye',
        })
      },
    }
  </script>
</current-syntax>
์ด๊ฒƒ๋ฐ–์— ๋ชจ๋ฅด๋‹ˆ๊นŒ ์–ด๋–ป๊ฒŒ ์“ฐ๋Š” ๊ฒŒ ์ข‹์„์ง€ ๋‹ค์‹œ ๋ณผ๊ฒŒ์š”.๐Ÿ‘

3๊ฐœ ๋งค๊ฐœ ๋ณ€์ˆ˜:opts,proops,state


์šฐ์„  3๊ฐœ ํŒŒ๋ผ๋ฏธํ„ฐopts, props, state์˜ ํ™•์ธ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•œ๋‹ค.๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ํ™•์ธํ•œ ํ›„ props, state ๋ฌธ์ œ ์—†์ด ๋™์ž‘์„ ํ•˜์˜€์œผ๋‚˜ opts ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
console.log(opts) // opts is not defined

this.onBeforeMount = (props, state) => {
  console.log(props) // {title: "Old Syntax Demo"}
  state.message = 'Hello'
}

๋ผ์ดํ”„ ์‚ฌ์ดํด ๋ฐฉ๋ฒ•์˜ ์“ฐ๊ธฐ


๋‹ค์Œ์€ ๋ผ์ดํ”„ ์‚ฌ์ดํด์„ ์“ฐ๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.์ง€๊ธˆ์€ ์“ฐ๋Š” ๋ฒ•๋„ ๊ดœ์ฐฎ์ง€๋งŒ ๊ตฌํŒ ์“ฐ๋Š” ๋ฒ•this.on('xxx')์€ ๋ชป ์“ฐ๋Š” ๊ฒƒ ๊ฐ™์•„์š”.
// OK
this.onMounted = () => {
  this.update({
    message: 'Bye',
  })
}

// NG
// SyntaxError: Unexpected token
this.on('mount', () => {
  console.log(this)
})

script ํƒœ๊ทธ ์ƒ๋žต


๊ตฌ ๋ฒ„์ „์˜ ์ž‘๋ฒ•์—์„œ <script> ๋ผ๋ฒจ์„ ์“ฐ์ง€ ์•Š์•„๋„ ๋˜์ง€๋งŒ, ์ด๊ฒƒ์€ ์ƒ๋žตํ•  ์ˆ˜ ์—†๋‹ค.
<old-syntax>
  <p>{ state.message }</p>
  <button onclick="{onClick}">Click Me</button>

  <!-- error -->
  this.onBeforeMount = () => {
    this.state.message = 'Hello'
  }

  this.onClick = () => {
    this.update({
      message: 'Goodbye'
    })
  }
</old-syntax>

์ด์ „ ๋ฒ„์ „์˜ ๊ธฐ๋Šฅ์€ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.


๋ฌผ๋ก  riot.mount('*')์ฒ˜๋Ÿผ mount ๋ฐฉ๋ฒ•์˜ ์–ด๋Œ‘ํ„ฐ์™€observable, mixin ๋“ฑ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค.

๋๋งบ๋‹ค


์†”์งํžˆ ๊ธฐ๋Œ€์น˜๋ณด๋‹ค ์กฐ๊ธˆ ๋‚ฎ์€ ๊ฑด ์ง„์‹ฌ์ด์•ผ๐Ÿ˜… v3ํ•™๊ณผ์˜ ๋ฌธ๋ฒ•์„ ์ง€์ง€ํ•˜๋Š” ์‚ฌ์ „ ํ†ต์ง€์—์„œ ๋‚˜๋Š” ๊ฐ์–‘๊ฐ์ƒ‰์˜ ๋ณต๊ฐ์„ ์ƒ๊ฐํ–ˆ์ง€๋งŒ ๊ทธ๊ฑด ๋„ˆ๋ฌด ์ด๋ฅด๋‹ค๐Ÿ’ฆ ์ด๋ ‡๊ฒŒ ๋งํ•˜๋ฉด ๋ช…ํ™•ํ•˜์ง€ ์•Š๊ฒŒ export default {}์จ๋„ ๋ผ์š”. ์—…๋ฐ์ดํŠธ ์ฐจ์ด๊ฐ€ ๋ณ„๋กœ ์—†์–ด์š”.๊ทธ๋Ÿฌ๋ฉด ๊ฐœ์ธ์ ์œผ๋กœ๋Š” ๋ช…์‹œexport default {}์˜ ๊ฐ€๋…์„ฑ์ด ๋†’์•„์„œ ์ข‹์•„ํ•ด์š”.
๊ทธ ์ „์˜ ์—…๋ฐ์ดํŠธ์—์„œ ๋ถ€ํ™œ ๊ธฐ๋Šฅ์ด ์žˆ์„์ง€๋„ ๋ชจ๋ฅด๋‹ˆ ์ž”์ž”ํ•œ ๊ธฐ๋Œ€๋ฅผ ๊ฐ€์ง€๊ณ  ์ด ๊ธฐ์‚ฌ๋ฅผ ๋๋‚ด๋„๋ก ํ•ด์ฃผ์„ธ์š”
๊ทธ๋Ÿผ ์•ˆ๋…•ํžˆ ๊ณ„์„ธ์š”.ฯ‰ ใ‚œ)ใƒŽ

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ