@talex-touch/utils 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/plugin/preload.ts +20 -18
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "module": "./index.ts",
6
6
  "license": "MPL-2.0",
7
7
  "private": false,
8
- "version": "1.0.0",
8
+ "version": "1.0.1",
9
9
  "scripts": {
10
10
  "publish": "npm publish --access public"
11
11
  },
package/plugin/preload.ts CHANGED
@@ -1,34 +1,36 @@
1
- import { touchChannel } from "./channel";
1
+ import { touchChannel } from './channel'
2
2
 
3
3
  // window type
4
4
  declare global {
5
5
  export interface Window {
6
6
  $plugin: {
7
- name: string;
8
- path: Object;
9
- };
10
- $send: (type: string, data: any) => void;
11
- $sendSync: (type: string, data: any) => Promise<any>;
12
- $regChannel: (type: string, callback: Function) => void;
13
- $crash: (message: string, extraData: any) => void;
7
+ name: string
8
+ path: Object
9
+ }
10
+ $send: (type: string, data: any) => void
11
+ $sendSync: (type: string, data: any) => Promise<any>
12
+ $regChannel: (type: string, callback: Function) => void
13
+ $crash: (message: string, extraData: any) => void
14
14
  $config: {
15
- themeStyle: any;
16
- };
15
+ themeStyle: any
16
+ }
17
17
  }
18
18
  }
19
19
 
20
20
  export function init(window: Window) {
21
- const plugin = window.$plugin;
21
+ const plugin = window.$plugin
22
22
  if (!plugin)
23
- throw new Error("Plugin has a fatal error! Please check your plugin!");
23
+ throw new Error('Plugin has a fatal error! Please check your plugin!')
24
24
 
25
- window.$crash = function(message, extraData) {
26
- window.$send("crash", { message, ...extraData });
27
- };
25
+ window.$crash = function (message, extraData) {
26
+ window.$send('crash', { message, ...extraData })
27
+ }
28
+
29
+ initBridge(window)
28
30
  }
29
31
 
30
32
  export function initBridge(window: Window) {
31
- window.$send = touchChannel.send;
32
- window.$sendSync = touchChannel.sendSync;
33
- window.$regChannel = touchChannel.regChannel;
33
+ window.$send = touchChannel.send
34
+ window.$sendSync = touchChannel.sendSync
35
+ window.$regChannel = touchChannel.regChannel
34
36
  }