Skip to content

Commit

Permalink
Add function to get hash of a list of style properties for an element #…
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkfranz committed Dec 8, 2017
1 parent fb47597 commit cdf508d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/style/get-for-ele.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,48 @@ styfn.getPropsList = function( propsObj ){
return rstyle;
};

let getPropIntIterator = ( ele, propNames ) => {
let entry = { done: false, value: 0 };

let propIndex = 0;
let nProps = propNames.length;

let prop = null;
let strValue = null;
let strIndex = 0;
let strLength = 0;

let next = () => {
if( propIndex < nProps ){
if( prop === null ){
prop = ele.pstyle( propNames[ propIndex ] );
strValue = prop.strValue;
strIndex = 0;
strLength = strValue.length;
}

if( strIndex < strLength ){
entry.value = strValue.charCodeAt( strIndex++ );
} else {
propIndex++;
prop = null;

return next();
}
} else {
entry.done = true;
}

return entry;
};

let iter = { next };

return iter;
};

styfn.getPropertiesHash = function( ele, propNames, seed ){
return util.hashIterableInts( getPropIntIterator( ele, propNames, seed ) );
};

module.exports = styfn;

0 comments on commit cdf508d

Please sign in to comment.