mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-02-21 00:23:02 +08:00
Added setOptions re-render check
This commit is contained in:
parent
4914c2d7a1
commit
b41f9a97e2
@ -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",
|
||||
|
@ -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])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user