Skip to content

Commit

Permalink
PR checks
Browse files Browse the repository at this point in the history
- set the config fallbacks back to argument value, to make sure there is only single source of default values for unprovided arguments.
- added label to button as well, to be consistent.
- updated some variable names for consistency.
  • Loading branch information
msawired committed Jun 5, 2023
1 parent 17bdbff commit b0aae5a
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions opc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ class OPC {
}

static slider(variableNameOrConfig, value, min = 0, max = null, step = null) {
let variableName
let label, description
let variableName, label, description;
if (typeof variableNameOrConfig === 'object') {
variableName = variableNameOrConfig.name;
value = variableNameOrConfig.value;
min = variableNameOrConfig.min ?? 0;
max = variableNameOrConfig.max ?? null;
step = variableNameOrConfig ?? null;
min = variableNameOrConfig.min ?? min;
max = variableNameOrConfig.max ?? max;
step = variableNameOrConfig ?? step;
label = variableNameOrConfig.label;
description = variableNameOrConfig.description;
} else {
Expand All @@ -39,11 +38,10 @@ class OPC {
}

static toggle(variableNameOrConfig, value = true) {
let variableName
let label, description
let variableName, label, description;
if (typeof variableNameOrConfig === 'object') {
variableName = variableNameOrConfig.name;
value = variableNameOrConfig.value ?? true;
value = variableNameOrConfig.value ?? value;
label = variableNameOrConfig.label;
description = variableNameOrConfig.description;
} else {
Expand All @@ -65,12 +63,11 @@ class OPC {
}

static palette(variableNameOrConfig, options, value = null) {
let variableName
let label, description
let variableName, label, description;
if (typeof variableNameOrConfig === 'object') {
variableName = variableNameOrConfig.name;
options = variableNameOrConfig.options;
value = variableNameOrConfig.value ?? null;
value = variableNameOrConfig.value ?? value;
label = variableNameOrConfig.label;
description = variableNameOrConfig.description;
} else {
Expand All @@ -92,11 +89,10 @@ class OPC {
return this.initVariable(this.options[variableName]);
}
static color(variableNameOrConfig, value = '#333333') {
let variableName
let label, description
let variableName, label, description;
if (typeof variableNameOrConfig === 'object') {
variableName = variableNameOrConfig.name;
value = variableNameOrConfig.value ?? null;
value = variableNameOrConfig.value ?? value;
label = variableNameOrConfig.label;
description = variableNameOrConfig.description;
} else {
Expand All @@ -118,13 +114,12 @@ class OPC {
}

static text(variableNameOrConfig, value, placeholder = null, maxChars = 1000) {
let variableName
let label, description
let variableName, label, description;
if (typeof variableNameOrConfig === 'object') {
variableName = variableNameOrConfig.name;
value = variableNameOrConfig.value ?? null;
placeholder = variableNameOrConfig.placeholder ?? null;
maxChars = variableNameOrConfig.maxChars ?? 1000;
value = variableNameOrConfig.value;
placeholder = variableNameOrConfig.placeholder ?? placeholder;
maxChars = variableNameOrConfig.maxChars ?? maxChars;
label = variableNameOrConfig.label;
description = variableNameOrConfig.description;
} else {
Expand All @@ -145,12 +140,12 @@ class OPC {
}
return this.initVariable(this.options[variableName]);
}
static button(variableNameOrConfig, buttonText) {
let variableName
let description
static button(variableNameOrConfig, value = 'Click Me!') {
let variableName, label, description;
if (typeof variableNameOrConfig === 'object') {
variableName = variableNameOrConfig.name;
buttonText = variableNameOrConfig.text;
value = variableNameOrConfig.value ?? value;
label = variableNameOrConfig.label ?? label;
description = variableNameOrConfig.description;
} else {
variableName = variableNameOrConfig;
Expand All @@ -165,8 +160,7 @@ class OPC {
this.options[variableName] = {
name: variableName,
type: 'button',
value: buttonText,
description
value, label, description
}
return this.initVariable(this.options[variableName]);
}
Expand Down

0 comments on commit b0aae5a

Please sign in to comment.