Skip to content

Commit

Permalink
refactored endless loop detection again
Browse files Browse the repository at this point in the history
  • Loading branch information
knowthelist committed Oct 11, 2021
1 parent f93fa2b commit 684ce10
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 49 deletions.
30 changes: 15 additions & 15 deletions controls_ftui.txt
Expand Up @@ -2,27 +2,27 @@ UPD 2020-12-31_16:39:02 857 www/ftui/components/badge/badge.component.css
UPD 2020-12-31_16:39:02 578 www/ftui/components/badge/badge.component.js
UPD 2021-01-02_23:47:00 1186 www/ftui/components/button/button-nice.component.js
UPD 2021-04-29_00:13:11 2189 www/ftui/components/button/button.component.css
UPD 2021-10-04_21:00:42 2209 www/ftui/components/button/button.component.js
UPD 2021-10-11_22:43:44 2176 www/ftui/components/button/button.component.js
UPD 2021-10-06_07:56:00 1927 www/ftui/components/cell/cell.component.js
UPD 2020-12-31_16:39:02 722 www/ftui/components/chart/chart-controls.component.css
UPD 2020-12-31_16:39:02 3467 www/ftui/components/chart/chart-controls.component.js
UPD 2020-12-31_16:39:02 3652 www/ftui/components/chart/chart-data.component.js
UPD 2020-12-31_16:39:02 231 www/ftui/components/chart/chart.component.css
UPD 2021-02-01_19:44:32 8051 www/ftui/components/chart/chart.component.js
UPD 2021-03-01_21:00:54 358 www/ftui/components/checkbox/checkbox.component.css
UPD 2021-03-01_20:25:25 2292 www/ftui/components/checkbox/checkbox.component.js
UPD 2021-10-11_22:43:44 2257 www/ftui/components/checkbox/checkbox.component.js
UPD 2021-02-01_19:44:33 496 www/ftui/components/circlemenu/circlemenu.component.css
UPD 2021-02-04_22:45:27 1946 www/ftui/components/circlemenu/circlemenu.component.js
UPD 2021-02-06_14:53:43 1727 www/ftui/components/clock/clock.component.js
UPD 2020-12-31_16:39:02 2955 www/ftui/components/colorpicker/colorpicker.component.js
UPD 2021-10-11_22:55:43 2965 www/ftui/components/colorpicker/colorpicker.component.js
UPD 2021-01-28_21:05:34 574 www/ftui/components/column/column.component.js
UPD 2021-02-11_15:04:25 39 www/ftui/components/content/content.component.css
UPD 2021-04-09_17:39:16 1436 www/ftui/components/content/content.component.js
UPD 2021-10-03_12:43:52 4159 www/ftui/components/departure/departure.component.css
UPD 2021-10-08_11:29:53 12357 www/ftui/components/departure/departure.component.js
UPD 2021-02-01_19:44:34 496 www/ftui/components/dropdown/dropdown.component.css
UPD 2021-04-13_20:30:58 2134 www/ftui/components/dropdown/dropdown.component.js
UPD 2021-10-04_19:21:17 4554 www/ftui/components/element.component.js
UPD 2021-10-11_22:55:43 2102 www/ftui/components/dropdown/dropdown.component.js
UPD 2021-10-11_22:43:44 4707 www/ftui/components/element.component.js
UPD 2021-04-13_21:43:34 1576 www/ftui/components/grid/grid-tile.component.css
UPD 2021-02-09_23:03:56 847 www/ftui/components/grid/grid-tile.component.js
UPD 2021-05-26_22:39:03 3230 www/ftui/components/grid/grid.component.js
Expand All @@ -31,11 +31,11 @@ UPD 2021-10-07_00:26:40 2659 www/ftui/components/icon/icon.component.js
UPD 2021-02-03_14:43:36 2489 www/ftui/components/image/image.component.js
UPD 2021-02-03_14:48:37 8329 www/ftui/components/image/image_not_available.js
UPD 2021-10-03_12:50:26 997 www/ftui/components/knob/knob.component.css
UPD 2021-10-03_12:52:11 13082 www/ftui/components/knob/knob.component.js
UPD 2021-10-11_22:43:44 13097 www/ftui/components/knob/knob.component.js
UPD 2021-05-05_00:26:47 2454 www/ftui/components/label/label.component.js
UPD 2021-02-01_19:44:36 1816 www/ftui/components/main/main.component.js
UPD 2021-04-21_00:05:17 983 www/ftui/components/medialist/medialist.component.css
UPD 2021-04-21_00:17:50 3698 www/ftui/components/medialist/medialist.component.js
UPD 2021-10-11_22:55:43 3636 www/ftui/components/medialist/medialist.component.js
UPD 2020-12-31_16:39:02 1042 www/ftui/components/menu/menu-button.component.js
UPD 2020-12-31_16:39:02 351 www/ftui/components/menu/menu.component.css
UPD 2020-12-31_16:39:02 1526 www/ftui/components/menu/menu.component.js
Expand All @@ -45,17 +45,17 @@ UPD 2021-02-01_19:44:37 3362 www/ftui/components/popup/popup.component.js
UPD 2021-10-06_07:56:00 907 www/ftui/components/row/row.component.js
UPD 2021-04-10_12:07:56 1479 www/ftui/components/segment/segment-button.component.js
UPD 2021-02-05_18:44:32 1066 www/ftui/components/segment/segment.component.css
UPD 2021-10-04_19:36:40 2785 www/ftui/components/segment/segment.component.js
UPD 2021-10-11_22:43:44 2765 www/ftui/components/segment/segment.component.js
UPD 2021-02-01_19:44:37 3379 www/ftui/components/slider/slider.component.css
UPD 2021-10-03_11:02:55 3343 www/ftui/components/slider/slider.component.js
UPD 2021-10-11_20:00:39 3926 www/ftui/components/slider/slider.component.js
UPD 2021-10-08_12:44:54 2184 www/ftui/components/speak/speak.component.js
UPD 2021-02-15_22:41:38 1326 www/ftui/components/swiper/swiper.component.css
UPD 2021-03-01_21:02:03 4864 www/ftui/components/swiper/swiper.component.js
UPD 2021-10-11_22:43:44 4894 www/ftui/components/swiper/swiper.component.js
UPD 2021-03-01_20:27:03 1270 www/ftui/components/switch/switch.component.css
UPD 2021-03-01_20:28:00 1091 www/ftui/components/switch/switch.component.js
UPD 2021-01-05_19:05:30 680 www/ftui/components/tab/tab-view.component.js
UPD 2020-12-31_16:39:02 498 www/ftui/components/tab/tab.component.css
UPD 2021-02-01_19:44:39 2284 www/ftui/components/tab/tab.component.js
UPD 2021-10-11_22:43:44 2300 www/ftui/components/tab/tab.component.js
UPD 2020-12-31_16:39:02 524 www/ftui/components/title/title.component.js
UPD 2021-02-23_22:38:21 1541 www/ftui/components/view/view-item.component.css
UPD 2021-03-01_20:30:46 1638 www/ftui/components/view/view-item.component.js
Expand Down Expand Up @@ -103,7 +103,7 @@ UPD 2021-10-02_19:03:48 8070 www/ftui/examples/mobile_full.html
UPD 2021-02-01_19:44:48 5457 www/ftui/examples/mobile_plain.html
UPD 2021-02-01_19:44:48 4355 www/ftui/examples/popup.html
UPD 2021-02-05_19:09:46 2361 www/ftui/examples/segment.html
UPD 2021-04-15_11:43:14 3982 www/ftui/examples/slider.html
UPD 2021-10-11_18:49:22 3982 www/ftui/examples/slider.html
UPD 2021-10-07_19:32:34 1224 www/ftui/examples/speak.html
UPD 2021-02-22_09:18:14 14852 www/ftui/examples/swiper.html
UPD 2021-02-15_23:19:12 1352 www/ftui/examples/switch.html
Expand Down Expand Up @@ -695,13 +695,13 @@ UPD 2021-02-04_22:43:17 8388 www/ftui/modules/circle-menu/circle-menu.js
UPD 2021-02-01_19:44:50 5063 www/ftui/modules/circle-menu/circle-menu.min.js
UPD 2021-10-03_20:09:09 13600 www/ftui/modules/ftui/fhem.service.js
UPD 2021-10-04_19:52:18 7731 www/ftui/modules/ftui/ftui.app.js
UPD 2021-10-09_13:37:36 11485 www/ftui/modules/ftui/ftui.binding.js
UPD 2021-10-09_13:37:49 13055 www/ftui/modules/ftui/ftui.helper.js
UPD 2021-10-11_22:45:36 11321 www/ftui/modules/ftui/ftui.binding.js
UPD 2021-10-11_19:04:38 13055 www/ftui/modules/ftui/ftui.helper.js
UPD 2020-12-31_16:39:06 9247 www/ftui/modules/hocon/hocon.js
UPD 2020-12-31_16:39:06 3192 www/ftui/modules/hocon/hocon.min.js
UPD 2020-12-31_16:39:06 65427 www/ftui/modules/iro.js/iro.js
UPD 2020-12-31_16:39:06 32619 www/ftui/modules/iro.js/iro.min.js
UPD 2021-10-03_11:00:48 24669 www/ftui/modules/rangeable/rangeable.js
UPD 2021-10-11_18:36:02 24669 www/ftui/modules/rangeable/rangeable.js
UPD 2020-12-31_16:39:06 4564 www/ftui/modules/rangeable/rangeable.min.css
UPD 2021-10-03_11:02:26 12055 www/ftui/modules/rangeable/rangeable.min.js
UPD 2020-12-31_16:39:06 1922 www/ftui/modules/vanilla-notify/vanilla-notify.css
Expand Down
3 changes: 1 addition & 2 deletions www/ftui/components/button/button.component.js
Expand Up @@ -60,8 +60,7 @@ export class FtuiButton extends FtuiElement {

onClickEvent() {
this.playEffect();
this.value = this.getNextValue();
this.emitChangeEvent('value', this.value );
this.submitChange('value', this.getNextValue());
}

getNextValue() {
Expand Down
3 changes: 1 addition & 2 deletions www/ftui/components/checkbox/checkbox.component.js
Expand Up @@ -58,7 +58,7 @@ export class FtuiCheckbox extends FtuiElement {
const stateIndex = this.elementCheckbox.classList.contains('checked') ? 1 : 0;
const value = this.getStates()[stateIndex];
if (this.value !== value) {
this.value = value;
this.submitChange('value', value);
}
}

Expand All @@ -70,7 +70,6 @@ export class FtuiCheckbox extends FtuiElement {
} else {
this.elementCheckbox.classList.remove('checked');
}
this.emitChangeEvent('value', this.value );
}
}

