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: - Object
5
6 public func Object(@ObjectDefinitionBuilder @_implicitSelfCapture _ body: () -> [AnyDefinition]) -> ObjectDefinition {
7 return ObjectDefinition(definitions: body())
8 }
9
10 // MARK: - Constants
11
12 /**
13 Definition function setting the module's constants to export.
14 */
15 public func Constants(@_implicitSelfCapture _ body: @escaping () -> [String: Any?]) -> AnyDefinition {
16 return ConstantsDefinition(body: body)
17 }
18
19 /**
20 Definition function setting the module's constants to export.
21 */
22 public func Constants(@_implicitSelfCapture _ body: @autoclosure @escaping () -> [String: Any?]) -> AnyDefinition {
23 return ConstantsDefinition(body: body)
24 }
25
26 // MARK: - Events
27
28 /**
29 Defines event names that the object can send to JavaScript.
30 */
Eventsnull31 public func Events(_ names: String...) -> EventsDefinition {
32 return EventsDefinition(names: names)
33 }
34
35 /**
36 Defines event names that the object can send to JavaScript.
37 */
Eventsnull38 public func Events(_ names: [String]) -> EventsDefinition {
39 return EventsDefinition(names: names)
40 }
41
42 /**
43 Function that is invoked when the first event listener is added.
44 */
45 public func OnStartObserving(@_implicitSelfCapture _ body: @escaping () -> Void) -> AsyncFunctionComponent<(), Void, Void> {
46 return AsyncFunctionComponent("startObserving", firstArgType: Void.self, dynamicArgumentTypes: [], body)
47 }
48
49 /**
50 Function that is invoked when all event listeners are removed.
51 */
52 public func OnStopObserving(@_implicitSelfCapture _ body: @escaping () -> Void) -> AsyncFunctionComponent<(), Void, Void> {
53 return AsyncFunctionComponent("stopObserving", firstArgType: Void.self, dynamicArgumentTypes: [], body)
54 }
55