Skip to content

Instantly share code, notes, and snippets.

@lukesutton
Created November 28, 2016 01:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lukesutton/b3b5a37ae85c9ad13f4b62032f668473 to your computer and use it in GitHub Desktop.
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