Rename BaseComponent to HostComponent

This commit is contained in:
Max Desiatov 2018-12-02 10:33:35 +00:00
parent 01c3cd3702
commit 25be5f14da
No known key found for this signature in database
GPG Key ID: FE08EBF9CF58CBA2
6 changed files with 27 additions and 34 deletions

View File

@ -122,7 +122,7 @@ public struct ConstraintProps: Equatable {
}
}
public struct Constraint: BaseComponent {
public struct Constraint: HostComponent {
public typealias Props = ConstraintProps
public typealias Children = [Node]

View File

@ -29,11 +29,11 @@ final class MountedCompositeComponent: MountedComponent {
}
}
final class MountedBaseComponent: MountedComponent {
let type: AnyBaseComponent.Type
final class MountedHostComponent: MountedComponent {
let type: AnyHostComponent.Type
let target: Any
init(_ node: Node, _ type: AnyBaseComponent.Type, _ target: Any) {
init(_ node: Node, _ type: AnyHostComponent.Type, _ target: Any) {
self.type = type
self.target = target

View File

@ -20,7 +20,7 @@ public struct Node: Equatable {
let type: ComponentType
}
extension BaseComponent {
extension HostComponent {
public static func node(key: String? = nil,
_ props: Props,
_ children: Children) -> Node {

View File

@ -9,18 +9,20 @@ import Foundation
protocol Renderer: class {
func mountTarget(to parent: Any,
with component: AnyBaseComponent.Type,
with component: AnyHostComponent.Type,
props: AnyEquatable,
children: AnyEquatable) -> Any
func update(target: Any,
with component: AnyBaseComponent.Type,
with component: AnyHostComponent.Type,
props: AnyEquatable,
children: AnyEquatable)
func umount(target: Any,
from parent: Any,
with component: AnyBaseComponent.Type,
with component: AnyHostComponent.Type,
props: AnyEquatable,
children: AnyEquatable)
func removeAllChildren(from target: Any)
}

View File

@ -34,7 +34,7 @@ final class StackReconciler {
props: node.props,
children: node.children)
rootComponent = MountedBaseComponent(node, type, target)
rootComponent = MountedHostComponent(node, type, target)
case let .composite(type):
let component = MountedCompositeComponent(node, type)
@ -82,25 +82,16 @@ final class StackReconciler {
with renderedNode: Node) {
let parentTarget = rootTarget
var stack = [(component, 0)]
var stack = [(component, renderedNode, 0)]
while !stack.isEmpty {
let (component, childIndex) = stack.removeLast()
let (component, node, childIndex) = stack.removeLast()
for child in component.mountedChildren {
switch (child, renderedNode.type) {
case let (child, .composite(nodeType))
as (MountedCompositeComponent, ComponentType):
guard child.type == nodeType &&
child.props == renderedNode.props &&
child.children == renderedNode.children else {
// FIXME: continue?
return
}
default:
assertionFailure("unhandled case to reconcile")
}
}
// switch node.children.value {
// case let child as Node:
//
// }
if component.mountedChildren.isEmpty {
// FIXME: handle fragment nodes here when those are introduced
@ -113,7 +104,7 @@ final class StackReconciler {
props: renderedNode.props,
children: renderedNode.children)
mountedChild = MountedBaseComponent(renderedNode, type, target)
mountedChild = MountedHostComponent(renderedNode, type, target)
case let .composite(type):
mountedChild = MountedCompositeComponent(renderedNode, type)
}

View File

@ -14,10 +14,10 @@ extension Never: Equatable {
}
}
public protocol AnyBaseComponent {
public protocol AnyHostComponent {
}
public protocol BaseComponent: AnyBaseComponent {
public protocol HostComponent: AnyHostComponent {
associatedtype Props: Equatable
associatedtype Children: ChildrenType & Equatable
}
@ -71,7 +71,7 @@ enum ComponentType: Equatable {
}
}
case base(AnyBaseComponent.Type)
case base(AnyHostComponent.Type)
case composite(AnyCompositeComponent.Type)
var composite: AnyCompositeComponent.Type? {
@ -80,14 +80,14 @@ enum ComponentType: Equatable {
return type
}
var base: AnyBaseComponent.Type? {
var base: AnyHostComponent.Type? {
guard case let .base(type) = self else { return nil }
return type
}
}
public struct View: BaseComponent {
public struct View: HostComponent {
public typealias Children = [Node]
public let props: Props
@ -97,7 +97,7 @@ public struct View: BaseComponent {
}
}
public struct Label: BaseComponent {
public struct Label: HostComponent {
public typealias Props = Null
public typealias Children = String
}
@ -116,12 +116,12 @@ public struct ButtonProps: Equatable {
}
}
public struct Button: BaseComponent {
public struct Button: HostComponent {
public typealias Props = ButtonProps
public typealias Children = String
}
public struct StackView: BaseComponent {
public struct StackView: HostComponent {
public typealias Props = Null
public typealias Children = [Node]
}