Expand Down
4 changes: 2 additions & 2 deletions www/ftui/components/colorpicker/colorpicker.component.js
Expand Up @@ -89,8 +89,8 @@ export class FtuiColorpicker extends FtuiElement {
}

onColorChange(color) {
this.hex = color.hexString;
this.emitChangeEvent('color', color);
this.submitChange('hex',color.hexString);
this.submitChange('color',color);
}

updateOptions() {
Expand Down
3 changes: 1 addition & 2 deletions www/ftui/components/dropdown/dropdown.component.js
Expand Up @@ -64,8 +64,7 @@ export class FtuiDropdown extends FtuiElement {
}

onChange() {
this.value = this.selectElement.value;
this.emitChangeEvent('value', this.value);
this.submitChange('value', this.selectElement.value);
}

fillList() {
Expand Down
6 changes: 6 additions & 0 deletions www/ftui/components/element.component.js
Expand Up @@ -99,6 +99,12 @@ export class FtuiElement extends HTMLElement {
}
}

submitChange(property, value) {
this.isActiveChange[property] = true;
this[property] = value;
this.emitChangeEvent(property, value );
}

emitChangeEvent(attribute, value) {
this.emitEvent(attribute + 'Change', value);
}
Expand Down
2 changes: 1 addition & 1 deletion www/ftui/components/knob/knob.component.js
Expand Up @@ -167,7 +167,7 @@ export class FtuiKnob extends FtuiElement {

onChange(angle) {
if (!this.readonly && this.draw(angle)) {
this.value = this.angleToValue(angle);
this.submitChange('value', this.angleToValue(angle));
}
}

Expand Down
6 changes: 2 additions & 4 deletions www/ftui/components/medialist/medialist.component.js
Expand Up @@ -64,10 +64,8 @@ export class FtuiMedialist extends FtuiElement {
}

onClicked(media) {
this.file = media.file
this.track = media.track
this.emitChangeEvent('file', this.file);
this.emitChangeEvent('track', this.track);
this.submitChange('file',media.file);
this.submitChange('track',media.track);
}

clearCurrent() {
Expand Down
5 changes: 2 additions & 3 deletions www/ftui/components/segment/segment.component.js
Expand Up @@ -65,8 +65,7 @@ class FtuiSegment extends FtuiElement {
onClick(event) {
const target = event.target.closest('ftui-segment-button');
if (target) {
this.value = target.value;
this.emitChangeEvent('value', this.value );
this.submitChange('value', target.value);
}
}

Expand All @@ -87,7 +86,7 @@ class FtuiSegment extends FtuiElement {
}

setValueByIndex(index) {
this.value = this.segments[index].value;
this.submitChange('value', this.segments[index].value);
}

update() {
Expand Down
26 changes: 21 additions & 5 deletions www/ftui/components/slider/slider.component.js
Expand Up @@ -32,7 +32,7 @@ export class FtuiSlider extends FtuiElement {
step: this.step,
onStart: () => this.onSliderStart(),
onChange: (value) => this.onSliderChanged(Number(value)),
onEnd: () => this.onSliderEnd()
onEnd: (value) => this.onSliderEnd(Number(value))
});

this.updateRangable();
Expand Down Expand Up @@ -67,7 +67,7 @@ export class FtuiSlider extends FtuiElement {

static get properties() {
return {
debounce: 200,
debounce: 300,
step: 1,
tick: 100,
wideTick: 100,
Expand All @@ -87,7 +87,8 @@ export class FtuiSlider extends FtuiElement {
}

onAttributeChanged(name, newValue, oldValue) {
if (oldValue !== newValue) {
if (oldValue !== newValue && !this.isDragging) {
console.log('AttributeChanged',this.value, newValue)
this.updateRangable();
}
}
Expand All @@ -99,13 +100,28 @@ export class FtuiSlider extends FtuiElement {
onSliderChanged(value) {
if (this.value !== null && this.value !== value) {
if (this.isDragging) {
this.value = value;
console.log('SliderChanged',this.value, value)
this.updateProperty('value', value);
}
}
}

onSliderEnd() {
onSliderEnd(value) {
this.isDragging = false;
if (this.value !== null && this.value !== value) {
console.log('end',this.value, value)
this.updateProperty('value', value);
}
}

captureTime(target, name, descriptor) {
const original = descriptor.value;
descriptor.value = function (...args) {
console.time(name);
const result = original.apply(this, args);
console.timeEnd(name);
return result;
};
}

updateRangable() {
Expand Down
4 changes: 2 additions & 2 deletions www/ftui/components/swiper/swiper.component.js
Expand Up @@ -75,7 +75,7 @@ class FtuiSwiper extends FtuiElement {
entries.forEach(entry => {
entry.target.isVisible = ('isVisible' in entry) ? entry.isVisible : entry.isIntersecting;
if (entry.target.isVisible && this.value !== entry.target.id) {
this.value = entry.target.id;
this.submitChange('value', entry.target.id);
}
});
}
Expand Down Expand Up @@ -143,7 +143,7 @@ class FtuiSwiper extends FtuiElement {
setValueByIndex(index) {
const slide = this.slides[index];
if (slide) {
this.value = slide.id;
this.submitChange('value', slide.id);
}
}

Expand Down
2 changes: 1 addition & 1 deletion www/ftui/components/tab/tab.component.js
Expand Up @@ -74,7 +74,7 @@ class FtuiTab extends FtuiButton {
});

// activate clicked tab
this.value = 'on'
this.submitChange('value', 'on');
this.active = true;

// emit event
Expand Down
2 changes: 1 addition & 1 deletion www/ftui/examples/slider.html
Expand Up @@ -20,7 +20,7 @@
<link href="themes/ftui-theme.css" rel="stylesheet">
<link href="favicon.ico" rel="icon" type="image/x-icon" />

<meta name="debug" content="2">
<meta name="debug" content="0">

<title>FTUI Example Slider</title>
</head>
Expand Down
14 changes: 5 additions & 9 deletions www/ftui/modules/ftui/ftui.binding.js
Expand Up @@ -38,12 +38,10 @@ export class FtuiBinding {
config: '',
outputAttributes: new Set(),
observer: null,
isChanging: {},
changingDate: {},
sentValue: {}
}

this.element = element;
this.element.isActiveChange = {};
this.isThirdPartyElement = false;
this.config = {
input: { readings: {} },
Expand All @@ -63,10 +61,9 @@ export class FtuiBinding {
if (mutation.type == 'attributes') {
const attributeName = mutation.attributeName;
const attributeValue = mutation.target[attributeName] || mutation.target.getAttribute(attributeName);
const isTooOld = this.private.changingDate[attributeName] < Date.now() - 300;
if (!this.private.isChanging[attributeName] || isTooOld) {
// send to FHEM when targets are defined
this.private.isChanging[attributeName] = false;
if (this.element.isActiveChange[attributeName]) {
// send to FHEM when it is an active change by a user
this.element.isActiveChange[attributeName] = false;
this.handleAttributeChanged(attributeName, attributeValue);
}
}
Expand All @@ -88,8 +85,7 @@ export class FtuiBinding {
Object.entries(readingAttributeMap)
.forEach(([attribute, options]) => {
// update marker to avoid infinity loops
this.private.isChanging[attribute] = true;
this.private.changingDate[attribute] = Date.now();
this.element.isActiveChange[attribute] = false;
const value = readingData[options.property];
if (ftuiHelper.isDefined(value)) {
const filteredValue = this.filterValue(value, options.filter);
Expand Down

0 comments on commit 684ce10

Please sign in to comment.