Skip to content

Commit 5aec83a

Browse files
Refactoring move method
1 parent 249297d commit 5aec83a

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

Iterable.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @flow
21
'use strict';
32

43
import { 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

4447
class 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

5463
class 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

Comments
 (0)