-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: ⚡️ create units object only once
- Loading branch information
Showing
5 changed files
with
48 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
process.env.NODE_ENV = 'development'; | ||
|
||
require('./units.test'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** @jest-environment node */ | ||
'use strict'; | ||
|
||
process.env.NODE_ENV = 'development'; | ||
|
||
require('./units.test'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** @jest-environment node */ | ||
'use strict'; | ||
|
||
require('./units.test'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
'use strict'; | ||
|
||
exports.addon = function (renderer) { | ||
var units = {}; | ||
var list = [ | ||
'px', | ||
'cm', | ||
'mm', | ||
'in', | ||
'pt', | ||
'pc', | ||
'em', | ||
'ex', | ||
'ch', | ||
'rem', | ||
'vw', | ||
'vh', | ||
'deg', | ||
'vmin', | ||
'vmax', | ||
]; | ||
var units = {}; | ||
var list = [ | ||
'px', | ||
'cm', | ||
'mm', | ||
'in', | ||
'pt', | ||
'pc', | ||
'em', | ||
'ex', | ||
'ch', | ||
'rem', | ||
'vw', | ||
'vh', | ||
'deg', | ||
'vmin', | ||
'vmax', | ||
]; | ||
|
||
function f (unit, val) { | ||
return val + unit; | ||
} | ||
function f (unit, val) { | ||
return val + unit; | ||
} | ||
|
||
for (var i = 0; i < list.length; i++) { | ||
var unit = list[i]; | ||
for (var i = 0; i < list.length; i++) { | ||
var unit = list[i]; | ||
|
||
units[unit] = f.bind(null, unit); | ||
} | ||
units[unit] = f.bind(null, unit); | ||
} | ||
|
||
units.inch = function (val) { | ||
return val + 'in'; | ||
}; | ||
units.inch = function (val) { | ||
return val + 'in'; | ||
}; | ||
|
||
units.pct = function (val) { | ||
return val + '%'; | ||
}; | ||
units.pct = function (val) { | ||
return val + '%'; | ||
}; | ||
|
||
exports.addon = function (renderer) { | ||
renderer.assign(renderer, units); | ||
renderer.units = units; | ||
}; |