Skip to content

Commit

Permalink
Merge pull request #42 from ra1028/deprecate-closure-render
Browse files Browse the repository at this point in the history
Deprecate closure style render function
  • Loading branch information
ra1028 committed Sep 4, 2019
2 parents 8ff8523 + 34b9828 commit 80a66f1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Sources/AnyComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,42 +156,42 @@ internal protocol AnyComponentBox {
@usableFromInline
internal struct ComponentBox<Base: Component>: AnyComponentBox {
@usableFromInline
internal let baseComponent: Base
let baseComponent: Base

@inlinable
internal var base: Any {
var base: Any {
return baseComponent
}

@inlinable
internal var reuseIdentifier: String {
var reuseIdentifier: String {
return baseComponent.reuseIdentifier
}

@inlinable
internal init(_ base: Base) {
init(_ base: Base) {
baseComponent = base
}

@inlinable
internal func renderContent() -> Any {
func renderContent() -> Any {
return baseComponent.renderContent()
}

@inlinable
internal func render(in content: Any) {
func render(in content: Any) {
guard let content = content as? Base.Content else { return }

baseComponent.render(in: content)
}

@inlinable
internal func referenceSize(in bounds: CGRect) -> CGSize? {
func referenceSize(in bounds: CGRect) -> CGSize? {
return baseComponent.referenceSize(in: bounds)
}

@inlinable
internal func layout(content: Any, in container: UIView) {
func layout(content: Any, in container: UIView) {
guard let content = content as? Base.Content else { return }

baseComponent.layout(content: content, in: container)
Expand All @@ -212,14 +212,14 @@ internal struct ComponentBox<Base: Component>: AnyComponentBox {
}

@inlinable
internal func contentWillDisplay(_ content: Any) {
func contentWillDisplay(_ content: Any) {
guard let content = content as? Base.Content else { return }

baseComponent.contentWillDisplay(content)
}

@inlinable
internal func contentDidEndDisplay(_ content: Any) {
func contentDidEndDisplay(_ content: Any) {
guard let content = content as? Base.Content else { return }

baseComponent.contentDidEndDisplay(content)
Expand Down
1 change: 1 addition & 0 deletions Sources/Renderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ open class Renderer<Updater: Carbon.Updater> {
///
/// - Parameters:
/// - buildData: A closure to build sections.
@available(*, deprecated, message: "This method will be removed next version owing to avoid ambiguity with new syntax using function builder.")
open func render(_ buildData: (inout [Section]) -> Void) {
var data = [Section]()
buildData(&data)
Expand Down
1 change: 1 addition & 0 deletions Sources/Section.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public struct Section {
/// - Parameters:
/// - id: An identifier to be wrapped.
/// - buildSection: A closure to build section.
@available(*, deprecated, message: "This method will be removed next version owing to avoid ambiguity with new syntax using function builder.")
@inlinable
public init<I: Hashable>(id: I, _ buildSection: (inout Section) -> Void) {
var section = Section(id: id)
Expand Down
1 change: 1 addition & 0 deletions Tests/RendererTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ final class RendererTests: XCTestCase {
XCTAssertEqual(renderer.updater.adapterCapturedOnUpdates, adapter)
}

@available(*, deprecated)
func testRenderWithBuilderClosure() {
let target = MockTarget()
let adapter = MockAdapter()
Expand Down
1 change: 1 addition & 0 deletions Tests/SectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ final class SectionTests: XCTestCase {
XCTAssertEqual(section.cells.count, 2)
}

@available(*, deprecated)
func testInitWithBuilderClosure() {
let section = Section(id: TestID.a) { section in
section.header = ViewNode(A.Component())
Expand Down

0 comments on commit 80a66f1

Please sign in to comment.