Giter VIP home page Giter VIP logo

Comments (6)

yyx990803 avatar yyx990803 commented on May 3, 2024 3

@posva I just realized in v3 directives are in fact implemented as special VNode data hooks - that is to say in render functions you can do this:

h('div', {
  vnodeMounted() { ... },
  vnodeUpdated() { ... }
})

And for template <div v-foo/>, it will take the mounted hook of v-foo and merge it into the VNode as vnodeMounted.

So they would be also included in the child component's this.$attrs. If the child component does not bind $attrs, the directive is ignored just like other extraneous attributes; if the child binds $attrs, it binds the custom directives as well. This makes it consistent with the new attr fallthrough behavior. WDYT?

from core.

posva avatar posva commented on May 3, 2024 2

I think it will make sense to still support directives on components, even if we receive an array of elements. Some DOM manipulations like v-focus or v-clickaway are still valid for components. This will also make the adoption strategy a bit harder

from core.

yyx990803 avatar yyx990803 commented on May 3, 2024

@posva making the first argument Element | Array<Element> is still a breaking change, in fact it requires heavier refactoring to make sure existing directives work properly. It's also not clear what a directive should do in the case of receiving multiple elements: what should v-focus or v-clickaway do in such cases? Implicitly failing seems like a bad idea.

from core.

posva avatar posva commented on May 3, 2024

making the first argument Element | Array is still a breaking change, in fact it requires heavier refactoring to make sure existing directives work properly

True, but it isn't much for existing directives to just extract the first element and throw if there are more (thinking of a possible codemod)

const [el] = elements
if (elements.length > 1) throw new Error()

For example, v-focus could lookup an input/select/button or explicitly tab-indexed element. For clickaway it could look up a data attribute.

But my point is, recreating those features with components is way more verbose:

<Focus>
  <v-text-field/>
</Focus>

or isn't declarative:

<v-text-field ref="mainInput"/>
this.$refs.mainInput.focus() // a component method

from core.

LinusBorg avatar LinusBorg commented on May 3, 2024

Just thinking out loud: Would this be achievable? And if so, would it make any sense? Would make the implementation treeshakable, right?

import {
  beforeMount,
  mounted,
  beforeUpdate,
  update,
  beforeUnmount,
  unmounted,
} from 'vue/directives'

export default () => {
  mounted((el, binding, vnode, prevVnode) => {
    // do stuff
  })
}

from core.

yyx990803 avatar yyx990803 commented on May 3, 2024

Revised and published: vuejs/rfcs#32

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.