1 // Copyright 2021-present 650 Industries. All rights reserved. 2 3 /** 4 `BaseModule` is just a stub class that fulfils `AnyModule` protocol requirement of public default initializer, 5 but doesn't implement that protocol explicitly, though — it would have to provide a definition which would require 6 other modules to use `override` keyword in the function returning the definition. 7 */ 8 open class BaseModule { 9 public private(set) weak var appContext: AppContext? 10 11 @available(*, unavailable, message: "Module's initializer cannot be overriden, use \"onCreate\" definition component instead.") 12 public init() {} 13 14 required public init(appContext: AppContext) { 15 self.appContext = appContext 16 } 17 18 /** 19 Sends an event with given name and body to JavaScript. 20 */ sendEventnull21 public func sendEvent(_ eventName: String, _ body: [String: Any?] = [:]) { 22 appContext?.eventEmitter?.sendEvent(withName: eventName, body: body) 23 } 24 } 25 26 /** 27 An alias for `AnyModule` extended by the `BaseModule` class that provides public default initializer. 28 */ 29 public typealias Module = AnyModule & BaseModule 30