@shopfront/bridge 3.0.7 → 3.0.8--canary.26.3363b8d.0

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.
package/README.md CHANGED
@@ -17,14 +17,13 @@ The setup of the frame is the default way of use, and nothing special is require
17
17
 
18
18
  ### JavaScript Communicator
19
19
 
20
- Shopfront expects an ES Module which exports the following three functions:
20
+ Shopfront expects an ES Module which exports either the application or the following three functions:
21
21
 
22
22
  - `execute`
23
23
  - `registerSendMessage`
24
24
  - `onReceiveMessage`
25
25
 
26
- The application exposes methods allowing your application to work directly with this, all you need to do is
27
- export them:
26
+ Exporting the application is the easiest and recommended option, make sure it's exported as default:
28
27
 
29
28
  ```javascript
30
29
  import { Bridge } from "@shopfront/bridge";
@@ -34,13 +33,10 @@ const application = Bridge.createApplication({
34
33
  communicator: "javascript",
35
34
  });
36
35
 
37
- export const execute = application.communicator.execute;
38
- export const registerSendMessage = application.communicator.registerSendMessage;
39
- export const onReceiveMessage = application.communicator.onReceiveMessage;
36
+ export default application;
40
37
  ```
41
-
42
- Alternatively, you can export the application as the default item and Shopfront will automatically infer the functions
43
- from it.
38
+ If you're wanting to do something custom or don't want to expose the application to Shopfront, then you can instead
39
+ expose the methods individually from the application:
44
40
 
45
41
  ```javascript
46
42
  import { Bridge } from "@shopfront/bridge";
@@ -50,5 +46,15 @@ const application = Bridge.createApplication({
50
46
  communicator: "javascript",
51
47
  });
52
48
 
53
- export default application;
49
+ export const execute = application.communicator.execute;
50
+ export const registerSendMessage = application.communicator.registerSendMessage;
51
+ export const onReceiveMessage = application.communicator.onReceiveMessage;
54
52
  ```
53
+
54
+ > [!NOTE]
55
+ > When exporting the methods individually, you may receive the TypeScript error "TS2742: The inferred type of
56
+ > onReceiveMessage cannot be named without a reference to Bridge". You can resolve this by specifying the type
57
+ > directly:
58
+ > ```javascript
59
+ > export const onReceiveMessage: typeof application.communicator.onReceiveMessage = application.communicator.onReceiveMessage;
60
+ > ```