Skip to content

Commit

Permalink
refactor(vdom): rename children() to fragment()
Browse files Browse the repository at this point in the history
BREAKING CHANGE: function `children()` is renamed to `fragment()`.
  • Loading branch information
localvoid committed May 12, 2018
1 parent e4daf4c commit b832e67
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
12 changes: 6 additions & 6 deletions packages/ivi/__tests__/vnode_children.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VNodeFlags, VNode, children, mapRange } from "ivi";
import { VNodeFlags, VNode, fragment, mapRange } from "ivi";
import * as h from "ivi-html";

test(`{ null }`, () => {
Expand Down Expand Up @@ -128,7 +128,7 @@ test(`<div></div><div></div>{ null }`, () => {
test(`{ children(<div></div><div></div>) }`, () => {
const v1 = h.div();
const v2 = h.div();
const v = h.div().c(children(v1, v2));
const v = h.div().c(fragment(v1, v2));

expect(v.flags & VNodeFlags.ChildrenVNode).toBeTruthy();
expect(v.children).toBe(v1);
Expand All @@ -145,7 +145,7 @@ test(`{ children(<div></div><div></div>) }`, () => {
test(`{ null }{ children(<div></div><div></div>) }`, () => {
const v1 = h.div();
const v2 = h.div();
const v = h.div().c(null, children(v1, v2));
const v = h.div().c(null, fragment(v1, v2));

expect(v.flags & VNodeFlags.ChildrenVNode).toBeTruthy();
expect(v.children).toBe(v1);
Expand All @@ -162,7 +162,7 @@ test(`{ null }{ children(<div></div><div></div>) }`, () => {
test(`{ null }{ children(<div key="a"></div><div></div>) }`, () => {
const v1 = h.div().k("a");
const v2 = h.div();
const v = h.div().c(null, children(v1, v2));
const v = h.div().c(null, fragment(v1, v2));

expect(v.flags & VNodeFlags.ChildrenVNode).toBeTruthy();
expect(v.children).toBe(v1);
Expand All @@ -180,7 +180,7 @@ test(`<div></div>{ children(<div></div><div></div>) }`, () => {
const v1 = h.div();
const v2 = h.div();
const v3 = h.div();
const v = h.div().c(v1, children(v2, v3));
const v = h.div().c(v1, fragment(v2, v3));

expect(v.flags & VNodeFlags.ChildrenVNode).toBeTruthy();
expect(v.children).toBe(v1);
Expand All @@ -202,7 +202,7 @@ test(`{ children(<div></div><div></div>) }<div></div>`, () => {
const v1 = h.div();
const v2 = h.div();
const v3 = h.div();
const v = h.div().c(children(v1, v2), v3);
const v = h.div().c(fragment(v1, v2), v3);

expect(v.flags & VNodeFlags.ChildrenVNode).toBeTruthy();
expect(v.children).toBe(v1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { VNodeFlags, VNode, children } from "ivi";
import { VNodeFlags, VNode, fragment } from "ivi";
import * as h from "ivi-html";

test(`empty`, () => {
expect(children()).toBeNull();
expect(fragment()).toBeNull();
});

test(`{ null }`, () => {
expect(children(null)).toBeNull();
expect(fragment(null)).toBeNull();
});

test(`{ null }{ null }`, () => {
expect(children(null, null)).toBeNull();
expect(fragment(null, null)).toBeNull();
});

test(`"abc"`, () => {
const first = children("abc")!;
const first = fragment("abc")!;

expect(first).toBeInstanceOf(VNode);
expect(first.flags & VNodeFlags.Text).toBeTruthy();
Expand All @@ -24,7 +24,7 @@ test(`"abc"`, () => {
});

test(`10`, () => {
const first = children(10)!;
const first = fragment(10)!;

expect(first).toBeInstanceOf(VNode);
expect(first.flags & VNodeFlags.Text).toBeTruthy();
Expand All @@ -35,7 +35,7 @@ test(`10`, () => {

test(`<div></div>`, () => {
const v1 = h.div();
const first = children(v1);
const first = fragment(v1);

expect(first).toBe(v1);
expect(v1.prev).toBe(v1);
Expand All @@ -45,7 +45,7 @@ test(`<div></div>`, () => {
test(`<div></div></div></div>`, () => {
const v1 = h.div();
const v2 = h.div();
const first = children(v1, v2);
const first = fragment(v1, v2);

expect(first).toBe(v1);
expect(v1.prev).toBe(v2);
Expand All @@ -56,7 +56,7 @@ test(`<div></div></div></div>`, () => {

test(`{ null }<div></div>`, () => {
const v1 = h.div();
const first = children(null, v1);
const first = fragment(null, v1);

expect(first).toBe(v1);
expect(v1.prev).toBe(v1);
Expand All @@ -65,7 +65,7 @@ test(`{ null }<div></div>`, () => {

test(`{ null }{ null }<div></div>`, () => {
const v1 = h.div();
const first = children(null, null, v1);
const first = fragment(null, null, v1);

expect(first).toBe(v1);
expect(v1.prev).toBe(v1);
Expand All @@ -74,7 +74,7 @@ test(`{ null }{ null }<div></div>`, () => {

test(`<div></div>{ null }`, () => {
const v1 = h.div();
const first = children(v1, null);
const first = fragment(v1, null);

expect(first).toBe(v1);
expect(v1.prev).toBe(v1);
Expand All @@ -83,7 +83,7 @@ test(`<div></div>{ null }`, () => {

test(`<div></div>{ null }{ null }`, () => {
const v1 = h.div();
const first = children(v1, null, null);
const first = fragment(v1, null, null);

expect(first).toBe(v1);
expect(v1.prev).toBe(v1);
Expand All @@ -92,7 +92,7 @@ test(`<div></div>{ null }{ null }`, () => {

test(`{ null }<div></div>{ null }`, () => {
const v1 = h.div();
const first = children(null, v1, null);
const first = fragment(null, v1, null);

expect(first).toBe(v1);
expect(v1.prev).toBe(v1);
Expand All @@ -102,7 +102,7 @@ test(`{ null }<div></div>{ null }`, () => {
test(`<div></div>{ null }</div></div>`, () => {
const v1 = h.div();
const v2 = h.div();
const first = children(v1, null, v2);
const first = fragment(v1, null, v2);

expect(first).toBe(v1);
expect(v1.prev).toBe(v2);
Expand All @@ -114,7 +114,7 @@ test(`<div></div>{ null }</div></div>`, () => {
test(`{ children(<div></div></div></div>) }`, () => {
const v1 = h.div();
const v2 = h.div();
const first = children(children(v1, v2));
const first = fragment(fragment(v1, v2));

expect(first).toBe(v1);
expect(v1.prev).toBe(v2);
Expand All @@ -127,7 +127,7 @@ test(`<div></div>{ children(<div></div></div></div>) }`, () => {
const v1 = h.div();
const v2 = h.div();
const v3 = h.div();
const first = children(v1, children(v2, v3));
const first = fragment(v1, fragment(v2, v3));

expect(first).toBe(v1);
expect(v1.prev).toBe(v3);
Expand Down
4 changes: 2 additions & 2 deletions packages/ivi/__tests__/vnode_collections_map.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { map, children, VNodeFlags } from "ivi";
import { map, fragment, VNodeFlags } from "ivi";
import * as h from "ivi-html";

test(`empty`, () => {
Expand Down Expand Up @@ -95,5 +95,5 @@ test(`raise an exception when VNode doesn't have an explicit key (second node)`,
});

test(`raise an exception when function returns children collection`, () => {
expect(() => { map([0], () => children(h.div().k(0), h.div().k(1))); }).toThrowError("singular");
expect(() => { map([0], () => fragment(h.div().k(0), h.div().k(1))); }).toThrowError("singular");
});
4 changes: 2 additions & 2 deletions packages/ivi/__tests__/vnode_collections_mapRange.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mapRange, VNodeFlags, children } from "ivi";
import { mapRange, VNodeFlags, fragment } from "ivi";
import * as h from "ivi-html";

test(`zero range (0, 0)`, () => {
Expand Down Expand Up @@ -61,5 +61,5 @@ test(`raise an exception when VNode doesn't have an explicit key (second node)`,
});

test(`raise an exception when function returns children collection`, () => {
expect(() => { mapRange(0, 1, () => children(h.div().k(0), h.div().k(1))); }).toThrowError("singular");
expect(() => { mapRange(0, 1, () => fragment(h.div().k(0), h.div().k(1))); }).toThrowError("singular");
});
2 changes: 1 addition & 1 deletion packages/ivi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export {
getDOMInstanceFromVNode, getComponentInstanceFromVNode,
autofocus, stopDirtyChecking,
} from "./vdom/vnode";
export { children, map, mapRange } from "./vdom/vnode_collections";
export { fragment, map, mapRange } from "./vdom/vnode_collections";
export { element } from "./vdom/element";
export { statefulComponent, statelessComponent, withShouldUpdate, context, connect } from "./vdom/vnode_factories";

Expand Down
8 changes: 4 additions & 4 deletions packages/ivi/src/vdom/vnode_collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { VNodeFlags } from "./flags";
import { VNode } from "./vnode";

/**
* children is a variadic function that creates a children collection.
* fragment is a variadic function that creates a children collection.
*
* const content = children(
* h.p().c("Paragraph 1"),
Expand All @@ -20,10 +20,10 @@ import { VNode } from "./vnode";
* @param args children.
* @returns children collection.
*/
export function children(...args: Array<VNode | string | number | null>): VNode | null;
export function fragment(...args: Array<VNode | string | number | null>): VNode | null;

/**
* children is a variadic function that creates a children collection.
* fragment is a variadic function that creates a children collection.
*
* const content = children(
* h.p().c("Paragraph 1"),
Expand All @@ -40,7 +40,7 @@ export function children(...args: Array<VNode | string | number | null>): VNode
*
* @returns children collection.
*/
export function children(): VNode | null {
export function fragment(): VNode | null {
const args: Array<VNode | string | number | null> = arguments as any;
let first: VNode<any> | null = null;
let prev: VNode<any> | null = null;
Expand Down

0 comments on commit b832e67

Please sign in to comment.