StackReconciler prototyping

This commit is contained in:
Max Desiatov 2018-11-28 09:56:24 +00:00
parent 1cec3f9610
commit 093c0b6881
No known key found for this signature in database
GPG Key ID: FE08EBF9CF58CBA2
3 changed files with 55 additions and 26 deletions

View File

@ -0,0 +1,55 @@
//
// StackReconciler.swift
// Gluon
//
// Created by Max Desiatov on 28/11/2018.
//
private let _hooks = Hooks()
extension Component {
public static var hooks: Hooks {
return _hooks
}
}
public struct Hooks {
public func state<T>(_ initial: T,
id: Int = #line) -> (T, (T) -> ()) {
return (initial, { _ in })
}
}
struct Pair<T: Hashable, U: Hashable>: Hashable {
let first: T
let second: U
}
final class NodeReference {
let key: String?
let props: AnyEquatable
let children: AnyEquatable
let type: _Component.Type
init(node: Node) {
self.key = node.key
self.props = node.props
self.children = node.children
self.type = node.type
}
}
final class StackReconciler {
/// A map from a fully qualified component type name and its state hook id
/// to a current state value.
var state = [Pair<String, Int>: Any]()
let root: NodeReference
func reconcile(node reference: NodeReference, with node: Node) {
}
init(root: Node) {
self.root = NodeReference(node: root)
}
}

View File

@ -51,21 +51,6 @@ public extension LeafComponent {
}
}
public struct Hooks {
public func state<T>(_ initial: T,
id: String = "\(#file)\(#line)") -> (T, (T) -> ()) {
return (initial, { _ in })
}
}
private let _hooks = Hooks()
extension Component {
public static var hooks: Hooks {
return _hooks
}
}
public struct Node: Equatable {
/// Equatable can't be automatically derived for `type` property?
public static func == (lhs: Node, rhs: Node) -> Bool {

View File

@ -13,10 +13,6 @@ protocol Renderer {
func umount(target: Any, from parent: Any, with component: RendererBaseComponent)
}
protocol Reconciler {
func reconcile(node: Node)
}
protocol RendererBaseComponent {
}
@ -24,13 +20,6 @@ protocol RendererBaseComponent {
protocol UIKitBaseComponent: RendererBaseComponent {
}
struct StackReconciler: Reconciler {
func reconcile(node: Node) {
}
}
struct UIKitRenderer {
}