Skip to content

Commit

Permalink
🖥 DOM implement DOM.print method
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaelIsaev committed Mar 31, 2023
1 parent 4efddbb commit 5f0cad4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/DOM/AnyElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ extension _BaseContentElementable {
switch item {
case .elements(let elements): elements.forEach { appendChild($0) }
case .items(let items): items.forEach { parseDOMItem($0) }
case .print(let print): Console.log(print.items)
case .none: break
}
}
Expand Down
21 changes: 21 additions & 0 deletions Sources/DOM/DOM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum DOMItem {
case none
case elements([DOMElement])
case items([DOMItem])
case print(DOMPrint)
}

private struct EmptyContent: DOMContent {
Expand Down Expand Up @@ -79,3 +80,23 @@ extension Optional: DOMContent where Wrapped: DOMElement {
}
}
}

public struct DOMPrint: DOMContent {
public var domContentItem: DOMItem { .print(self) }

let items: [ConvertibleToJSValue]

public init (_ items: [ConvertibleToJSValue]) {
self.items = items
}

public init (_ items: ConvertibleToJSValue...) {
self.items = items
}
}

extension DOM {
public static func print(_ items: ConvertibleToJSValue...) -> DOMPrint {
.init(items)
}
}
1 change: 1 addition & 0 deletions Sources/DOM/ForEach.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public class ForEach<Item>: BaseElement, ScrollHandleable, AlignAttrable where I
switch item {
case .elements(let elements): elements.forEach { appendChild($0) }
case .items(let items): items.forEach { parseDOMItem($0) }
case .print(let print): Console.log(print.items)
case .none: break
}
}
Expand Down

0 comments on commit 5f0cad4

Please sign in to comment.