Skip to content

Commit be6fe43

Browse files
Improving solution
1 parent f27a20e commit be6fe43

File tree

4 files changed

+19
-50
lines changed

4 files changed

+19
-50
lines changed

src/core/componentStructure.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,25 @@ class ComponentStructure {
3434
};
3535
this.transitionMode = isTransition(defaultNodes);
3636
this.externalComponent = root.externalComponent;
37+
this.rootTransition = root.transition;
3738
this.tag = root.tag;
38-
this.noneFunctional =
39-
this.externalComponent && typeof this.tag !== "function";
4039
this.setHtmlRoot($el);
4140
}
4241

42+
get _domChildrenFromNodes() {
43+
return this._getChildrenNodes().map(getHtmlElementFromNode);
44+
}
45+
46+
get _isRootComponent() {
47+
return this.externalComponent || this.rootTransition;
48+
}
49+
50+
render(h, attributes) {
51+
const { tag, children, _isRootComponent } = this;
52+
const option = !_isRootComponent ? children : { default: () => children };
53+
return h(tag, attributes, option);
54+
}
55+
4356
setHtmlRoot($el) {
4457
if (!$el) {
4558
return;
@@ -52,21 +65,12 @@ class ComponentStructure {
5265
return this;
5366
}
5467

55-
get _domChildrenFromNodes() {
56-
return this._getChildrenNodes().map(getHtmlElementFromNode);
57-
}
58-
5968
_getChildrenNodes() {
6069
const {
61-
noneFunctional,
6270
transitionMode,
6371
nodes: { default: defaultNodes }
6472
} = this;
6573

66-
if (noneFunctional) {
67-
return defaultNodes[0].children;
68-
}
69-
7074
if (!transitionMode) {
7175
return defaultNodes.length === 1 && defaultNodes[0].el.nodeType === 3
7276
? defaultNodes[0].children

src/core/renderHelper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ function computeNodes(slots) {
2121
}
2222

2323
function getRootInformation(tag) {
24-
const externalComponent = !isHtmlTag(tag) && !isTransition(tag);
24+
const transition = isTransition(tag);
25+
const externalComponent = !isHtmlTag(tag) && !transition;
2526
return {
27+
transition,
2628
externalComponent,
2729
tag: externalComponent ? resolveComponent(tag) : tag
2830
};

src/vuedraggable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const draggableComponent = defineComponent({
7575
const componentStructure = computeComponentStructure({ $slots, tag, $el });
7676
this.componentStructure = componentStructure;
7777
const attributes = getComponentAttributes({ $attrs, componentData });
78-
return h(componentStructure.tag, attributes, componentStructure.children);
78+
return componentStructure.render(h, attributes);
7979
},
8080

8181
created() {

tests/unit/vuedraggable.spec.js

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,6 @@ describe("draggable.vue when initialized with list", () => {
192192
const expectedRegex = new RegExp(`^<${tag}>.*<\/${tag}>$`);
193193
expect(wrapper.html()).toMatch(expectedRegex);
194194
});
195-
196-
it("set noneFunctional to false ", () => {
197-
const {
198-
componentStructure: { noneFunctional }
199-
} = vm;
200-
expect(noneFunctional).toBe(false);
201-
});
202195
});
203196

204197
it("computes indexes", async () => {
@@ -308,36 +301,6 @@ describe("draggable.vue when initialized with list", () => {
308301
});
309302
});
310303

311-
describe("when creating a component", () => {
312-
test.each([
313-
["Fake", true, Fake],
314-
["FakeFunctional", false, FakeFunctional]
315-
])(
316-
"when using component with tag %p compute noneFunctionalComponentMode as %p ",
317-
(_, expectedNoneFunctionalComponentMode, component) => {
318-
wrapper = mount(draggable, {
319-
propsData: {
320-
tag: "child"
321-
},
322-
slots: {
323-
default: () => []
324-
},
325-
global: {
326-
components: {
327-
child: component
328-
}
329-
}
330-
});
331-
const {
332-
vm: {
333-
componentStructure: { noneFunctional }
334-
}
335-
} = wrapper;
336-
expect(noneFunctional).toBe(expectedNoneFunctionalComponentMode);
337-
}
338-
);
339-
});
340-
341304
it("keeps a reference to Sortable instance", () => {
342305
expect(vm._sortable).toBe(SortableFake);
343306
});

0 commit comments

Comments
 (0)