-
-
Notifications
You must be signed in to change notification settings - Fork 165
Description
Currently the Document holds a reference to a Graph, from the property-graph
package:
glTF-Transform/packages/core/src/document.ts
Lines 76 to 94 in a7c1dec
private _graph: Graph<Property> = new Graph<Property>(); | |
private _root: Root = new Root(this._graph); | |
private _logger: ILogger = Logger.DEFAULT_INSTANCE; | |
/** | |
* Enables lookup of a Document from its Graph. For internal use, only. | |
* @internal | |
* @experimental | |
*/ | |
private static _GRAPH_DOCUMENTS = new WeakMap<Graph<Property>, Document>(); | |
/** | |
* Returns the Document associated with a given Graph, if any. | |
* @hidden | |
* @experimental | |
*/ | |
public static fromGraph(graph: Graph<Property>): Document | null { | |
return Document._GRAPH_DOCUMENTS.get(graph) || null; | |
} |
To keep function parameter simple though, we sometimes need to look up a Document from an arbitrary Property...
glTF-Transform/packages/functions/src/list-texture-channels.ts
Lines 44 to 45 in a7c1dec
export function getTextureChannelMask(texture: Texture): number { | |
const document = Document.fromGraph(texture.getGraph())!; |
... which works fine in general, but with Node.js continuing to delay the ecosystem from adopting ESM, it can be a source of hard-to-debug failures from dual package hazard. At some point I will need to drop CommonJS support entirely, but ...
It might be a nice simplification to merge the Document and Graph concepts by having Document extend Graph<Property>
. Then there's one fewer concepts to think about, and one source of mystery bug in Node.js could go away. I think if I could do that and remove all use of instanceof
, dual package hazard might not break end-user applications at all. May require a major release.