Skip to content

Commit

Permalink
re-add widget startup module for performance savings
Browse files Browse the repository at this point in the history
  • Loading branch information
BurningTreeC committed Mar 17, 2024
1 parent 6be1ce7 commit a5eb127
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 61 deletions.
36 changes: 36 additions & 0 deletions TiddlyFlex/files/modules/startup/widget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*\
title: $:/plugins/BTC/TiddlyFlex/modules/startup/widget.js
type: application/javascript
module-type: startup
Overwriting the Base Widget refreshChildren method
\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

exports.name = "tiddlyflex-widget";
exports.platforms = ["browser"];
exports.after = ["startup"];
exports.synchronous = true;

var Widget = require("$:/core/modules/widgets/widget.js").widget;

Widget.prototype.refreshChildren = function(changedTiddlers,force) {
var children = this.children,
refreshed = false;
for(var i=0; i<children.length; i++) {
var child = children[i];
if(!force && child.domNodes && child.domNodes[0] && child.domNodes[0].style && ((child.domNodes[0].style["content-visibility"] === "auto") || (child.domNodes[0].style["content-visibility"] === "hidden"))) {
return false;
} else {
refreshed = child.refresh(changedTiddlers) || refreshed;
}
}
return refreshed;
};

})();
49 changes: 29 additions & 20 deletions TiddlyFlex/files/modules/widgets/dynanode.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ DynaNodeWidget.prototype.render = function(parent,nextSibling) {

this.onScroll = function(event) {
if(!self.isWaitingForAnimationFrame) {
self.refreshChildren(self.changedTiddlers);
self.domNode.ownerDocument.defaultView.requestAnimationFrame(worker);
}
self.isWaitingForAnimationFrame |= ANIM_FRAME_CAUSED_BY_SCROLL;
Expand Down Expand Up @@ -101,20 +100,24 @@ DynaNodeWidget.prototype.render = function(parent,nextSibling) {
};

this.resizeObserver = new ResizeObserver(function(entries) {
self.domNode.ownerDocument.defaultView.requestAnimationFrame(function() {
if(!Array.isArray(entries) || !entries.length) {
return;
}
if(self.isWaitingForAnimationFrame) {
return;
}
if(!self.isWaitingForAnimationFrame) {
self.domNode.ownerDocument.defaultView.requestAnimationFrame(function() {
self.dynanodeWorker(entries);
});
}
self.isWaitingForAnimationFrame |= ANIM_FRAME_CAUSED_BY_RESIZE;
});
if(!self.isWaitingForAnimationFrame) {
self.domNode.ownerDocument.defaultView.requestAnimationFrame(function() {
if(!Array.isArray(entries) || !entries.length) {
return;
}
if(self.isWaitingForAnimationFrame) {
return;
}
if(!self.isWaitingForAnimationFrame) {
self.domNode.ownerDocument.defaultView.requestAnimationFrame(function() {
self.dynanodeWorker(entries);
});
}
self.isWaitingForAnimationFrame |= ANIM_FRAME_CAUSED_BY_RESIZE;
});
} else {
return;
}
});

this.mutationObserver = new MutationObserver(function(mutations) {
Expand All @@ -130,8 +133,10 @@ DynaNodeWidget.prototype.render = function(parent,nextSibling) {
addedNodes.push(addedNode);
if(j === (mutation.addedNodes.length - 1)) {
for(var k=0; k<addedNodes.length; k++) {
self.dynanodeElements.push(addedNodes[k]);
self.resizeObserver.observe(addedNodes[k]);
if(self.dynanodeElements.indexOf(addedNodes[k]) === -1) {
self.dynanodeElements.push(addedNodes[k]);
self.resizeObserver.observe(addedNodes[k]);
}
if(k === (addedNodes.length - 1)) {
if(!self.isWaitingForAnimationFrame) {
self.domNode.ownerDocument.defaultView.requestAnimationFrame(function() {
Expand Down Expand Up @@ -228,6 +233,7 @@ DynaNodeWidget.prototype.checkVisibility = function() {
var self = this;
//var elements = this.domNode.querySelectorAll(this.dynanodeSelector);
var elements = this.dynanodeElements;
var visibilityChanged = false;
var domNodeWidth = this.domNode.offsetWidth,
domNodeHeight = this.domNode.offsetHeight,
domNodeBounds = this.domNode.getBoundingClientRect();
Expand Down Expand Up @@ -268,9 +274,9 @@ DynaNodeWidget.prototype.checkVisibility = function() {
$tw.utils.setStyle(element,[
{ contentVisibility: null }
]);
if(currValue !== undefined) {
self.refreshChildren(self.changedTiddlers);
}
//if(currValue !== undefined) {
visibilityChanged = true;
//}
}
if(newValue === STATE_NEAR_VIEW) {
$tw.utils.addClass(element,"tc-dynanode-near");
Expand All @@ -294,6 +300,9 @@ DynaNodeWidget.prototype.checkVisibility = function() {
}
}
if(i === (elements.length - 1)) {
if(visibilityChanged) {
self.refreshChildren(self.changedTiddlers);
}
self.isWaitingForAnimationFrame = 0;
}
}
Expand Down
37 changes: 0 additions & 37 deletions TiddlyFlex/files/modules/widgets/subclasses/element.js

This file was deleted.

6 changes: 3 additions & 3 deletions TiddlyFlex/files/tiddlywiki.files
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"module-type": "widget-subclass"
}
},{
"file": "modules/widgets/subclasses/element.js",
"file": "modules/startup/widget.js",
"fields": {
"type": "application/javascript",
"title": "$:/plugins/BTC/TiddlyFlex/modules/widgets/subclasses/element.js",
"module-type": "widget-subclass"
"title": "$:/plugins/BTC/TiddlyFlex/modules/startup/widget.js",
"module-type": "startup"
}
},{
"file": "modules/utils/utils.js",
Expand Down
2 changes: 1 addition & 1 deletion TiddlyFlex/plugin.info
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "TiddlyFlex",
"plugin-type": "plugin",
"author": "Simon Huber",
"version": "0.0.130",
"version": "0.0.131",
"core-version": ">=5.3.3",
"source": "https://github.com/BurningTreeC/TiddlyFlex",
"list": "readme license"
Expand Down

0 comments on commit a5eb127

Please sign in to comment.