Skip to content

Commit d4b394a

Browse files
authored
chore: Documentation comments (#26)
1 parent 4d71841 commit d4b394a

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

src/index.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,28 @@ const { IONPortalPubSub, IONPortalManager, IONLiveUpdatesManager } =
1010

1111
export { default as PortalView } from './PortalView';
1212

13+
/**
14+
* The data that is received from a subscription event.
15+
*/
1316
export interface Message {
17+
/** The unique subscription reference received from {@link subscribe}*/
1418
subscriptionRef: number;
1519
data: any;
20+
/** The topic the message was sent from */
1621
topic: string;
1722
}
1823

1924
const PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);
2025

2126
const subscriptionMap = new Map<number, EmitterSubscription>();
2227

28+
/**
29+
* Subscribes to messages for a topic
30+
*
31+
* @param topic The topic to subscribe to
32+
* @param onMessageReceived The callback to invoke when a message is received
33+
* @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.
34+
*/
2335
export const subscribe = async (
2436
topic: string,
2537
onMessageReceived: (message: Message) => void
@@ -40,6 +52,12 @@ export const subscribe = async (
4052
return subscriptionRef;
4153
};
4254

55+
/**
56+
* Unsubscribes from events for the provided topic and subscription reference
57+
*
58+
* @param topic The topic to unsubscribe from
59+
* @param subRef The unique subscription reference received when initially calling {@link subscribe}
60+
*/
4361
export const unsubscribe = (topic: string, subRef: number) => {
4462
IONPortalPubSub.unsubscribe(topic, subRef);
4563

@@ -50,62 +68,118 @@ export const unsubscribe = (topic: string, subRef: number) => {
5068
}
5169
};
5270

71+
/**
72+
* Publishes a message to the provided topic
73+
*
74+
* @param topic The topic to publish the message to
75+
* @param data The data to publish to subscribers
76+
*/
5377
export const publish = (topic: string, data: any) => {
5478
const msg = { message: data };
5579
IONPortalPubSub.publish(topic, msg);
5680
};
5781

82+
/**
83+
* Validates that a valid registration key has been procured from http://ionic.io/register-portals
84+
* @param key The registration key
85+
*/
5886
export const register = (key: string) => {
5987
IONPortalManager.register(key);
6088
};
6189

90+
/**
91+
* The configuration of a web application to be embedded in a React Native application.
92+
*/
6293
export interface Portal {
94+
/** The name of the Portal to be referenced. Must be **unique** */
6395
name: string;
96+
/** The classpath of all Capacitor plugins used in Android. (e.g. com.capacitorjs.plugins.camera.CameraPlugin) */
6497
androidPlugins?: string[];
98+
/**
99+
* The root directory of the web application relative to Bundle.main on iOS
100+
* and src/main/assets on Android. If omitted, `name` is used.
101+
*/
65102
startDir?: string;
103+
/** The name of the initial file to load. If omitted, 'index.html' is used. */
66104
index?: string;
105+
/** Any data needed at initial render when a portal is loaded. */
67106
initialContext?: {
68107
[key: string]: any;
69108
};
70109
liveUpdate?: LiveUpdateConfig;
71110
}
72111

112+
/**
113+
* A subset of {@link Portal} properties needed for rendering a Portal. `initialContext` can be used to override
114+
* any initialContext defined in the original {@link Portal} definition.
115+
*/
73116
export type PortalProp = {
74117
portal: Pick<Portal, 'name' | 'initialContext'>;
75118
};
76119

120+
/**
121+
* Props needed for rendering a {@link Portal}
122+
*/
77123
export type PortalProps = PortalProp & ViewProps;
78124

125+
/**
126+
* Adds a Portal to an internal registry. Must be called before attempting to render a {@link PortalView}.
127+
*
128+
* @param portal The portal to add to the internal registry.
129+
*/
79130
export const addPortal = (portal: Portal) => {
80131
IONPortalManager.addPortal(portal);
81132
};
82133

83134
export interface LiveUpdate {
135+
/** The AppFlow application ID */
84136
appId: string;
137+
/** The AppFlow distribution channel */
85138
channel: string;
86139
}
87140

141+
/** Data needed to register a live update to be managed */
88142
export type LiveUpdateConfig = LiveUpdate & { syncOnAdd: boolean };
89143

90144
export interface LiveUpdateError {
145+
/** The AppFlow application ID relating to the failure */
91146
appId: string;
147+
/** The step in the sync process the LiveUpdate failed on. (e.g. CHECK, UNPACK)*/
92148
failStep: string;
149+
/** A human readable error message */
93150
message: string;
94151
}
95152

153+
/** Used for communicating sync results of multiple live updates */
96154
export interface SyncResults {
97155
liveUpdates: LiveUpdate[];
98156
errors: LiveUpdateError[];
99157
}
100158

159+
/**
160+
* Syncs a single live update.
161+
*
162+
* @param appId The AppFlow application ID to sync.
163+
* @returns A Promise<LiveUpdate>. A failure should result in a {@link LiveUpdateError}.
164+
*/
101165
export const syncOne = (appId: string): Promise<LiveUpdate> => {
102166
return IONLiveUpdatesManager.syncOne(appId);
103167
};
104168

169+
/**
170+
* Syncs many live updates.
171+
*
172+
* @param appIds The AppFlow application IDs to sync.
173+
* @returns Promise<SyncResults>
174+
*/
105175
export const syncSome = (appIds: string[]): Promise<SyncResults> => {
106176
return IONLiveUpdatesManager.syncSome(appIds);
107177
};
108178

179+
/**
180+
* Syncs all registered LiveUpdates
181+
* @returns Promise<SyncResults>
182+
*/
109183
export const syncAll = (): Promise<SyncResults> => {
110184
return IONLiveUpdatesManager.syncAll();
111185
};

0 commit comments

Comments
 (0)