1 /// This file implements definition components that are allowed in any object-based definition — `ObjectDefinition`.
2 /// So far only constants and functions belong to plain object.
3 
4 // MARK: - Constants
5 
6 /**
7  Definition function setting the module's constants to export.
8  */
9 public func Constants(@_implicitSelfCapture _ body: @escaping () -> [String: Any?]) -> AnyDefinition {
10   return ConstantsDefinition(body: body)
11 }
12 
13 /**
14  Definition function setting the module's constants to export.
15  */
16 public func Constants(@_implicitSelfCapture _ body: @autoclosure @escaping () -> [String: Any?]) -> AnyDefinition {
17   return ConstantsDefinition(body: body)
18 }
19 
20 // MARK: - Events
21 
22 /**
23  Defines event names that the object can send to JavaScript.
24  */
25 public func Events(_ names: String...) -> EventsDefinition {
26   return EventsDefinition(names: names)
27 }
28 
29 /**
30  Function that is invoked when the first event listener is added.
31  */
32 public func OnStartObserving(@_implicitSelfCapture _ body: @escaping () -> Void) -> AsyncFunctionComponent<(), Void, Void> {
33   return AsyncFunctionComponent("startObserving", firstArgType: Void.self, dynamicArgumentTypes: [], body)
34 }
35 
36 /**
37  Function that is invoked when all event listeners are removed.
38  */
39 public func OnStopObserving(@_implicitSelfCapture _ body: @escaping () -> Void) -> AsyncFunctionComponent<(), Void, Void> {
40   return AsyncFunctionComponent("stopObserving", firstArgType: Void.self, dynamicArgumentTypes: [], body)
41 }
42