@@ -66,8 +66,10 @@ const DEFAULT_TIP_CONFIG = Object.freeze({
6666} ) ;
6767
6868/**
69+ * is a string if not initialized/loaded yet
70+ *
6971 * @private
70- * @type {TipObject[] }
72+ * @type {TipObject[]|string }
7173 * @see {@link tips }
7274 */
7375let tips ;
@@ -292,6 +294,15 @@ export function setContext(newContext) {
292294 * @returns {Promise }
293295 */
294296export async function showRandomTip ( ) {
297+ // load tips if not already loaded
298+ if ( ! tips || ! Array . isArray ( tips ) ) {
299+ const tipsToShow = import ( tips ) ; // ES6 dynamic modules, requires Firefoy >= 67
300+
301+ // use local shallow copy, so we can modify it
302+ // inner objects won't be modified, so we do not need to deep-clone it.
303+ tips = tipsToShow . slice ( ) ;
304+ }
305+
295306 // only try to select tip, if one is even available
296307 if ( tips . length === 0 ) {
297308 console . info ( "no tips to show available anymore" ) ;
@@ -340,13 +351,16 @@ export function showRandomTipIfWanted() {
340351 * Initialises the module.
341352 *
342353 * @public
343- * @param {TipObject[] } tipsToShow the tips object to init
354+ * @param {TipObject[]|string } [tipsToShow="/common/modules/data/Tips.js"]
355+ * optionally, the tips object to init
356+ * or the path to lazy-load the data from
344357 * @returns {Promise.<void> }
345358 */
346- export function init ( tipsToShow ) {
347- // use local shallow copy, so we can modify it
348- // inner objects won't be modified, so we do not need to deep-clone it.
349- tips = tipsToShow . slice ( ) ;
359+ export function init ( tipsToShow = "/common/modules/data/Tips.js" ) {
360+ if ( tipsToShow ) {
361+ // use local shallow copy, if it si an array or save path
362+ tips = Array . isArray ( tipsToShow ) ? tipsToShow . slice ( ) : tipsToShow ;
363+ }
350364
351365 // load function
352366 // We need to assign it here to make it testable.
0 commit comments