forked from wikiwi/reassemble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwithHandlers.tsx
63 lines (52 loc) · 1.48 KB
/
withHandlers.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* tslint:disable: no-console */
/* tslint:disable: no-var-requires */
/* tslint:disable: only-arrow-functions */
import * as Benchmark from "benchmark";
import * as recompose from "recompose";
import * as recompact from "recompact";
import * as React from "react";
import * as ReactDOM from "react-dom";
import * as reassemble from "../src";
require("../test/setupDOM");
const suite = new Benchmark.Suite();
const Component: React.StatelessComponent<any> = () => null;
const container = document.createElement("div");
document.body.appendChild(container);
function render(node: React.ReactElement<any>) {
ReactDOM.render(node, container);
}
function cleanup() {
ReactDOM.unmountComponentAtNode(container);
}
const create = (lib: any) => {
const { withHandlers } = lib;
return lib.compose(
...Array(10).fill(withHandlers({ onClick: () => () => "foo" })),
);
};
const Composed = create(recompose)(Component);
const Compacted = create(recompact)(Component);
const Assembled = create(reassemble)(Component);
// add tests
suite
.add("recompose", () => {
render(<Composed />);
cleanup();
})
.add("recompact", () => {
render(<Compacted />);
cleanup();
})
.add("reassemble", () => {
render(<Assembled />);
cleanup();
})
// add listeners
.on("cycle", (event: any) => {
console.log(String(event.target));
})
.on("complete", function() {
console.log("Fastest is " + this.filter("fastest").map("name"));
})
// run async
.run({ async: true });