Explorar el Código

Add the `env` to `_converse` as well.

As I was working on a 3rd party plugin, I realized it's currently clunky
to get hold of the `ev`. The global `converse` object doesn't have it
because it's the wrapped obj from `src/entry.js`.
JC Brand hace 3 meses
padre
commit
3e096e3c58

+ 5 - 0
src/headless/shared/_converse.js

@@ -127,6 +127,11 @@ class ConversePrivateGlobal extends EventEmitter(Object) {
          */
         this.constants = /** @type {Record<string, string|Object>} */({});
 
+        /**
+         * Utility methods and globals from bundled 3rd party libraries.
+         */
+        this.env = /** @type {import("./api/types.js").ConverseEnv} */ ({});
+
         /**
          * Namespace for storing the state, as represented by instances of
          * Models and Collections.

+ 27 - 24
src/headless/shared/api/public.js

@@ -31,6 +31,31 @@ import {
     registerGlobalEventHandlers,
 } from '../../utils/init.js';
 
+const env = /** @type {import('./types').ConverseEnv} */ {
+    $build,
+    $iq,
+    $msg,
+    $pres,
+    utils: u,
+    Collection,
+    Model,
+    Stanza,
+    Strophe,
+    TimeoutError,
+    VERSION_NAME,
+    dayjs,
+    errors,
+    filesize,
+    html,
+    css,
+    render,
+    log,
+    sizzle,
+    sprintf,
+    stx,
+    u,
+}
+
 /**
  * @typedef {Window & {converse: ConversePrivateGlobal} } window
  *
@@ -94,6 +119,7 @@ const converse = Object.assign(/** @type {ConversePrivateGlobal} */(window).conv
         const connfeedback = new ConnectionFeedback();
         Object.assign(_converse, { connfeedback }); // XXX: DEPRECATED
         Object.assign(_converse.state, { connfeedback });
+        _converse.env = env;
 
         await initSessionStorage(_converse);
         await initClientConfig(_converse);
@@ -163,30 +189,7 @@ const converse = Object.assign(/** @type {ConversePrivateGlobal} */(window).conv
         }
 
     },
-    env: /** @type {import('./types').ConverseEnv} */({
-        $build,
-        $iq,
-        $msg,
-        $pres,
-        utils: u,
-        Collection,
-        Model,
-        Stanza,
-        Strophe,
-        TimeoutError,
-        VERSION_NAME,
-        dayjs,
-        errors,
-        filesize,
-        html,
-        css,
-        render,
-        log,
-        sizzle,
-        sprintf,
-        stx,
-        u,
-    })
+    env,
 });
 
 export default converse;

+ 5 - 1
src/headless/types/shared/_converse.d.ts

@@ -15,7 +15,7 @@ declare const ConversePrivateGlobal_base: (new (...args: any[]) => {
     off(name: string, callback: (event: any, model: import("@converse/skeletor/src/types/model.js").Model, collection: import("@converse/skeletor").Collection, options?: Record<string, any>) => any, context?: any): any;
     stopListening(obj?: any, name?: string, callback?: (event: any, model: import("@converse/skeletor/src/types/model.js").Model, collection: import("@converse/skeletor").Collection, options?: Record<string, any>) => any): any;
     once(name: string, callback: (event: any, model: import("@converse/skeletor/src/types/model.js").Model, collection: import("@converse/skeletor").Collection, options?: Record<string, any>) => any, context: any): any;
-    listenToOnce(obj: any, name: string, callback?: (event: any, model: import("@converse/skeletor/src/types/model.js").Model, collection: import("@converse/skeletor").Collection, options?: Record<string, any>) => any): any;
+    listenToOnce(obj: any, name: string, callback?: (event: any, model: import("@converse/skeletor/src/types/model.js").Model, collection: import("@converse/skeletor").Collection, options? /** @type {ConverseState} */: Record<string, any>) => any): any;
     trigger(name: string, ...args: any[]): any;
 }) & ObjectConstructor;
 /**
@@ -66,6 +66,10 @@ declare class ConversePrivateGlobal extends ConversePrivateGlobal_base {
      * Converse.
      */
     constants: Record<string, any>;
+    /**
+     * Utility methods and globals from bundled 3rd party libraries.
+     */
+    env: import("./api/types.js").ConverseEnv;
     /**
      * Namespace for storing the state, as represented by instances of
      * Models and Collections.

+ 1 - 0
src/headless/types/shared/api/index.d.ts

@@ -24,6 +24,7 @@ export type _converse = {
     labels: Record<string, string | Record<string, string>>;
     exports: Record<string, any>;
     constants: Record<string, any>;
+    env: import("./types.js").ConverseEnv;
     state: any;
     initSession(): void;
     session: import("@converse/skeletor").Model;