add flags and cooldown to prevent read/write clash
This commit is contained in:
parent
cfbcef04b3
commit
78fd39ca65
1 changed files with 52 additions and 29 deletions
|
@ -5,6 +5,7 @@ import texts from "/scripts/mapping/read.js";
|
|||
import Tabs from "/scripts/GUI/tabs.js";
|
||||
import {global, observe} from "/scripts/secretariat.js";
|
||||
import {URLs} from "/scripts/utils/URLs.js";
|
||||
import wait from "/scripts/utils/wait.js";
|
||||
|
||||
export default class windowman {
|
||||
elements = {};
|
||||
|
@ -291,6 +292,11 @@ export default class windowman {
|
|||
|
||||
/* Run this function if you would like to synchronize with data. */
|
||||
async sync() {
|
||||
// Prepare flags.
|
||||
this[`state`] = {};
|
||||
this[`state`][`read/write`] = 0;
|
||||
|
||||
// Set the linked elements.
|
||||
this[`elements`][`linked`] = (this[`elements`][`linked`]) ? this[`elements`][`linked`] : {};
|
||||
|
||||
const fill = () => {
|
||||
|
@ -314,9 +320,14 @@ export default class windowman {
|
|||
(this[`elements`][`linked`][`show`][data[`source`]] ? this[`elements`][`linked`][`show`][data[`source`]].length : false)
|
||||
? this[`elements`][`linked`][`show`][data[`source`]].push(input_element)
|
||||
: this[`elements`][`linked`][`show`][data[`source`]] = [input_element];
|
||||
|
||||
// Remove the attribute.
|
||||
input_element.removeAttribute(`data-store`);
|
||||
});
|
||||
};
|
||||
|
||||
// Wait until this[`state`][`read/write`] is >= 0; don't clash.
|
||||
wait((this[`state`][`read/write`] ? this[`state`][`read/write`] >= 0 : true)).then(() => {
|
||||
(this[`elements`][`linked`][`show`] ? Object.keys(Object.keys(this[`elements`][`linked`][`show`])).length : false)
|
||||
? (Object.keys(this[`elements`][`linked`][`show`])).forEach((SOURCE) => {
|
||||
(this[`elements`][`linked`][`show`][SOURCE] ? this[`elements`][`linked`][`show`][SOURCE].length : false)
|
||||
|
@ -346,6 +357,7 @@ export default class windowman {
|
|||
|
||||
})
|
||||
: false;
|
||||
})
|
||||
}
|
||||
|
||||
const enable = () => {
|
||||
|
@ -409,11 +421,19 @@ export default class windowman {
|
|||
switch (ELEMENT[`type`]) {
|
||||
case `checkbox`:
|
||||
ELEMENT[`event`] = () => {
|
||||
// Set flag to prevent reading.
|
||||
this[`state`][`read/write`] = -1;
|
||||
global.write(SOURCE, ELEMENT.checked, ELEMENT[`storage`][`source`]);
|
||||
|
||||
// Unlock reading.
|
||||
this[`state`][`read/write`] = 0;
|
||||
};
|
||||
break;
|
||||
default:
|
||||
ELEMENT[`event`] = () => {
|
||||
// Set flag to write to prevent reading.
|
||||
this[`state`][`read/write`] = -1;
|
||||
|
||||
if (ELEMENT[`type`].includes(`num`) || ELEMENT[`type`].includes(`range`)) {
|
||||
ELEMENT.value = ((((ELEMENT.hasAttribute(`min`)) ? ELEMENT.value < parseFloat(ELEMENT.getAttribute(`min`)) : false))
|
||||
? ELEMENT.getAttribute(`min`)
|
||||
|
@ -429,6 +449,9 @@ export default class windowman {
|
|||
: ELEMENT.value;
|
||||
|
||||
global.write(SOURCE, VALUE, ELEMENT[`storage`][`source`]);
|
||||
|
||||
// Finish writing.
|
||||
this[`state`][`read/write`] = 0;
|
||||
};
|
||||
break;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue