Skip to content

Commit

Permalink
Proper prioritization of children over spread
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Jan 11, 2020
1 parent 49389ba commit fc82a66
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dom-expressions",
"description": "A Fine-Grained Runtime for Performant DOM Rendering",
"version": "0.14.11",
"version": "0.14.12",
"author": "Ryan Carniato",
"license": "MIT",
"repository": {
Expand All @@ -24,7 +24,7 @@
"devDependencies": {
"@babel/core": "^7.7.7",
"@babel/preset-env": "^7.7.7",
"babel-plugin-jsx-dom-expressions": "0.14.12",
"babel-plugin-jsx-dom-expressions": "0.14.15",
"coveralls": "3.0.9",
"jest": "24.9.0",
"s-js": "~0.4.9"
Expand Down
7 changes: 6 additions & 1 deletion runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ declare module "dom-expressions-runtime" {
): any;
export function delegateEvents(eventNames: string[]): void;
export function clearDelegatedEvents(): void;
export function spread(node: Element, accessor: any, isSVG: Boolean): void;
export function spread(
node: Element,
accessor: any,
isSVG?: Boolean,
skipChildren?: Boolean
): void;
export function classList(
node: Element,
value: { [k: string]: boolean },
Expand Down
7 changes: 6 additions & 1 deletion template/runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export function createComponent(
): any;
export function delegateEvents(eventNames: string[]): void;
export function clearDelegatedEvents(): void;
export function spread(node: Element, accessor: any, isSVG: Boolean): void;
export function spread(
node: Element,
accessor: any,
isSVG?: Boolean,
skipChildren?: Boolean
): void;
export function classList(
node: Element,
value: { [k: string]: boolean },
Expand Down
10 changes: 5 additions & 5 deletions template/runtime.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export function classList(node, value, prev) {
}
}

export function spread(node, accessor, isSVG) {
export function spread(node, accessor, isSVG, skipChildren) {
if (typeof accessor === 'function') {
wrap(current => spreadExpression(node, accessor(), current, isSVG));
} else spreadExpression(node, accessor, undefined, isSVG);
wrap(current => spreadExpression(node, accessor(), current, isSVG, skipChildren));
} else spreadExpression(node, accessor, undefined, isSVG, skipChildren);
}

export function insert(parent, accessor, marker, initial) {
Expand Down Expand Up @@ -180,9 +180,9 @@ function eventHandler(e) {
}
}

function spreadExpression(node, props, prevProps = {}, isSVG) {
function spreadExpression(node, props, prevProps = {}, isSVG, skipChildren) {
let info;
if ("children" in props) {
if (!skipChildren && "children" in props) {
wrap(() =>
(prevProps.children = insertExpression(
node,
Expand Down
18 changes: 18 additions & 0 deletions test/spread.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,22 @@ describe("create element with various spreads", () => {
expect(span.__click).toBeDefined();
disposer();
});

it("should properly prioritize children over spread", () => {
let span, disposer;

const Component = props => <span {...props}>Holla</span>;

S.root(dispose => {
disposer = dispose;
<Component ref={span} onClick={() => console.log("click")}>
Hi
</Component>;
});

expect(span).toBeDefined();
expect(span.textContent).toBe("Holla");
expect(span.__click).toBeDefined();
disposer();
});
});

0 comments on commit fc82a66

Please sign in to comment.