Skip to content

Commit

Permalink
perf(hiccup): update css()
Browse files Browse the repository at this point in the history
- use string concat (~2.5x faster)
- skip null values
  • Loading branch information
postspectacular committed May 12, 2018
1 parent feca566 commit b1cb7d9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/hiccup/src/css.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { isFunction } from "@thi.ng/checks/is-function";

export const css = (rules: any) => {
const css = [];
let css = "", v;
for (let r in rules) {
if (rules.hasOwnProperty(r)) {
let v = rules[r];
if (isFunction(v)) {
v = v(rules);
}
css.push(r + ":" + v + ";");
v = rules[r];
if (isFunction(v)) {
v = v(rules);
}
v != null && (css += `${r}:${v};`);
}
return css.join("");
return css;
};

0 comments on commit b1cb7d9

Please sign in to comment.