Skip to content

Commit

Permalink
dynamic styles refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
beyaz committed Jan 13, 2024
1 parent 47394f1 commit 813b2f5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2692,50 +2692,44 @@ function ProcessDynamicCssClasses(dynamicStyles)
return;
}

let hasChange = false;

// remove all related css of component
for (var key in dynamicStyles)
{
if (dynamicStyles.hasOwnProperty(key))
{
const cssSelector = key;
const cssBody = dynamicStyles[key];

let shouldInsert = true;
var componentUniqueIdentifier = GetComponentUniqueIdentifierFromCssSelector(cssSelector);

for (var i = 0; i < DynamicStyles.length; i++)
// remove all related css of component
for (let i = 0; i < DynamicStyles.length; i++)
{
if (DynamicStyles[i].cssSelector === cssSelector)
if (DynamicStyles[i].componentUniqueIdentifier === componentUniqueIdentifier)
{
if (DynamicStyles[i].cssBody === cssBody)
{
shouldInsert = false;
break;
}

hasChange = true;
DynamicStyles[i].cssBody = cssBody;
break;
DynamicStyles.splice(i, 1);
i--;
}
}

if (shouldInsert)
{
hasChange = true;

DynamicStyles.push({
cssSelector: cssSelector,
cssBody: cssBody,
componentUniqueIdentifier: GetComponentUniqueIdentifierFromCssSelector(cssSelector)
});
}
}
}

if (hasChange)
// Add new records
for (var key in dynamicStyles)
{
ApplyDynamicStylesToDom();
if (dynamicStyles.hasOwnProperty(key))
{
const cssSelector = key;
const cssBody = dynamicStyles[key];

DynamicStyles.push({
cssSelector: cssSelector,
cssBody: cssBody,
componentUniqueIdentifier: GetComponentUniqueIdentifierFromCssSelector(cssSelector)
});
}
}

ApplyDynamicStylesToDom();
}

function ApplyDynamicStylesToDom()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2692,50 +2692,44 @@ function ProcessDynamicCssClasses(dynamicStyles)
return;
}

let hasChange = false;

// remove all related css of component
for (var key in dynamicStyles)
{
if (dynamicStyles.hasOwnProperty(key))
{
const cssSelector = key;
const cssBody = dynamicStyles[key];

let shouldInsert = true;
var componentUniqueIdentifier = GetComponentUniqueIdentifierFromCssSelector(cssSelector);

for (var i = 0; i < DynamicStyles.length; i++)
// remove all related css of component
for (let i = 0; i < DynamicStyles.length; i++)
{
if (DynamicStyles[i].cssSelector === cssSelector)
if (DynamicStyles[i].componentUniqueIdentifier === componentUniqueIdentifier)
{
if (DynamicStyles[i].cssBody === cssBody)
{
shouldInsert = false;
break;
}

hasChange = true;
DynamicStyles[i].cssBody = cssBody;
break;
DynamicStyles.splice(i, 1);
i--;
}
}

if (shouldInsert)
{
hasChange = true;

DynamicStyles.push({
cssSelector: cssSelector,
cssBody: cssBody,
componentUniqueIdentifier: GetComponentUniqueIdentifierFromCssSelector(cssSelector)
});
}
}
}

if (hasChange)
// Add new records
for (var key in dynamicStyles)
{
ApplyDynamicStylesToDom();
if (dynamicStyles.hasOwnProperty(key))
{
const cssSelector = key;
const cssBody = dynamicStyles[key];

DynamicStyles.push({
cssSelector: cssSelector,
cssBody: cssBody,
componentUniqueIdentifier: GetComponentUniqueIdentifierFromCssSelector(cssSelector)
});
}
}

ApplyDynamicStylesToDom();
}

function ApplyDynamicStylesToDom()
Expand Down

0 comments on commit 813b2f5

Please sign in to comment.