@@ -41,78 +41,56 @@ function span(text) {
4141}
4242
4343function createUIForMeasurementMethod ( ) {
44- let check = document . createElement ( "input" ) ;
45- check . type = "checkbox" ;
46- check . id = "measurement-method" ;
47- check . checked = params . measurementMethod === "raf" ;
48-
49- check . onchange = ( ) => {
50- params . measurementMethod = check . checked ? "raf" : "timer" ;
51- updateURL ( ) ;
52- } ;
53-
54- let label = document . createElement ( "label" ) ;
55- label . append ( check , " " , span ( "rAF timing" ) ) ;
56-
57- return label ;
44+ return createCheckboxUI ( "rAF timing" , params . measurementMethod === "raf" , ( isChecked ) => {
45+ params . measurementMethod = isChecked ? "raf" : "timer" ;
46+ } ) ;
5847}
5948
6049function createUIForWarmupSuite ( ) {
61- let check = document . createElement ( "input" ) ;
62- check . type = "checkbox" ;
63- check . id = "warmup-suite" ;
64- check . checked = ! ! params . useWarmupSuite ;
50+ return createCheckboxUI ( "Use Warmup Suite" , params . useWarmupSuite , ( isChecked ) => {
51+ params . useWarmupSuite = isChecked ;
52+ } ) ;
53+ }
6554
66- check . onchange = ( ) => {
67- params . useWarmupSuite = check . checked ;
55+ function createCheckboxUI ( labelValue , initialValue , paramsUpdateCallback ) {
56+ const checkbox = document . createElement ( "input" ) ;
57+ checkbox . type = "checkbox" ;
58+ checkbox . checked = ! ! initialValue ;
59+ checkbox . onchange = ( ) => {
60+ paramsUpdateCallback ( checkbox . checked ) ;
6861 updateURL ( ) ;
6962 } ;
7063
71- let label = document . createElement ( "label" ) ;
72- label . append ( check , " " , span ( "Use Warmup Suite" ) ) ;
64+ const label = document . createElement ( "label" ) ;
65+ label . append ( checkbox , " " , span ( labelValue ) ) ;
7366
7467 return label ;
7568}
7669
7770function createUIForIterationCount ( ) {
78- const { range, label } = createTimeRangeUI ( "Iterations: " , params . iterationCount , "#" , 1 , 200 ) ;
79- range . onchange = ( ) => {
80- params . iterationCount = parseInt ( range . value ) ;
81- updateURL ( ) ;
82- } ;
83- return label ;
71+ return createTimeRangeUI ( "Iterations: " , "iterationCount" , "#" , 1 , 200 ) ;
8472}
8573
8674function createUIForWarmupBeforeSync ( ) {
87- const { range, label } = createTimeRangeUI ( "Warmup time: " , params . warmupBeforeSync ) ;
88- range . onchange = ( ) => {
89- params . warmupBeforeSync = parseInt ( range . value ) ;
90- updateURL ( ) ;
91- } ;
92- return label ;
75+ return createTimeRangeUI ( "Warmup time: " , "warmupBeforeSync" ) ;
9376}
9477
9578function createUIForSyncStepDelay ( ) {
96- const { range, label } = createTimeRangeUI ( "Sync step delay: " , params . waitBeforeSync ) ;
97- range . onchange = ( ) => {
98- params . waitBeforeSync = parseInt ( range . value ) ;
99- updateURL ( ) ;
100- } ;
101- return label ;
79+ return createTimeRangeUI ( "Sync step delay: " , "waitBeforeSync" ) ;
10280}
10381
104- function createTimeRangeUI ( labelText , initialValue , unit = "ms" , min = 0 , max = 1000 ) {
82+ function createTimeRangeUI ( labelText , paramKey , unit = "ms" , min = 0 , max = 1000 ) {
10583 const range = document . createElement ( "input" ) ;
10684 range . type = "range" ;
10785 range . min = min ;
10886 range . max = max ;
109- range . value = initialValue ;
87+ range . value = params [ paramKey ] ;
11088
11189 const rangeValueAndUnit = document . createElement ( "span" ) ;
11290 rangeValueAndUnit . className = "range-label-data" ;
11391
11492 const rangeValue = document . createElement ( "span" ) ;
115- rangeValue . textContent = initialValue ;
93+ rangeValue . textContent = params [ paramKey ] ;
11694 rangeValueAndUnit . append ( rangeValue , " " , unit ) ;
11795
11896 const label = document . createElement ( "label" ) ;
@@ -121,8 +99,12 @@ function createTimeRangeUI(labelText, initialValue, unit = "ms", min = 0, max =
12199 range . oninput = ( ) => {
122100 rangeValue . textContent = range . value ;
123101 } ;
102+ range . onchange = ( ) => {
103+ params [ paramKey ] = parseInt ( range . value ) ;
104+ updateURL ( ) ;
105+ } ;
124106
125- return { range , label } ;
107+ return label ;
126108}
127109
128110function createUIForSuites ( ) {
0 commit comments