Added validation feature for window.app object.
This provides possibilities of more reliable testing and debugging. See the comments in "docstate.js" file. Signed-off-by: Gökay Şatır <gokaysatir@collabora.com> Change-Id: I28ba2098cbe7e206f363fb2b0acbf5c5c2bf155d
This commit is contained in:
parent
4f4c11a886
commit
7c6c16f46b
1 changed files with 36 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
|||
/* global Proxy */
|
||||
|
||||
window.app = { // Shouldn't have any functions defined.
|
||||
definitions: {}, // Class instances are created using definitions under this variable.
|
||||
dpiScale: window.devicePixelRatio,
|
||||
|
@ -43,3 +45,37 @@ window.app = { // Shouldn't have any functions defined.
|
|||
socket: window.app.socket,
|
||||
console: window.app.console,
|
||||
};
|
||||
|
||||
var activateValidation = false;
|
||||
|
||||
if (activateValidation) {
|
||||
/*
|
||||
For debugging purposes.
|
||||
|
||||
* Easier debugging.
|
||||
* Value range checks.
|
||||
|
||||
It logs the changes of the variables of "window.app" object.
|
||||
This provides debugging of window.app object and makes easier use of these global states of the document.
|
||||
window.app object can contain cursor position etc. variables related to document state.
|
||||
One needs to only watch the data structure and add new variables into related sub-object (file, view, tile etc.).
|
||||
|
||||
This validator also enables global data validation.
|
||||
If a variable of window.app should stay in a specified range:
|
||||
* One can add a check for that variable into "set" function below.
|
||||
This validation feature may also be useful with Cypress tests and Javascript unit tests.
|
||||
|
||||
This first version only contains the logging of the changes.
|
||||
*/
|
||||
var validator = {
|
||||
set: function(obj, prop, value) {
|
||||
// The default behavior to store the value
|
||||
obj[prop] = value;
|
||||
console.log('window.app property changed: ' + prop, value);
|
||||
// Indicate success
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
window.app = new Proxy(window.app, validator);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue