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

Updates core variable interfaces due to Constants refactor. #16

Merged
merged 2 commits into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions src/core/Remixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
* under the License.
*/

import * as vars from "./variables/variableTypes";
import { Constants as CONST } from "../lib/Constants";
import { BooleanVariable } from "./variables/BooleanVariable";
import { ColorVariable } from "./variables/ColorVariable";
import { KeyCode, KeyEvent, CSS } from "../lib/Constants";
import { LocalStorage } from "../lib/LocalStorage";
import { Messaging } from "../lib/Messaging";
import { VariableCallback, VariableKeyMap } from "./variables/Variable";
import { NumberVariable } from "./variables/NumberVariable";
import { RangeVariable } from "./variables/RangeVariable";
import { StringVariable } from "./variables/StringVariable";
import { Variable, VariableCallback, VariableKeyMap } from "./variables/Variable";

/**
* The Remixer class is a singleton class that keeps track of all the Variables
Expand Down Expand Up @@ -61,7 +65,7 @@ class Remixer {
private appendFrameToBody(): void {
if (!this._frameElement) {
let frame = document.createElement("IFRAME") as HTMLFrameElement;
frame.id = CONST.ID_OVERLAY_FRAME;
frame.id = CSS.RMX_OVERLAY_FRAME;
frame.setAttribute("src", "../dist/overlay.html");
frame.setAttribute("style", "position:fixed; border:0; width:400px; height:100%; top:0; right:0; z-index:999999;");
frame.setAttribute("sandbox", "allow-scripts allow-same-origin");
Expand All @@ -75,8 +79,8 @@ class Remixer {
* @private
*/
private addKeyListener(): void {
document.addEventListener(CONST.KEY_EVENT_DOWN, (e: KeyboardEvent) => {
if (e.keyCode === CONST.KEY_CODE_ESC) {
document.addEventListener(KeyEvent.DOWN, (e: KeyboardEvent) => {
if (e.keyCode === KeyCode.ESC) {
Messaging.postToFrame(Messaging.type.ToggleVisibility);
}
});
Expand Down Expand Up @@ -108,8 +112,8 @@ class Remixer {
* when the Variable is updated.
* @return {BooleanVariable}
*/
static addBooleanVariable(key: string, defaultValue: boolean, callback?: VariableCallback): vars.BooleanVariable {
let variable = new vars.BooleanVariable(key, defaultValue, callback);
static addBooleanVariable(key: string, defaultValue: boolean, callback?: VariableCallback): BooleanVariable {
let variable = new BooleanVariable(key, defaultValue, callback);
this.addVariable(variable);
return variable;
}
Expand All @@ -125,8 +129,8 @@ class Remixer {
* when the Variable is updated.
* @return {RangeVariable}
*/
static addRangeVariable(key: string, defaultValue: number, minValue: number, maxValue: number, increment: number, callback?: VariableCallback): vars.RangeVariable {
let variable = new vars.RangeVariable(key, defaultValue, minValue, maxValue, increment, callback);
static addRangeVariable(key: string, defaultValue: number, minValue: number, maxValue: number, increment: number, callback?: VariableCallback): RangeVariable {
let variable = new RangeVariable(key, defaultValue, minValue, maxValue, increment, callback);
this.addVariable(variable);
return variable;
}
Expand All @@ -140,8 +144,8 @@ class Remixer {
* when the Variable is updated.
* @return {StringVariable}
*/
static addStringVariable(key: string, defaultValue: string, possibleValues?: Array<string>, callback?: VariableCallback): vars.StringVariable {
let variable = new vars.StringVariable(key, defaultValue, possibleValues, callback);
static addStringVariable(key: string, defaultValue: string, possibleValues?: Array<string>, callback?: VariableCallback): StringVariable {
let variable = new StringVariable(key, defaultValue, possibleValues, callback);
this.addVariable(variable);
return variable;
}
Expand All @@ -155,8 +159,8 @@ class Remixer {
* when the Variable is updated.
* @return {NumberVariable}
*/
static addNumberVariable(key: string, defaultValue: number, possibleValues?: Array<number>, callback?: VariableCallback): vars.NumberVariable {
let variable = new vars.NumberVariable(key, defaultValue, possibleValues, callback);
static addNumberVariable(key: string, defaultValue: number, possibleValues?: Array<number>, callback?: VariableCallback): NumberVariable {
let variable = new NumberVariable(key, defaultValue, possibleValues, callback);
this.addVariable(variable);
return variable;
}
Expand All @@ -170,8 +174,8 @@ class Remixer {
* when the Variable is updated.
* @return {ColorVariable}
*/
static addColorVariable(key: string, defaultValue: string, possibleValues?: Array<string>, callback?: VariableCallback): vars.ColorVariable {
let variable = new vars.ColorVariable(key, defaultValue, possibleValues, callback);
static addColorVariable(key: string, defaultValue: string, possibleValues?: Array<string>, callback?: VariableCallback): ColorVariable {
let variable = new ColorVariable(key, defaultValue, possibleValues, callback);
this.addVariable(variable);
return variable;
}
Expand All @@ -183,7 +187,7 @@ class Remixer {
* @static
* @param {Variable} variable The variable to add.
*/
private static addVariable(variable: vars.Variable): void {
private static addVariable(variable: Variable): void {
let key: string = variable.key;
let existingVariable = this.getVariable(key);
if (existingVariable) {
Expand Down Expand Up @@ -217,16 +221,16 @@ class Remixer {
* Returns an array of Variables from the Remixer shared instance.
* @return {Array<Variable>} Array of Variables.
*/
get variablesArray(): Array<vars.Variable> {
get variablesArray(): Array<Variable> {
return Object.keys(this._variables).map(key => this._variables[key]);
}

/**
* Returns an Variable for a given key from the Remixer shared instance.
* @static
* @return {Array<vars.Variable>} Array of Variables.
* @return {Array<Variable>} Array of Variables.
*/
static getVariable(key: string): vars.Variable {
static getVariable(key: string): Variable {
return this._sharedInstance._variables[key];
}

Expand All @@ -236,15 +240,15 @@ class Remixer {
* @param {Variable} variable The Variable to update.
* @param {any} selectedValue The new selected value.
*/
static updateVariable(variable: vars.Variable, selectedValue: any): void {
static updateVariable(variable: Variable, selectedValue: any): void {
variable.selectedValue = selectedValue;
}

/**
* Saves the Variable to local storage.
* @param {Variable} variable The Variable to save.
*/
static saveVariable(variable: vars.Variable): void {
static saveVariable(variable: Variable): void {
LocalStorage.saveVariable(variable);
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/core/variables/BooleanVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* under the License.
*/

import { Constants as CONST } from "../../lib/Constants";
import { SerializableData } from "../../lib/LocalStorage";
import { Variable, VariableType, VariableCallback } from "./Variable";
import { Variable, VariableParams, VariableCallback } from "./Variable";
import { VariableType } from "../../lib/Constants";

/**
* Interface for a class that represents a type of Variable for boolean values.
* @interface
* @extends VariableType
* @extends VariableParams
*/
interface BooleanVariableType extends VariableType {
interface BooleanVariableParams extends VariableParams {
defaultValue: boolean;
selectedValue: boolean;
}
Expand All @@ -32,9 +32,9 @@ interface BooleanVariableType extends VariableType {
* A class representing a type of Variable for boolean values.
* @class
* @extends Variable
* @implements {BooleanVariableType}
* @implements {BooleanVariableParams}
*/
export class BooleanVariable extends Variable implements BooleanVariableType {
export class BooleanVariable extends Variable implements BooleanVariableParams {

/**
* Creates an instance of a BooleanVariable.
Expand All @@ -45,7 +45,7 @@ export class BooleanVariable extends Variable implements BooleanVariableType {
* @return {BooleanVariable}
*/
constructor(key: string, defaultValue: boolean, callback?: VariableCallback) {
super(key, CONST.VARIABLE_TYPE_BOOLEAN, defaultValue, callback);
super(key, VariableType.BOOLEAN, defaultValue, callback);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/core/variables/ColorVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* under the License.
*/

import { Constants as CONST } from "../../lib/Constants";
import { SerializableData } from "../../lib/LocalStorage";
import { Variable, VariableListType, VariableCallback } from "./Variable";
import { Variable, VariableListParams, VariableCallback } from "./Variable";
import { VariableType } from "../../lib/Constants";

/**
* Interface for a class that represents a type of Variable for color values.
* @interface
* @extends VariableListType
* @extends VariableListParams
*/
interface ColorVariableType extends VariableListType {
interface ColorVariableParams extends VariableListParams {
defaultValue: string;
selectedValue: string;
possibleValues?: Array<string>;
Expand All @@ -33,9 +33,9 @@ interface ColorVariableType extends VariableListType {
* A class representing a type of Variable for color values.
* @class
* @extends Variable
* @implements {ColorVariableType}
* @implements {ColorVariableParams}
*/
export class ColorVariable extends Variable implements ColorVariableType {
export class ColorVariable extends Variable implements ColorVariableParams {

/**
* Creates an instance of a ColorVariable.
Expand All @@ -47,7 +47,7 @@ export class ColorVariable extends Variable implements ColorVariableType {
* @return {ColorVariable}
*/
constructor(key: string, defaultValue: string, possibleValues?: Array<string>, callback?: VariableCallback) {
super(key, CONST.VARIABLE_TYPE_COLOR, defaultValue, callback);
super(key, VariableType.COLOR, defaultValue, callback);
this.possibleValues = possibleValues;
}

Expand Down
14 changes: 7 additions & 7 deletions src/core/variables/NumberVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* under the License.
*/

import { Constants as CONST } from "../../lib/Constants";
import { SerializableData } from "../../lib/LocalStorage";
import { Variable, VariableListType, VariableCallback } from "./Variable";
import { Variable, VariableListParams, VariableCallback } from "./Variable";
import { VariableType } from "../../lib/Constants";

/**
* Interface for a class that represents a type of Variable for number values.
* @interface
* @extends VariableListType
* @extends VariableListParams
*/
interface NumberVariableType extends VariableListType {
interface NumberVariableParams extends VariableListParams {
defaultValue: number;
selectedValue: number;
possibleValues?: Array<number>;
Expand All @@ -33,9 +33,9 @@ interface NumberVariableType extends VariableListType {
* A class representing a type of Variable for number values.
* @class
* @extends Variable
* @implements {NumberVariableType}
* @implements {NumberVariableParams}
*/
export class NumberVariable extends Variable implements NumberVariableType {
export class NumberVariable extends Variable implements NumberVariableParams {

/**
* Creates an instance of a ColorVariable.
Expand All @@ -47,7 +47,7 @@ export class NumberVariable extends Variable implements NumberVariableType {
* @return {[NumberVariable]}
*/
constructor(key: string, defaultValue: number, possibleValues?: Array<number>, callback?: VariableCallback) {
super(key, CONST.VARIABLE_TYPE_NUMBER, defaultValue, callback);
super(key, VariableType.NUMBER, defaultValue, callback);
this.possibleValues = possibleValues;
}

Expand Down
14 changes: 7 additions & 7 deletions src/core/variables/RangeVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* under the License.
*/

import { Constants as CONST } from "../../lib/Constants";
import { SerializableData } from "../../lib/LocalStorage";
import { Variable, VariableType, VariableCallback } from "./Variable";
import { Variable, VariableParams, VariableCallback } from "./Variable";
import { VariableType } from "../../lib/Constants";

/**
* Interface for a class that represents a type of Variable for a range of values.
* @interface
* @extends VariableType
* @extends VariableParams
*/
interface RangeVariableType extends VariableType {
interface RangeVariableParams extends VariableParams {
defaultValue: number;
selectedValue: number;
minValue: number;
Expand All @@ -35,9 +35,9 @@ interface RangeVariableType extends VariableType {
* A class representing a type of Variable for a range of values.
* @class
* @extends Variable
* @implements {RangeVariableType}
* @implements {RangeVariableParams}
*/
export class RangeVariable extends Variable implements RangeVariableType {
export class RangeVariable extends Variable implements RangeVariableParams {

/**
* Creates an instance of a RangeVariable.
Expand All @@ -50,7 +50,7 @@ export class RangeVariable extends Variable implements RangeVariableType {
* @return {RangeVariable}
*/
constructor(key: string, defaultValue: number, minValue: number, maxValue: number, increment: number, callback?: VariableCallback) {
super(key, CONST.VARIABLE_TYPE_RANGE, defaultValue, callback);
super(key, VariableType.RANGE, defaultValue, callback);
this.minValue = minValue;
this.maxValue = maxValue;
this.increment = increment;
Expand Down
14 changes: 7 additions & 7 deletions src/core/variables/StringVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* under the License.
*/

import { Constants as CONST } from "../../lib/Constants";
import { SerializableData } from "../../lib/LocalStorage";
import { Variable, VariableListType, VariableCallback } from "./Variable";
import { Variable, VariableListParams, VariableCallback } from "./Variable";
import { VariableType } from "../../lib/Constants";

/**
* Interface for a class that represents a type of Variable for string values.
* @interface
* @extends VariableListType
* @extends VariableListParams
*/
interface StringVariableType extends VariableListType {
interface StringVariableParams extends VariableListParams {
defaultValue: string;
selectedValue: string;
possibleValues?: Array<string>;
Expand All @@ -33,9 +33,9 @@ interface StringVariableType extends VariableListType {
* A class representing a type of Variable for string values.
* @class
* @extends Variable
* @implements {StringVariableType}
* @implements {StringVariableParams}
*/
export class StringVariable extends Variable implements StringVariableType {
export class StringVariable extends Variable implements StringVariableParams {

/**
* Creates an instance of a StringVariable.
Expand All @@ -47,7 +47,7 @@ export class StringVariable extends Variable implements StringVariableType {
* @return {StringVariable}
*/
constructor(key: string, defaultValue: string, possibleValues?: Array<string>, callback?: VariableCallback) {
super(key, CONST.VARIABLE_TYPE_STRING, defaultValue, callback);
super(key, VariableType.STRING, defaultValue, callback);
this.possibleValues = possibleValues;
}

Expand Down
10 changes: 5 additions & 5 deletions src/core/variables/Variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
* under the License.
*/

import { Constants as CONST } from "../../lib/Constants";
import { SerializableData } from "../../lib/LocalStorage";
import { remixer } from "../Remixer";

/**
* Interface for a class that represents a type a Variable.
* @interface
*/
export interface VariableType {
export interface VariableParams {
key: string;
title: string;
dataType: string;
Expand All @@ -34,8 +33,9 @@ export interface VariableType {
/**
* Interface for a class that represents a type a Variable with possible values.
* @interface
* @extends VariableParams
*/
export interface VariableListType extends VariableType {
export interface VariableListParams extends VariableParams {
possibleValues?: Array<any>;
}

Expand All @@ -59,9 +59,9 @@ export interface VariableKeyMap {
/**
* A class representing a type a Variable.
* @class
* @implements {VariableType}
* @implements {VariableParams}
*/
export class Variable implements VariableType {
export class Variable implements VariableParams {

/**
* Creates an instance of a Variable.
Expand Down
Loading