Hello,
I have some utility functions for my codemirror 6 plugin and I’d like to export them at the $tw.codemirrorutils namespace
I tried but couldn’t figure out how to do that
Does anybody know the solution?
I guess it must be done in a startup module?
Edit:
The header looks like this:
/*\
title: $:/plugins/BTC/tiddlywiki-codemirror-6/lib/codemirror-utils.js
type: application/javascript
module-type: codemirrorutils
\*/
you can see, the module-type is “codemirrorutils”
Thank you in advance,
Simon
I found a solution!
I need to require the utils module before the “load-modules” startup module
just for the record, my startup module now looks like this:
/*\
title: $:/plugins/BTC/tiddlywiki-codemirror-6/startup/load-modules.js
type: application/javascript
module-type: startup
Load codemirror modules
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
$tw.codemirrorutils = Object.create(null);
// Export name and synchronous status
exports.name = "load-codemirror-utils";
exports.synchronous = true;
exports.before = ["load-modules"];
exports.startup = function() {
// Load modules
$tw.modules.applyMethods("codemirrorutils",$tw.codemirrorutils);
};
})();
Why not $tw.utils.codemirror.xxx?
But if you are using a bundler, you can just import them across files, and not exporting them. Just like https://github.com/tiddly-gittly/watch-fs/blob/master/src/watch-fs/utils.ts , I just import them, and bundle everything into a single .js
Good question! I didn’t think about it too much 