-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBsDiffPatchModule.kt
More file actions
43 lines (38 loc) · 1.09 KB
/
BsDiffPatchModule.kt
File metadata and controls
43 lines (38 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.jimmydaddy.bsdiffpatch
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.module.annotations.ReactModule
@ReactModule(name = BsDiffPatchNative.NAME)
class BsDiffPatchModule(reactContext: ReactApplicationContext) :
NativeBsDiffPatchSpec(reactContext) {
override fun getName(): String = BsDiffPatchNative.NAME
override fun patch(
oldFile: String,
newFile: String,
patchFile: String,
promise: Promise
) {
execute(promise) {
BsDiffPatchNative.patch(oldFile, newFile, patchFile)
}
}
override fun diff(
oldFile: String,
newFile: String,
patchFile: String,
promise: Promise
) {
execute(promise) {
BsDiffPatchNative.diff(oldFile, newFile, patchFile)
}
}
private fun execute(promise: Promise, block: () -> Int) {
try {
promise.resolve(block())
} catch (error: BsDiffPatchException) {
promise.reject(error.code, error.message, error)
} catch (error: Exception) {
promise.reject("EUNSPECIFIED", error.message, error)
}
}
}