Skip to content

Commit 9a6288e

Browse files
committed
quintuple flushable rect cashing
1 parent ac1f3e7 commit 9a6288e

File tree

9 files changed

+69
-9
lines changed

9 files changed

+69
-9
lines changed

blocks/button/ButtonAbstract.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default class ButtonAbstract {
3636
*/
3737
static _shadowFunction(args) {
3838
const
39-
rect = args.eventControlElement.domElement.getBoundingClientRect(),
39+
rect = args.eventControlElement.rect,
4040
hover = [
4141
args.event.clientX - rect.left,
4242
args.event.clientY - rect.top

blocks/card/CardAbstract.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import LA from '../../js/math/LinearAlgebra.js';
88
* the effects
99
* @abstract
1010
*/
11-
export default class cardAbstract {
11+
export default class CardAbstract {
1212
/**
1313
* @param {String} [modifier = ''] Modifier of the card block.
1414
* Default '' means mo modifier.
@@ -21,8 +21,8 @@ export default class cardAbstract {
2121
modifier = '',
2222
postTransformFunction,
2323
postShadowFunction,
24-
transformationFunction = cardAbstract._transformationFunction,
25-
shadowFunction = cardAbstract._shadowFunction
24+
transformationFunction = CardAbstract._transformationFunction,
25+
shadowFunction = CardAbstract._shadowFunction
2626
) {
2727

2828
this._throwIfAbstractClass();
@@ -40,6 +40,11 @@ export default class cardAbstract {
4040
);
4141
}
4242

43+
flushRectCaches() {
44+
this._ct.flushRectCaches();
45+
this._cm.flushRectCaches();
46+
}
47+
4348
/**
4449
* function which returns the correct transformation for a standard
4550
* card block depending on the absolute position on screen and the
@@ -84,7 +89,7 @@ export default class cardAbstract {
8489
*/
8590
static _shadowFunction(args) {
8691
const
87-
rect = args.eventControlElement.domElement.getBoundingClientRect(),
92+
rect = args.eventControlElement.rect,
8893
hover = [
8994
args.event.clientX - rect.left,
9095
args.event.clientY - rect.top

blocks/card/card.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,14 @@ window.addEventListener('load', () => {
1919
// TODO: do i need this? In which case?
2020
// C.doEvent(e);
2121
});
22+
23+
const onMove = () => {
24+
CP.flushRectCaches();
25+
CM.flushRectCaches();
26+
//C.flushRectCaches();
27+
}
28+
29+
window.addEventListener('pushstate', onMove);
30+
window.addEventListener('popstate', onMove);
31+
window.addEventListener('replacestate', onMove);
2232
});

blocks/graphic/Graphic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Graphic extends MC {
3737
*/
3838
_shadowFunction(args) {
3939
const
40-
rect = args.eventControlElement.domElement.getBoundingClientRect(),
40+
rect = args.eventControlElement.rect,
4141
hover = [
4242
args.event.clientX - rect.left,
4343
args.event.clientY - rect.top

blocks/page/Page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Page extends MC {
3939
*/
4040
_shadowFunction(args) {
4141
const
42-
rect = args.eventControlElement.domElement.getBoundingClientRect(),
42+
rect = args.eventControlElement.rect,
4343
hover = [
4444
args.event.clientX - rect.left,
4545
args.event.clientY - rect.top

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<!-- htmllint attr-bans="false" -->
1111
<a class="link-to" href="#">zum Start/go to start</a>
1212
<a id="to-qr" class="link-to" href="#to-qr">zum QR code/go to the QR code</a>
13-
<a id="to-projects" class="link-to" href="#to-prjoects">zur Projekseite/go to the project page</a>
13+
<a id="to-projects" class="link-to" href="#to-projects">zur Projektseite/go to the project page</a>
1414
<!-- htmllint attr-bans="$previous" -->
1515
<div class="main-container main-container--initial">
1616
<div class="card card--main main-card main-card--initial">

js/eventControl/EventControlElement.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,46 @@ export default class EventControlElement {
4040
return this.__size;
4141
}
4242

43+
/**
44+
* clientBoundingRect of the domElement, cached after it has been the
45+
* same for 5 calls. Cache can be flushed using {flushRectCache}
46+
*/
47+
get rect() {
48+
if(this._rectSafe === undefined) {
49+
this._rectSafe = 5;
50+
}
51+
52+
if(this._rect === undefined || this._rectSafe !== 0) {
53+
const newRect = this.domElement.getBoundingClientRect();
54+
55+
if(this._rect !== undefined) {
56+
this._rectSafe--;
57+
for(let a in newRect) {
58+
if(newRect[a] !== this._rect) {
59+
this._rectSafe = 5;
60+
break;
61+
}
62+
}
63+
}
64+
65+
this._rect = newRect;
66+
console.log('neql');
67+
} else {
68+
console.log('equal');
69+
}
70+
71+
return this._rect;
72+
}
73+
74+
/**
75+
* flushes the rect cache from {get rect}
76+
* @returns {void}
77+
*/
78+
flushRectCache() {
79+
this._rect = undefined;
80+
this._rectSafe = 5;
81+
}
82+
4383
/**
4484
* adds the given css classes to the DOM element so that it can be
4585
* recognized as transformable when looking at the DOM

js/eventControl/EventController.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ export default class EventController {
120120
});
121121
}
122122

123+
flushRectCaches() {
124+
this.eventControlElements
125+
.forEach(ece => ece.flushRectCache());
126+
}
127+
123128
/**
124129
* _mutates() calls this method when there might have been a CSS
125130
* change. This method makes sure that the EventControlElements of

js/transformation/TransformableElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ export default class TransformableElement extends ECE {
634634
'transform', this.initialTransform
635635
);
636636

637-
const rect = this.domElement.getBoundingClientRect();
637+
const rect = this.rect;
638638

639639
this._setProperty('transform', '');
640640

0 commit comments

Comments
 (0)