Add partial rerendering to document sheets via a custom mixin
This commit is contained in:
parent
761f0b6563
commit
96eccc62f2
3 changed files with 77 additions and 30 deletions
36
module/apps/mixins/TAFDocumentSheetMixin.mjs
Normal file
36
module/apps/mixins/TAFDocumentSheetMixin.mjs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
const { hasProperty } = foundry.utils;
|
||||
|
||||
export function TAFDocumentSheetMixin(HandlebarsApplication) {
|
||||
class TAFDocumentSheet extends HandlebarsApplication {
|
||||
/** @type {Record<string, string[]> | null} */
|
||||
static PROPERTY_TO_PARTIAL = null;
|
||||
|
||||
/**
|
||||
* This override is used by the mixin in order to allow for partial
|
||||
* re-rendering of applications based on what properties changed.
|
||||
* It requires that a static PROPERTY_TO_PARTIAL to be defined as
|
||||
* an object of path keys to arrays of part IDs in order to work.
|
||||
* This will not interfere with renders that are not started as
|
||||
* part of the actor update lifecycle.
|
||||
*/
|
||||
_configureRenderOptions(options) {
|
||||
|
||||
if (options.renderContext === `updateActor`) {
|
||||
const propertyToParts = this.constructor.PROPERTY_TO_PARTIAL;
|
||||
if (propertyToParts) {
|
||||
const parts = new Set();
|
||||
for (const property in propertyToParts) {
|
||||
if (hasProperty(options.renderData, property)) {
|
||||
propertyToParts[property].forEach(partID => parts.add(partID));
|
||||
};
|
||||
};
|
||||
options.parts = options.parts?.filter(part => !parts.has(part)) ?? Array.from(parts);
|
||||
}
|
||||
};
|
||||
|
||||
super._configureRenderOptions(options);
|
||||
};
|
||||
};
|
||||
|
||||
return TAFDocumentSheet;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue