]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat: inheritAttrs
authorEvan You <yyx990803@gmail.com>
Mon, 24 Sep 2018 03:28:21 +0000 (23:28 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 24 Sep 2018 03:28:21 +0000 (23:28 -0400)
packages/core/src/component.ts
packages/core/src/componentOptions.ts
packages/core/src/componentUtils.ts
packages/core/src/createRenderer.ts

index 1790aa330d3e667bbbd04f9301f966f06902ee0f..bb98101287fef1ddac86c7a9327a50cb5bb16b94 100644 (file)
@@ -21,6 +21,7 @@ export interface ComponentClass extends Flatten<typeof Component> {
 export interface FunctionalComponent<P = Data> extends RenderFunction<P> {
   pure?: boolean
   props?: ComponentPropsOptions<P>
+  inheritAttrs?: boolean
 }
 
 // this interface is merged with the class type
index d459a82e70a9bdef1fb23aa2f9aa6362091ceb52..c8ce0caa16ada283c8be1be2f67984606be7d1ba 100644 (file)
@@ -13,6 +13,7 @@ export interface ComponentOptions<D = Data, P = Data> {
   computed?: ComponentComputedOptions<D, P>
   watch?: ComponentWatchOptions<D, P>
   render?: RenderFunction<P>
+  inheritAttrs?: boolean
   // TODO other options
   readonly [key: string]: any
 }
index ff893b66b28d70ee0f1b6c3850e713840630f546..d4c4dc7e0c06bb8db56d3ee0fa6312786b5015ff 100644 (file)
@@ -71,7 +71,11 @@ export function renderInstanceRoot(instance: MountedComponent) {
       }
     }
   }
-  return normalizeComponentRoot(vnode, instance.$parentVNode)
+  return normalizeComponentRoot(
+    vnode,
+    instance.$parentVNode,
+    instance.$options.inheritAttrs
+  )
 }
 
 export function teardownComponentInstance(instance: MountedComponent) {
@@ -88,7 +92,8 @@ export function teardownComponentInstance(instance: MountedComponent) {
 
 export function normalizeComponentRoot(
   vnode: any,
-  componentVNode: VNode | null
+  componentVNode: VNode | null,
+  inheritAttrs: boolean | void
 ): VNode {
   if (vnode == null) {
     vnode = createTextVNode('')
@@ -104,7 +109,7 @@ export function normalizeComponentRoot(
       (flags & VNodeFlags.COMPONENT || flags & VNodeFlags.ELEMENT)
     ) {
       const parentData = componentVNode.data
-      if (parentData != null) {
+      if (parentData != null && inheritAttrs !== false) {
         let extraData: any = null
         for (const key in parentData) {
           // attrs/class/style bindings on parentVNode are merged down to child
index 4c8ebb4f6e263b9ff7ab165f64e893efb60fc244..1deb16305b6338211d1227b3c32bd156054b62e9 100644 (file)
@@ -278,7 +278,8 @@ export function createRenderer(options: RendererOptions) {
       // functional component
       const subTree = (vnode.children = normalizeComponentRoot(
         (tag as FunctionalComponent)(data || EMPTY_OBJ, slots || EMPTY_OBJ),
-        vnode
+        vnode,
+        (tag as FunctionalComponent).inheritAttrs
       ))
       el = vnode.el = mount(subTree, null, parentComponent, isSVG, null)
     }
@@ -562,7 +563,8 @@ export function createRenderer(options: RendererOptions) {
     if (shouldUpdate) {
       const nextTree = (nextVNode.children = normalizeComponentRoot(
         render(nextProps || EMPTY_OBJ, nextSlots || EMPTY_OBJ),
-        nextVNode
+        nextVNode,
+        render.inheritAttrs
       ))
       patch(prevTree, nextTree, container, parentComponent, isSVG)
       nextVNode.el = nextTree.el