@@ -2,48 +2,11 @@ import * as commands from './commands/index.js';
22import * as plugins from './plugins/index.js' ;
33import { BranchInitializedData } from './plugins/branch.js' ;
44import { InAppPurchaseInfoReadyData } from './plugins/iap.js' ;
5- import { ShareToAppData } from './plugins/share.js' ;
6- import { createTempFunctionName , setMedianCallback , setSubscription } from './utils.js' ;
5+ import { ShareToAppData } from './plugins/shareIntoApp.js' ;
6+ import { createListener } from './utils/listener.js' ;
7+ import { AppsFlyer } from './types/appsflyer.js' ;
78
89namespace Median {
9- ///////////////////////////////
10- // Internal //
11- ///////////////////////////////
12- const listeners : Record < string , Record < string , ( ...args : any [ ] ) => void > > = { } ;
13-
14- const addListener = < T > ( functionName : string , callback : ( data : T ) => void ) => {
15- const functionId = createTempFunctionName ( functionName ) ;
16-
17- if ( typeof callback !== 'function' ) {
18- return functionId ;
19- }
20-
21- listeners [ functionName ] = listeners [ functionName ] || { } ;
22- listeners [ functionName ] [ functionId ] = callback ;
23-
24- setMedianCallback ( functionName , listeners [ functionName ] ) ;
25- setSubscription ( functionName , true ) ;
26-
27- return functionId ;
28- } ;
29-
30- const removeListener = ( functionName : string , functionId : string ) => {
31- if ( ! functionName || ! functionId ) return ;
32-
33- listeners [ functionName ] = listeners [ functionName ] || { } ;
34- delete listeners [ functionName ] [ functionId ] ;
35-
36- setMedianCallback ( functionName , listeners [ functionName ] ) ;
37- if ( Object . keys ( listeners [ functionName ] ) . length === 0 ) {
38- setSubscription ( functionName , false ) ;
39- }
40- } ;
41-
42- const createListenerProp = < T = void > ( functionName : string ) => ( {
43- addListener : ( callback : ( data : T ) => void ) => addListener < T > ( functionName , callback ) ,
44- removeListener : ( functionId : string ) => removeListener ( functionName , functionId ) ,
45- } ) ;
46-
4710 ///////////////////////////////
4811 // General Commands //
4912 ///////////////////////////////
@@ -55,6 +18,7 @@ namespace Median {
5518 export const connectivity = commands . general . connectivity ;
5619 export const deviceInfo = commands . general . deviceInfo ;
5720 export const internalExternal = commands . general . internalExternal ;
21+ export const jsNavigation = commands . general . jsNavigation ;
5822 export const keyboard = commands . general . keyboard ;
5923 export const nativebridge = commands . general . nativebridge ;
6024 export const navigationLevels = commands . general . navigationLevels ;
@@ -119,8 +83,8 @@ namespace Median {
11983 export const opentok = plugins . opentok ;
12084 export const permissions = plugins . permissions ;
12185 export const plaid = plugins . plaid ;
122- export const purchase = plugins . iap . purchase ;
12386 export const revenueCat = plugins . revenueCat ;
87+ export const shareIntoApp = plugins . shareIntoApp ;
12488 export const socialLogin = plugins . socialLogin ;
12589 export const socialShare = plugins . socialShare ;
12690 export const storage = {
@@ -168,25 +132,48 @@ namespace Median {
168132 ///////////////////////////////
169133 // Events //
170134 ///////////////////////////////
171- export const appsFlyerConversionData = createListenerProp < any > ( '_median_appsflyer_cd' ) ;
172- export const appsFlyerDeeplinkResult = createListenerProp < any > ( '_median_appsflyer_deeplink_result' ) ;
173- export const appsFlyerSdkStart = createListenerProp < any > ( '_median_appsflyer_sdk_start' ) ;
174- export const appResumed = createListenerProp ( '_median_app_resumed' ) ;
175- export const branchInitialized = createListenerProp < BranchInitializedData > ( '_median_branch_initialized' ) ;
176- export const deviceShake = createListenerProp ( '_median_device_shake' ) ;
177- export const iapInfoReady = createListenerProp < InAppPurchaseInfoReadyData > ( '_median_info_ready' ) ;
178- export const iapPurchases = createListenerProp < any > ( '_median_iap_purchases' ) ;
179- export const jsNavigation = {
180- url : createListenerProp < { url : string } > ( '_median_url_changed' ) ,
181- } ;
182- export const oneSignalPushOpened = createListenerProp < any > ( '_median_onesignal_push_opened' ) ;
183- export const shareToApp = createListenerProp < ShareToAppData > ( '_median_share_to_app' ) ;
135+ export const appResumed = createListener ( '_median_app_resumed' ) ;
136+ export const deviceShake = createListener ( '_median_device_shake' ) ;
137+
138+ /**
139+ * @deprecated Use `Median.appsflyer.conversionData` instead.
140+ */
141+ export const appsFlyerConversionData = createListener < AppsFlyer . ConversionData > ( '_median_appsflyer_cd' ) ;
142+ /**
143+ * @deprecated Use `Median.appsflyer.deeplinkResult` instead.
144+ */
145+ export const appsFlyerDeeplinkResult = createListener < AppsFlyer . DeeplinkResult > ( '_median_appsflyer_deeplink_result' ) ;
146+ /**
147+ * @deprecated Use `Median.appsflyer.sdkStart` instead.
148+ */
149+ export const appsFlyerSdkStart = createListener < AppsFlyer . SdkStartResponse > ( '_median_appsflyer_sdk_start' ) ;
150+ /**
151+ * @deprecated Use `Median.branch.initialized` instead.
152+ */
153+ export const branchInitialized = createListener < BranchInitializedData > ( '_median_branch_initialized' ) ;
154+ /**
155+ * @deprecated Use `Median.iap.infoReady` instead.
156+ */
157+ export const iapInfoReady = createListener < InAppPurchaseInfoReadyData > ( '_median_info_ready' ) ;
158+ /**
159+ * @deprecated Use `Median.iap.purchaseResult` instead.
160+ */
161+ export const iapPurchases = createListener < Record < string , any > > ( '_median_iap_purchases' ) ;
162+ /**
163+ * @deprecated Use `Median.oneSignal.pushOpened` instead.
164+ */
165+ export const oneSignalPushOpened = createListener < Record < string , any > > ( '_median_onesignal_push_opened' ) ;
166+ /**
167+ * @deprecated Use `Median.shareIntoApp.shareResult` instead.
168+ */
169+ export const shareToApp = createListener < ShareToAppData > ( '_median_share_to_app' ) ;
184170}
185171
186172export default Median ;
187173
188174///////////////////////////////
189175// Types //
190176///////////////////////////////
177+ export { AppsFlyer } from './types/appsflyer.js' ;
191178export { HealthBridge } from './types/healthBridge.js' ;
192179export { MasterLock } from './types/masterlock.js' ;
0 commit comments