Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What's next in Vue 3? 🖖 3️⃣

What's next in Vue 3? 🖖 3️⃣

Ignacio Anaya

June 27, 2019
Tweet

More Decks by Ignacio Anaya

Other Decks in Programming

Transcript

  1. ! Nacho Anaya ! @ianaya89 • JavaScript Engineer @BloqInc •

    Ambassador @Auth0 • Tech Speaker @MozTechSpeakers • Organizador @Vuenos_Aires What's next in Vue3? - @ianaya89 2
  2. ☢ " Antes (2.x) <template> <h1>{{ name }}</h1> </template> <script>

    export default { data () { return { name: 'Nacho', foo: 'bar' } } } </script> What's next in Vue3? - @ianaya89 20
  3. ☢ " Antes (2.x) <script> export default { data ()

    { return { object: { name: 'Nacho' }, array: ['string'] } }, created () { this.$set(this.object, 'lastName', 'Anaya') this.$delete(this.object, 'lastName') this.$set(this.array, 1, 'new string') } } </script> What's next in Vue3? - @ianaya89 21
  4. ☢ " Antes (2.x) <script> export default { data ()

    { return { object: { name: 'Nacho' }, array: ['string'] } }, created () { this.$set(this.object, 'lastName', 'Anaya') this.$delete(this.object, 'lastName') this.$set(this.array, 1, 'new string') } } </script> What's next in Vue3? - @ianaya89 22
  5. ! Proxy const handler = { get: (object, property) =>

    object[property] || 'Default Value' } const p = new Proxy({}, handler) p.a = 1 p.b = undefined console.log(p.a, p.b) // 1, 'Default Value' What's next in Vue3? - @ianaya89 24
  6. ☢ " Ahora (3.x) // this.$set(this.object, 'lastName', 'Anaya') // this.$delete(this.object,

    'lastName') // this.$set(this.array, 1, 'new string' this.object.lastName = 'Anaya' delete this.object.lastName this.array[1] = 'new string' What's next in Vue3? - @ianaya89 25
  7. ☢ " Ahora (3.x) Map - Set - WeakMap -

    WeakSet What's next in Vue3? - @ianaya89 27
  8. ❓ Class API class App extends Vue { static template

    = ` <div @click="increment"> {{ count }} {{ plusOne }} </div> ` count = 0 created() { console.log(this.count) } get plusOne() { return this.count + 1 } increment() { this.count++ } } What's next in Vue3? - @ianaya89 30
  9. ! Reactivity API import { state } from '@vue/observer' //

    crea un objeto reactivo const store = state({ counter: 1 }) console.log(store.counter) What's next in Vue3? - @ianaya89 34
  10. ! Reactivity API import { value, watch } from '@vue/observer'

    // crea un objeto reactivo sobre un valor primitivo const counter = value(0) // crea un watcher a una propiedad reactiva watch( counter, value => console.log('Counter changed', value) ) What's next in Vue3? - @ianaya89 35
  11. ! Reactivity API import { value, computed } from '@vue/observer'

    // crea un valor/estado reactivo const counter = value(0) // crea una computed sobre una propiedad reactiva const plusOne = computed(() => counter.value + 1) What's next in Vue3? - @ianaya89 36
  12. ! Por qué? • Cambiar paradigmas para crear Plugins/Librerias •

    Mejorar la integración SDK's • Mejorar la integración con librerías • Crear alternativas para Vuex What's next in Vue3? - @ianaya89 38
  13. ♻ Dynamic Lifecycle Injection import { onMounted, onUpdated } from

    'vue' export default { setup () { onMounted(() => console.log('Mounted')) onUpdated(() => console.log('Updated')) } } What's next in Vue3? - @ianaya89 40
  14. ♻ Dynamic Lifecycle Injection import { onMounted, onUpdated } from

    'vue' export default { setup () { // updated hook que se ejecuta solo una vez const remove = onUpdated(() => { console.log('Updated') remove() }) } } What's next in Vue3? - @ianaya89 41
  15. ♻ Dynamic LifeCycle Injection import { onMounted, onUpdated } from

    'vue' export default { setup () { // attachar un hook para otro componente onMounted(() => console.log('Mounted...'), otherComponent) } } What's next in Vue3? - @ianaya89 42
  16. λ Function API <template> <div> <span>count is {{ count }}</span>

    <span>plusOne is {{ plusOne }}</span> <button @click="increment">count++</button> </div> </template> What's next in Vue3? - @ianaya89 45
  17. λ Function API <script> import { value, computed, onMounted }

    from 'vue' export default { setup() { const count = value(0) const plusOne = computed(() => count.value + 1) const increment = () => { count.value += 1 } onMounted(() => { console.log('mounted') }) return { count, plusOne, increment } } } </script> What's next in Vue3? - @ianaya89 46
  18. λ Function API <script> export default { props: { name:

    String }, setup(props, context) { console.log(props.name) context.attrs context.slots context.refs context.emit context.parent context.root } } </script> What's next in Vue3? - @ianaya89 47
  19. ! Depreacados data - computed - methods - watch -

    inject - mixins - extends - hooks What's next in Vue3? - @ianaya89 48
  20. ! Motivación • Inferencia de Tipos • Reducir el Bundle

    • Performance • ! Logic Composition " What's next in Vue3? - @ianaya89 50
  21. ! Reactivity API + ♻ Dynamic Lifecycle Injection + λ

    Function API = ! Composition Functions What's next in Vue3? - @ianaya89 51
  22. ! Composition Functions import { onMounted, onUnmounted } from 'vue'

    import { state } from '@vue/observer' export default function useMouse() { const mousePos = state({ x: 0, y: 0 }) const update = e => { x.value = e.pageX y.value = e.pageY } onMounted(() => { window.addEventListener('mousemove', update) }) onUnmounted(() => { window.removeEventListener('mousemove', update) }) return mousePos } What's next in Vue3? - @ianaya89 53
  23. ! Logic Composition <template> <div>{{ x, y }}</div> </template> <script>

    import useMouse from './useMouse' export default { setup() { const { x, y } = useMouse() const { z } = useOtherLogic() return { x, y, z } } } </script> What's next in Vue3? - @ianaya89 54
  24. ! Más! • Multiples root elements • v-model automágico (y

    multiple) • Propagación de atributos • Herramienta de migración (~5min) • Sintaxis de slots What's next in Vue3? - @ianaya89 61
  25. Nacho: "When Vue 3.0 will be ready?" Evan: "When it’s

    ready" What's next in Vue3? - @ianaya89 66