From 271cba918ac4cffcbc566eab87ebf85f6f05048b Mon Sep 17 00:00:00 2001 From: Andrej Date: Mon, 27 May 2019 07:02:04 +0700 Subject: [PATCH] Use ES module --- src/dat/controllers/CustomController.js | 1 + src/dat/gui/GUI.js | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/dat/controllers/CustomController.js b/src/dat/controllers/CustomController.js index 381c30c..fe82583 100644 --- a/src/dat/controllers/CustomController.js +++ b/src/dat/controllers/CustomController.js @@ -22,6 +22,7 @@ class CustomController extends Controller{ super(object, property); object.constructor( this ); + this.custom = true; } } diff --git a/src/dat/gui/GUI.js b/src/dat/gui/GUI.js index f3d79e1..4f1d87e 100644 --- a/src/dat/gui/GUI.js +++ b/src/dat/gui/GUI.js @@ -521,7 +521,7 @@ common.extend( object, property, { - custom: object instanceof CustomController, + custom: object.custom, factoryArgs: Array.prototype.slice.call(arguments, 2) } ); @@ -1154,7 +1154,8 @@ function recallSavedValue(gui, controller) { } function add(gui, object, property, params) { - if (!object instanceof CustomController && !params.custom && (object[property] === undefined)) { + var customObject = object.custom; + if (!customObject && !params.custom && (object[property] === undefined)) { throw new Error(`Object "${object}" has no property "${property}"`); } @@ -1162,12 +1163,12 @@ function add(gui, object, property, params) { if (params.color) { controller = new ColorController(object, property); - } else if(object instanceof CustomController && ( property === undefined )){ + } else if(customObject && ( property === undefined )){ controller = object; - } else if (!(object instanceof CustomController) && params.custom && (object[property] === undefined)) { + } else if (!(customObject) && params.custom && (object[property] === undefined)) { controller = new CustomController(object, property); }else { - const factoryArgs = object instanceof CustomController ? + const factoryArgs = customObject ? [property].concat(params.factoryArgs) : [object, property].concat(params.factoryArgs); controller = ControllerFactory.apply(gui, factoryArgs); } @@ -1183,7 +1184,7 @@ function add(gui, object, property, params) { const container = document.createElement('div'); const name = params.custom && ( controller instanceof CustomController === false ) ? - ( object instanceof CustomController ? object.domElement : new CustomController(object).domElement ) : document.createElement('span'); + ( customObject ? object.domElement : new CustomController(object).domElement ) : document.createElement('span'); if (!params.custom) name.innerHTML = controller.property; dom.addClass(name, 'property-name');