1- // @flow
21'use strict' ;
32
43import { NativeModules , NativeEventEmitter } from 'react-native' ;
@@ -39,6 +38,10 @@ class IterableAction {
3938 this . data = data
4039 this . userInput = userInput
4140 }
41+
42+ static fromDict ( dict : any ) : IterableAction {
43+ return new IterableAction ( dict [ "type" ] , dict [ "data" ] , dict [ "userInput" ] )
44+ }
4245}
4346
4447class IterableActionContext {
@@ -49,6 +52,12 @@ class IterableActionContext {
4952 this . action = action
5053 this . source = source
5154 }
55+
56+ static fromDict ( dict : any ) : IterableActionContext {
57+ const action = IterableAction . fromDict ( dict [ "action" ] )
58+ const source = dict [ "actionSource" ] as IterableActionSource
59+ return new IterableActionContext ( action , source )
60+ }
5261}
5362
5463class IterableAttributionInfo {
@@ -95,10 +104,9 @@ class Iterable {
95104 RNEventEmitter . addListener (
96105 EventName . handleUrlCalled ,
97106 ( dict ) => {
98- let url = dict [ "url" ]
99- let contextDict = dict [ "context" ]
100- let context = Iterable . convertDictToIterableContext ( contextDict )
101- let result = config . urlDelegate ! ( url , context )
107+ const url = dict [ "url" ]
108+ const context = IterableActionContext . fromDict ( dict [ "context" ] )
109+ const result = config . urlDelegate ! ( url , context )
102110 RNIterableAPI . setUrlHandled ( result )
103111 }
104112 )
@@ -107,11 +115,8 @@ class Iterable {
107115 RNEventEmitter . addListener (
108116 EventName . handleCustomActionCalled ,
109117 ( dict ) => {
110- let actionDict = dict [ "action" ]
111- let contextDict = dict [ "context" ]
112- let action = Iterable . convertDictToIterableAction ( actionDict )
113- let context = Iterable . convertDictToIterableContext ( contextDict )
114-
118+ const action = IterableAction . fromDict ( dict [ "action" ] )
119+ const context = IterableActionContext . fromDict ( dict [ "context" ] )
115120 config . customActionDelegate ! ( action , context )
116121 }
117122 )
@@ -227,17 +232,6 @@ class Iterable {
227232 }
228233 }
229234
230- private static convertDictToIterableContext ( dict : any ) : IterableActionContext {
231- const actionDict = dict [ "action" ]
232- const action = Iterable . convertDictToIterableAction ( actionDict )
233- const actionSource = dict [ "actionSource" ] as IterableActionSource
234- return new IterableActionContext ( action , actionSource )
235- }
236-
237- private static convertDictToIterableAction ( actionDict : any ) : IterableAction {
238- return new IterableAction ( actionDict [ "type" ] , actionDict [ "data" ] , actionDict [ "userInput" ] )
239- }
240-
241235 static async getInAppMessages ( ) {
242236 console . log ( "getInAppMessages" ) ;
243237 try {
0 commit comments