From 32b9c57bdab22be954774d8c401b445b4c8aa225 Mon Sep 17 00:00:00 2001 From: sakuntala_motukuri Date: Tue, 3 Sep 2024 14:24:43 -0400 Subject: [PATCH] removed white spaces --- ios/core/Sources/Types/Hooks/Hook.swift | 52 +++++++++---------- .../ios/Sources/AsyncNodePlugin.swift | 36 ++++++------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/ios/core/Sources/Types/Hooks/Hook.swift b/ios/core/Sources/Types/Hooks/Hook.swift index be4655110..6510ae7a1 100644 --- a/ios/core/Sources/Types/Hooks/Hook.swift +++ b/ios/core/Sources/Types/Hooks/Hook.swift @@ -11,16 +11,16 @@ import JavaScriptCore /// A base for implementing JS backed hooks open class BaseJSHook { private let baseValue: JSValue - + /// The JS reference to the hook public var hook: JSValue { baseValue.objectForKeyedSubscript("hooks").objectForKeyedSubscript(name) } - + /// The JSContext for the hook public var context: JSContext { hook.context } - + /// The name of the hook public let name: String - + /// Retrieves a hook by name from an object in JS /// - Parameters: /// - baseValue: The object that has `hooks` @@ -39,7 +39,7 @@ public class Hook: BaseJSHook where T: CreatedFromJSValue { /** Attach a closure to the hook, so when the hook is fired in the JS runtime we receive the event in the native runtime - + - parameters: - hook: A function to run when the JS hook is fired */ @@ -51,7 +51,7 @@ public class Hook: BaseJSHook where T: CreatedFromJSValue { else { return } hook(hookValue) } - + self.hook.invokeMethod("tap", withArguments: [name, JSValue(object: tapMethod, in: context) as Any]) } } @@ -64,7 +64,7 @@ public class Hook2: BaseJSHook where T: CreatedFromJSValue, U: CreatedFrom /** Attach a closure to the hook, so when the hook is fired in the JS runtime we receive the event in the native runtime - + - parameters: - hook: A function to run when the JS hook is fired */ @@ -78,7 +78,7 @@ public class Hook2: BaseJSHook where T: CreatedFromJSValue, U: CreatedFrom else { return } hook(hookValue, hookValue2) } - + self.hook.invokeMethod("tap", withArguments: [name, JSValue(object: tapMethod, in: context) as Any]) } } @@ -91,7 +91,7 @@ public class HookDecode: BaseJSHook where T: Decodable { /** Attach a closure to the hook, so when the hook is fired in the JS runtime we receive the event in the native runtime - + - parameters: - hook: A function to run when the JS hook is fired */ @@ -103,7 +103,7 @@ public class HookDecode: BaseJSHook where T: Decodable { else { return } hook(hookValue) } - + self.hook.invokeMethod("tap", withArguments: [name, JSValue(object: tapMethod, in: context) as Any]) } } @@ -116,13 +116,13 @@ public class Hook2Decode: BaseJSHook where T: Decodable, U: Decodable { /** Attach a closure to the hook, so when the hook is fired in the JS runtime we receive the event in the native runtime - + - parameters: - hook: A function to run when the JS hook is fired */ public func tap(_ hook: @escaping (T, U) -> Void) { let tapMethod: @convention(block) (JSValue?, JSValue?) -> Void = { value, value2 in - + let decoder = JSONDecoder() guard let val = value, @@ -132,7 +132,7 @@ public class Hook2Decode: BaseJSHook where T: Decodable, U: Decodable { else { return } hook(hookValue, hookValue2) } - + self.hook.invokeMethod("tap", withArguments: [name, JSValue(object: tapMethod, in: context) as Any]) } } @@ -143,13 +143,13 @@ public class Hook2Decode: BaseJSHook where T: Decodable, U: Decodable { */ public class AsyncHook: BaseJSHook where T: CreatedFromJSValue { private var handler: AsyncHookHandler? - + public typealias AsyncHookHandler = (T) async throws -> JSValue? - + /** Attach a closure to the hook, so when the hook is fired in the JS runtime we receive the event in the native runtime - + - parameters: - hook: A function to run when the JS hook is fired */ @@ -159,7 +159,7 @@ public class AsyncHook: BaseJSHook where T: CreatedFromJSValue { let val = value, let hookValue = T.createInstance(value: val) as? T else { return JSValue() } - + let promise = JSUtilities.createPromise(context: self.context, handler: { (resolve, _) in Task { @@ -169,10 +169,10 @@ public class AsyncHook: BaseJSHook where T: CreatedFromJSValue { } } }) - + return promise ?? JSValue() } - + self.hook.invokeMethod("tap", withArguments: [name, JSValue(object: tapMethod, in: context) as Any]) } } @@ -184,13 +184,13 @@ public class AsyncHook: BaseJSHook where T: CreatedFromJSValue { */ public class AsyncHook2: BaseJSHook where T: CreatedFromJSValue, U: CreatedFromJSValue { private var handler: AsyncHookHandler? - + public typealias AsyncHookHandler = (T, U) async throws -> JSValue? - + /** Attach a closure to the hook, so when the hook is fired in the JS runtime we receive the event in the native runtime - + - parameters: - hook: A function to run when the JS hook is fired */ @@ -202,8 +202,8 @@ public class AsyncHook2: BaseJSHook where T: CreatedFromJSValue, U: Create let hookValue = T.createInstance(value: val) as? T, let hookValue2 = U.createInstance(value: val2) as? U else { return JSValue() } - - + + let promise = JSUtilities.createPromise(context: self.context, handler: { (resolve, _) in Task { @@ -213,10 +213,10 @@ public class AsyncHook2: BaseJSHook where T: CreatedFromJSValue, U: Create } } }) - + return promise ?? JSValue() } - + self.hook.invokeMethod("tap", withArguments: [name, JSValue(object: tapMethod, in: context) as Any]) } } diff --git a/plugins/async-node/ios/Sources/AsyncNodePlugin.swift b/plugins/async-node/ios/Sources/AsyncNodePlugin.swift index 4e6fad717..539f3dc22 100644 --- a/plugins/async-node/ios/Sources/AsyncNodePlugin.swift +++ b/plugins/async-node/ios/Sources/AsyncNodePlugin.swift @@ -52,10 +52,10 @@ public extension AsyncNodeHandlerType { $0.toJSValue(context: context) } return context.objectForKeyedSubscript("Array").objectForKeyedSubscript("from").call(withArguments: [jsValueArray]) - + case .singleNode(let replacementNode): return replacementNode.toJSValue(context: context) - + case .emptyNode: return nil } @@ -67,11 +67,11 @@ public extension AsyncNodeHandlerType { */ public class AsyncNodePlugin: JSBasePlugin, NativePlugin { public var hooks: AsyncNodeHook? - + private var asyncHookHandler: AsyncHookHandler? - + public var plugins: [JSBasePlugin] = [] - + /** Constructs the AsyncNodePlugin - Parameters: @@ -79,30 +79,30 @@ public class AsyncNodePlugin: JSBasePlugin, NativePlugin { exposed to users of the plugin allowing them to supply the replacement node used in the tap callback */ public convenience init(plugins: [JSBasePlugin] = [AsyncNodePluginPlugin()], _ handler: @escaping AsyncHookHandler) { - + self.init(fileName: "AsyncNodePlugin.native", pluginName: "AsyncNodePlugin.AsyncNodePlugin") self.asyncHookHandler = handler self.plugins = plugins } - + override public func setup(context: JSContext) { super.setup(context: context) - + if let pluginRef = pluginRef { self.hooks = AsyncNodeHook(onAsyncNode: AsyncHook2(baseValue: pluginRef, name: "onAsyncNode")) } - + hooks?.onAsyncNode.tap({ node, callback in // hook value is the original node guard let asyncHookHandler = self.asyncHookHandler else { return JSValue() } - + let replacementNode = try await (asyncHookHandler)(node, callback) return replacementNode.handlerTypeToJSValue(context:context) ?? JSValue() }) } - + /** Retrieves the arguments for constructing this plugin, this is necessary because the arguments need to be supplied after construction of the swift object, once the context has been provided @@ -112,10 +112,10 @@ public class AsyncNodePlugin: JSBasePlugin, NativePlugin { for plugin in plugins { plugin.context = self.context } - + return [["plugins": plugins.map { $0.pluginRef }]] } - + override open func getUrlForFile(fileName: String) -> URL? { #if SWIFT_PACKAGE ResourceUtilities.urlForFile(name: fileName, ext: "js", bundle: Bundle.module) @@ -140,10 +140,10 @@ public struct AsyncNodeHook { public enum ReplacementNode: Encodable { case concrete(JSValue) case encodable(Encodable) - + public func encode(to encoder: Encoder) throws { var container = encoder.singleValueContainer() - + switch self { case .encodable(let value): try container.encode(value) @@ -157,12 +157,12 @@ public struct AssetPlaceholderNode: Encodable { public enum CodingKeys: String, CodingKey { case asset } - + var asset: Encodable public init(asset: Encodable) { self.asset = asset } - + public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try? container.encode(asset, forKey: .asset) @@ -185,7 +185,7 @@ public class AsyncNodePluginPlugin: JSBasePlugin { public convenience init() { self.init(fileName: "AsyncNodePlugin.native", pluginName: "AsyncNodePlugin.AsyncNodePluginPlugin") } - + override open func getUrlForFile(fileName: String) -> URL? { #if SWIFT_PACKAGE ResourceUtilities.urlForFile(name: fileName, ext: "js", bundle: Bundle.module)