Created
November 28, 2016 01:24
-
-
Save lukesutton/b3b5a37ae85c9ad13f4b62032f668473 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Property<N> { | |
typealias N = N | |
func toPropertyList() -> PropertyList<N> { | |
return PropertyList<N>(properties: [self]) | |
} | |
} | |
struct PropertyList<N>: PropertyListConvertible { | |
typealias N = N | |
let properties: [Property<N>] | |
func toPropertyList() -> PropertyList<N> { | |
return self | |
} | |
} | |
protocol PropertyListConvertible { | |
associatedtype N | |
func toPropertyList() -> PropertyList<N> | |
} | |
protocol ComponentType {} | |
struct Component<N>: ComponentType { | |
let id: Identifier<N> | |
let properties: [Property<N>] | |
let children: [ComponentType] | |
} | |
extension Component { | |
static func button<P>(_ id: String, _ properties: P...) -> ComponentType | |
where P: PropertyListConvertible, P.N == UIButton { | |
return Component<UIButton>(id: Identifier<UIButton>(id), properties: properties.map { $0.toPropertyList() }, children: []) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment