Skip to content

Code cleanup, DRY #104

Closed
Closed
@sirian

Description

@sirian

Look at
https://github.com/jsdom/cssstyle/blob/master/lib/allExtraProperties.js
https://github.com/jsdom/cssstyle/blob/master/lib/allProperties.js

var allExtraProperties = new Set();
module.exports = allExtraProperties;
allExtraProperties.add('background-position-x');
allExtraProperties.add('background-position-y');
allExtraProperties.add('background-repeat-x');
allExtraProperties.add('background-repeat-y');
allExtraProperties.add('color-interpolation');
...  // ~750 lines of same code in 2 files

Why not simply pass all of them in Set constructor? Or at least use loop

module.exports = new Set([
    'background-position-x',
    'background-position-y',
    'background-repeat-x',
    'background-repeat-y',
...
]);

UPD. or using arrays

var props = [
    'background-position-x',
    'background-position-y',
    'background-repeat-x',
    'background-repeat-y',
...
];

for (let i = 0; i < props.length; i++) {
    allExtraProperties.add(props[i])
}

These 2 files now takes 30kb of code. And 50% of this size is overhead of repeated 250 times allExtraProperties.add() and 500 times extraProperties.add()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions