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

Commit

Permalink
Fixes color formatting bug. Closes #81. (#83)
Browse files Browse the repository at this point in the history
* Fixes color formatting bug. Closes #81.

* Update comment.

* Fixes return type.
  • Loading branch information
chriscox authored Mar 24, 2017
1 parent 6612a2f commit fe62f83
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/Remixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ class Remixer {
* @param {any} selectedValue The new selected value.
*/
static cloneAndUpdateVariable(variable: Variable, selectedValue: any): void {
// First make sure selected value is in proper format.
selectedValue = variable.formatValue(selectedValue);

if (variable.selectedValue !== selectedValue) {
let clonedVariable = variable.clone();
this.attachedInstance._variables[variable.key] = clonedVariable;
Expand Down
13 changes: 13 additions & 0 deletions src/core/variables/ColorVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,17 @@ export class ColorVariable extends Variable implements IColorVariableParams {
variable.title = data.title;
return variable;
}

/**
* Returns color value formatted as string if not already.
* @override
* @param {any} value The value that should be formatted.
* @return {string} Return the original string or formatted string value.
*/
formatValue(value: any): string {
if (typeof value === "object") {
return ColorUtils.toRgbaString(value);
}
return value;
}
}
11 changes: 11 additions & 0 deletions src/core/variables/Variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,15 @@ export class Variable implements IVariableParams {
private sanitizeKey(key: string): string {
return key.split(" ").join("_");
}

/**
* Subclass should override this method and return a properly formatted value.
* For example, a ColorVariable may choose to return an rgba string when
* provided an RgbaColor object.
* @param {any} value The value that should be formatted.
* @return {any} Return either the original or formatted value.
*/
formatValue(value: any): any {
return value;
}
}

0 comments on commit fe62f83

Please sign in to comment.