Added setOptions re-render check

This commit is contained in:
Francisco Hodge 2020-04-22 21:52:17 -04:00
parent 4914c2d7a1
commit b41f9a97e2
2 changed files with 29 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{
"name": "simple-keyboard",
"version": "2.28.73",
"version": "2.29.0",
"description": "On-screen Javascript Virtual Keyboard",
"main": "build/index.js",
"types": "build/index.d.ts",

View File

@ -468,19 +468,37 @@ class SimpleKeyboard {
* Set new option or modify existing ones after initialization.
* @param {object} options The options to set
*/
setOptions(options) {
options = options || {};
setOptions(options = {}) {
const changedOptions = this.changedOptions(options);
this.options = Object.assign(this.options, options);
/**
* Some option changes require adjustments before re-render
*/
this.onSetOptions(options);
if (changedOptions.length) {
if (this.options.debug) {
console.log("changedOptions", changedOptions);
}
/**
* Rendering
*/
this.render();
/**
* Some option changes require adjustments before re-render
*/
this.onSetOptions(options);
/**
* Rendering
*/
this.render();
}
}
/**
* Detecting changes to non-function options
* This allows us to ascertain whether a button re-render is needed
*/
changedOptions(newOptions) {
return Object.keys(newOptions).filter(
optionName =>
JSON.stringify(newOptions[optionName]) !==
JSON.stringify(this.options[optionName])
);
}
/**