Skip to content

Commit

Permalink
Split out updateAttributes into a separate function.
Browse files Browse the repository at this point in the history
  • Loading branch information
sepand committed Sep 14, 2016
1 parent 0fb2539 commit 963f33f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
13 changes: 9 additions & 4 deletions perf/exploration.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,16 @@
};

function elementOpen(tagName, key, statics) {
var node = coreElementOpen(tagName, key, elementCreated, statics);
coreElementOpen(tagName, key, elementCreated, statics);
}

function updateAttributes() {
var node = currentParent;
var data = node['__incrementalDomData'];

var attrsArr = data.attrsArr;
var attrsChanged = false;
var i = 3;
var i = 0;
var j = 0;

for (; i < arguments.length && j < attrsArr.length; i += 1, j += 1) {
Expand All @@ -245,7 +249,7 @@
newAttrs[attr] = undefined;
}

for (i = 3; i < arguments.length; i += 2) {
for (i = 0; i < arguments.length; i += 2) {
newAttrs[arguments[i]] = arguments[i + 1];
}

Expand Down Expand Up @@ -286,6 +290,7 @@
elementOpen: elementOpen,
elementClose: elementClose,
elementVoid: elementVoid,
text: text
text: text,
updateAttributes: updateAttributes
};
})(window);
26 changes: 14 additions & 12 deletions perf/list/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function ListRenderer(container, lib) {
elementVoid = lib.elementVoid,
elementOpen = lib.elementOpen,
elementClose = lib.elementClose,
text = lib.text;
text = lib.text,
ua = lib.updateAttributes;

function render(props) {
var items = props.items;
Expand All @@ -41,29 +42,30 @@ function ListRenderer(container, lib) {
var item = items[i];
var isSelected = selectedKeys[item.key];

elementOpen('div', item.key, itemStatics,
'aria-selected', isSelected);
elementOpen('div', item.key, itemStatics);
ua('aria-selected', isSelected);

elementOpen('div', null, checkboxStatics,
'aria-checked', 'false');
elementOpen('div', null, checkboxStatics);
ua('aria-checked', 'false');
elementClose('div');

elementOpen('div', null, starStatics,
'data-starred', item.starred,
'aria-label', item.starred ? 'Starred' : 'Not Starred');
elementOpen('div', null, starStatics);
ua('data-starred', item.starred,
'aria-label', item.starred ? 'Starred' : 'Not Starred');
elementClose('div');

elementOpen('span', null, senderStatics,
'title', item.sender);
elementOpen('span', null, senderStatics);
ua('title', item.sender);
text(item.sender);
elementClose('span');

elementOpen('span', null, subjectStatics,
'title', item.subject);
elementOpen('span', null, subjectStatics);
ua('title', item.subject);
text(item.subject);
elementClose('span');

elementOpen('span');
ua();
text(item.date);
elementClose('span');

Expand Down
14 changes: 9 additions & 5 deletions perf/mutation/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function MutationRenderer(container, lib) {
elementVoid = lib.elementVoid,
elementOpen = lib.elementOpen,
elementClose = lib.elementClose,
text = lib.text;
text = lib.text,
ua = lib.updateAttributes;

function render(props) {
var items = props.items;
Expand All @@ -47,17 +48,20 @@ function MutationRenderer(container, lib) {
var delta = item.value * item.change;

elementOpen('tr', item.key, itemStatics);
ua();
elementOpen('td', null, nameStatics);
elementOpen('a', null, null,
'href', item.name);
ua();
elementOpen('a');
ua('href', item.name);
text(item.name);
elementClose('a');
elementClose('td');
elementOpen('td', null, valueStatics);
ua();
text(item.value, toFixedTwo);
elementClose('td');
elementOpen('td', null, changeStatics,
'data-positive', item.change >= 0);
elementOpen('td', null, changeStatics);
ua('data-positive', item.change >= 0);
text(delta, toFixedTwo);
text(item.change, toPercent, toFixedTwo, wrapChange)
elementClose('td');
Expand Down

0 comments on commit 963f33f

Please sign in to comment.