Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Minification related refactoring #180

Closed
emileber opened this issue Oct 6, 2016 · 0 comments
Closed

Minification related refactoring #180

emileber opened this issue Oct 6, 2016 · 0 comments

Comments

@emileber
Copy link

emileber commented Oct 6, 2016

There's a lot of repeated code that could benefit from a refactoring, with minification in mind, without impeding readability.

Stuff like:

this.picker = $(this.options.template);
if (this.options.customClass) {
    this.picker.addClass(this.options.customClass);
}
if (this.options.inline) {
    this.picker.addClass('colorpicker-inline colorpicker-visible');
} else {
    this.picker.addClass('colorpicker-hidden');
}

could be changed to:

var options = this.options,
    $picker = this.picker = $(options.template);
if (options.customClass) {
    $picker.addClass(options.customClass);
}
if (options.inline) {
    $picker.addClass('colorpicker-inline colorpicker-visible');
} else {
    $picker.addClass('colorpicker-hidden');
}

And minified (with formatting to compare), it would look like this:

var o = this.options,
    p = this.picker = $(o.template);
if (o.customClass) {
    p.addClass(o.customClass);
}
if (o.inline) {
    p.addClass('colorpicker-inline colorpicker-visible');
} else {
    p.addClass('colorpicker-hidden');
}

Just in that small example, 44 bytes were saved. #BytesLivesMatter

This has to do with property names which can't be minified, so this.options can't be minified.

I'd be honored to propose a pull request (when I'll have time, like next week) if that's okay.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant