guify icon indicating copy to clipboard operation
guify copied to clipboard

Variable binding does not work

Open copark86 opened this issue 4 years ago • 0 comments

I was testing the following example code but found that the variable binding is not working.

When I run the code, "Stepped Range" starts with 8 instead of 64 and the log message in the call-back always prints 64 regardless of the slider value. Do you see any problem with the code?

	var container_gui = document.getElementById("gui-container");
	container_gui.style.display = "none";
	// Create the GUI
	var gui2 = new guify({
		theme: 'dark', // dark, light, yorha, or theme object
		align: 'right', // left, right
		width: 300,
		barMode: 'none', // none, overlay, above, offset
		panelMode: 'inner',
		opacity: 0.95,
		root: container_gui,
		open: false
	});

	var steppedNumber = 64;
	gui2.Register({
		type: 'range',
		label: 'Stepped Range',
		min: 8, max: 64, step: 8,
		object: this, property: "steppedNumber",
		onChange: (data) => {
			console.log(steppedNumber);
		}
	});

Edit 1: I have track the problem and found the opts.object is undefined in the following code. https://github.com/colejd/guify/blob/beae4ec79261058ba96ceceb2e94e6f79cf547e7/src/gui.js#L190

"object: this" was not defined as the code was in a module.

''

Is there a way to fix this without moving the code out of the module? It should be a module due to "import".

copark86 avatar Dec 25 '21 17:12 copark86