Apply SwiftFormat changes
This commit is contained in:
parent
0ba1d1c616
commit
e4ea316b3a
|
@ -0,0 +1,6 @@
|
|||
--indent 2
|
||||
--indentcase false
|
||||
--trimwhitespace always
|
||||
--ranges nospace
|
||||
--empty tuple
|
||||
--operatorfunc nospace
|
|
@ -10,37 +10,32 @@ import UIKit
|
|||
|
||||
@UIApplicationMain
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
var window: UIWindow?
|
||||
|
||||
var window: UIWindow?
|
||||
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
return true
|
||||
}
|
||||
|
||||
func applicationWillResignActive(_: UIApplication) {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
return true
|
||||
}
|
||||
func applicationDidEnterBackground(_: UIApplication) {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
}
|
||||
|
||||
func applicationWillResignActive(_ application: UIApplication) {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
func applicationDidEnterBackground(_ application: UIApplication) {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
}
|
||||
|
||||
func applicationWillEnterForeground(_ application: UIApplication) {
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(_ application: UIApplication) {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
func applicationWillEnterForeground(_: UIApplication) {
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(_: UIApplication) {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
// Copyright (c) 2018 Max Desiatov. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Gluon
|
||||
import UIKit
|
||||
|
||||
//struct TodoList: Store {
|
||||
// struct TodoList: Store {
|
||||
// enum Action {
|
||||
// case add(String, Int)
|
||||
// case remove(Int)
|
||||
|
@ -28,7 +28,7 @@ import Gluon
|
|||
// state.remove(at: index)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
// }
|
||||
|
||||
struct Counter: LeafComponent {
|
||||
struct Props: Equatable {
|
||||
|
@ -46,8 +46,8 @@ struct Counter: LeafComponent {
|
|||
return StackView.node(.init(axis: .vertical,
|
||||
distribution: .fillEqually,
|
||||
frame: props.frame), [
|
||||
Button.node(.init(handlers: [.touchUpInside: handler]), "Increment"),
|
||||
Label.node(Null(), "\(count)")
|
||||
Button.node(.init(handlers: [.touchUpInside: handler]), "Increment"),
|
||||
Label.node(Null(), "\(count)"),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ final class GluonViewController: UIViewController {
|
|||
target: view)
|
||||
}
|
||||
|
||||
@IBAction func onTap(_ sender: Any) {
|
||||
@IBAction func onTap(_: Any) {
|
||||
// let counters = (0..<1_000_000).map { _ in Counter(props: NoProps(), children: []) }
|
||||
print(#file)
|
||||
}
|
||||
|
@ -98,4 +98,3 @@ final class ClassicViewController: UIViewController {
|
|||
view.addSubview(label)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,25 +9,23 @@
|
|||
import XCTest
|
||||
|
||||
class GluonTest: XCTestCase {
|
||||
override func setUp() {
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func setUp() {
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
func testExample() {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||
}
|
||||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
measure {
|
||||
// Put the code you want to measure the time of here.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
func testExample() {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||
}
|
||||
|
||||
func testPerformanceExample() {
|
||||
// This is an example of a performance test case.
|
||||
self.measure {
|
||||
// Put the code you want to measure the time of here.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,37 +4,44 @@
|
|||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "Gluon",
|
||||
products: [
|
||||
// Products define the executables and libraries produced by a package, and make them visible to other packages.
|
||||
.library(
|
||||
name: "Gluon",
|
||||
targets: ["Gluon"]),
|
||||
.library(
|
||||
name: "GluonUIKit",
|
||||
targets: ["GluonUIKit"]),
|
||||
.library(
|
||||
name: "GluonTestRenderer",
|
||||
targets: ["GluonTestRenderer"]),
|
||||
],
|
||||
dependencies: [
|
||||
// Dependencies declare other packages that this package depends on.
|
||||
// .package(url: /* package url */, from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
|
||||
.target(
|
||||
name: "Gluon",
|
||||
dependencies: []),
|
||||
.target(
|
||||
name: "GluonUIKit",
|
||||
dependencies: ["Gluon"]),
|
||||
.target(
|
||||
name: "GluonTestRenderer",
|
||||
dependencies: ["Gluon"]),
|
||||
.testTarget(
|
||||
name: "GluonTests",
|
||||
dependencies: ["GluonTestRenderer"]),
|
||||
]
|
||||
name: "Gluon",
|
||||
products: [
|
||||
// Products define the executables and libraries produced by a package, and make them visible to other packages.
|
||||
.library(
|
||||
name: "Gluon",
|
||||
targets: ["Gluon"]
|
||||
),
|
||||
.library(
|
||||
name: "GluonUIKit",
|
||||
targets: ["GluonUIKit"]
|
||||
),
|
||||
.library(
|
||||
name: "GluonTestRenderer",
|
||||
targets: ["GluonTestRenderer"]
|
||||
),
|
||||
],
|
||||
dependencies: [
|
||||
// Dependencies declare other packages that this package depends on.
|
||||
// .package(url: /* package url */, from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
|
||||
.target(
|
||||
name: "Gluon",
|
||||
dependencies: []
|
||||
),
|
||||
.target(
|
||||
name: "GluonUIKit",
|
||||
dependencies: ["Gluon"]
|
||||
),
|
||||
.target(
|
||||
name: "GluonTestRenderer",
|
||||
dependencies: ["Gluon"]
|
||||
),
|
||||
.testTarget(
|
||||
name: "GluonTests",
|
||||
dependencies: ["GluonTestRenderer"]
|
||||
),
|
||||
]
|
||||
)
|
||||
|
|
|
@ -5,17 +5,16 @@
|
|||
// Created by Max Desiatov on 06/11/2018.
|
||||
//
|
||||
|
||||
|
||||
public struct AnyEquatable: Equatable {
|
||||
public let value: Any
|
||||
private let equals: (Any) -> Bool
|
||||
|
||||
public init<E: Equatable>(_ value: E) {
|
||||
self.value = value
|
||||
self.equals = { ($0 as? E) == value }
|
||||
equals = { ($0 as? E) == value }
|
||||
}
|
||||
|
||||
public static func == (lhs: AnyEquatable, rhs: AnyEquatable) -> Bool {
|
||||
public static func ==(lhs: AnyEquatable, rhs: AnyEquatable) -> Bool {
|
||||
return lhs.equals(rhs.value) || rhs.equals(lhs.value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@ final class CompositeComponentWrapper: ComponentWrapper {
|
|||
|
||||
func update(with reconciler: StackReconciler) {
|
||||
switch (mountedChildren.last, render(with: reconciler)) {
|
||||
|
||||
// no mounted children, but children available now
|
||||
case let (nil, renderedNode):
|
||||
let child = renderedNode.makeComponentWrapper(parentTarget)
|
||||
|
@ -53,20 +52,20 @@ final class CompositeComponentWrapper: ComponentWrapper {
|
|||
// some mounted children
|
||||
case let (wrapper?, renderedNode):
|
||||
// new node is the same type as existing child, checking props/children
|
||||
if wrapper.node.type == renderedNode.type &&
|
||||
if wrapper.node.type == renderedNode.type,
|
||||
(wrapper.node.props != renderedNode.props ||
|
||||
wrapper.node.children != renderedNode.children) {
|
||||
wrapper.node = renderedNode
|
||||
wrapper.update(with: reconciler)
|
||||
} else
|
||||
// new node is of different type, complete rerender, i.e. unmount old
|
||||
// wrapper, then mount a new one with new node
|
||||
if wrapper.node.type != renderedNode.type {
|
||||
wrapper.unmount(with: reconciler)
|
||||
// new node is of different type, complete rerender, i.e. unmount old
|
||||
// wrapper, then mount a new one with new node
|
||||
if wrapper.node.type != renderedNode.type {
|
||||
wrapper.unmount(with: reconciler)
|
||||
|
||||
let child = renderedNode.makeComponentWrapper(parentTarget)
|
||||
mountedChildren = [child]
|
||||
child.mount(with: reconciler)
|
||||
let child = renderedNode.makeComponentWrapper(parentTarget)
|
||||
mountedChildren = [child]
|
||||
child.mount(with: reconciler)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ final class HostComponentWrapper: ComponentWrapper {
|
|||
with: type,
|
||||
props: node.props,
|
||||
children: node.children)
|
||||
else { return }
|
||||
else { return }
|
||||
|
||||
self.target = target
|
||||
|
||||
|
@ -76,9 +76,9 @@ final class HostComponentWrapper: ComponentWrapper {
|
|||
var newChildren = [ComponentWrapper]()
|
||||
|
||||
while let child = mountedChildren.first, let node = nodes.first {
|
||||
if node.key != nil &&
|
||||
node.type == mountedChildren[0].node.type &&
|
||||
node.key == child.node.key {
|
||||
if node.key != nil,
|
||||
node.type == mountedChildren[0].node.type,
|
||||
node.key == child.node.key {
|
||||
child.node = node
|
||||
child.update(with: reconciler)
|
||||
newChildren.append(child)
|
||||
|
@ -108,7 +108,7 @@ final class HostComponentWrapper: ComponentWrapper {
|
|||
child.mount(with: reconciler)
|
||||
}
|
||||
|
||||
// child type that can't be rendered, but still makes sense as a child
|
||||
// child type that can't be rendered, but still makes sense as a child
|
||||
// (e.g. `String`)
|
||||
default:
|
||||
()
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
// Created by Max Desiatov on 06/11/2018.
|
||||
//
|
||||
|
||||
|
||||
public struct Hooks {
|
||||
var currentReconciler: StackReconciler?
|
||||
var currentComponent: CompositeComponentWrapper?
|
||||
|
@ -13,7 +12,7 @@ public struct Hooks {
|
|||
public func state<T>(_ initial: T,
|
||||
id: String = "\(#file)\(#line)") -> (T, (T) -> ()) {
|
||||
guard let component = currentComponent,
|
||||
let reconciler = currentReconciler else {
|
||||
let reconciler = currentReconciler else {
|
||||
fatalError("""
|
||||
attempt to use `state` hook outside of a `render` function,
|
||||
or `render` is not called from a renderer
|
||||
|
@ -27,7 +26,7 @@ public struct Hooks {
|
|||
// owned by callbacks owned by node's target, which is strongly referenced
|
||||
// from node. Same with the reconciler.
|
||||
guard let component = component,
|
||||
let reconciler = reconciler else { return }
|
||||
let reconciler = reconciler else { return }
|
||||
|
||||
reconciler.queue(state: new, for: component, id: id) })
|
||||
}
|
||||
|
|
|
@ -100,15 +100,15 @@ public struct ConstraintProps: Equatable {
|
|||
public let width: Size?
|
||||
|
||||
public init(baseline: VerticalLocation? = nil,
|
||||
bottom: VerticalLocation? = nil,
|
||||
center: Center? = nil,
|
||||
centerX: HorizontalLocation? = nil,
|
||||
centerY: VerticalLocation? = nil,
|
||||
height: Size? = nil,
|
||||
left: HorizontalLocation? = nil,
|
||||
right: HorizontalLocation? = nil,
|
||||
top: VerticalLocation? = nil,
|
||||
width: Size? = nil) {
|
||||
bottom: VerticalLocation? = nil,
|
||||
center: Center? = nil,
|
||||
centerX: HorizontalLocation? = nil,
|
||||
centerY: VerticalLocation? = nil,
|
||||
height: Size? = nil,
|
||||
left: HorizontalLocation? = nil,
|
||||
right: HorizontalLocation? = nil,
|
||||
top: VerticalLocation? = nil,
|
||||
width: Size? = nil) {
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.centerX = centerX
|
||||
|
@ -125,6 +125,4 @@ public struct ConstraintProps: Equatable {
|
|||
public struct Constraint: HostComponent {
|
||||
public typealias Props = ConstraintProps
|
||||
public typealias Children = [Node]
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -60,17 +60,12 @@ extension LeafComponent {
|
|||
|
||||
/// Conforming to this protocol, but implementing support for these new types
|
||||
/// in a renderer would make that renderer skip unknown types of children.
|
||||
public protocol ChildrenType {
|
||||
}
|
||||
public protocol ChildrenType {}
|
||||
|
||||
extension Null: ChildrenType {
|
||||
}
|
||||
extension Null: ChildrenType {}
|
||||
|
||||
extension Node: ChildrenType {
|
||||
}
|
||||
extension Node: ChildrenType {}
|
||||
|
||||
extension Array: ChildrenType where Element == Node {
|
||||
}
|
||||
extension Array: ChildrenType where Element == Node {}
|
||||
|
||||
extension String: ChildrenType {
|
||||
}
|
||||
extension String: ChildrenType {}
|
||||
|
|
|
@ -20,19 +20,19 @@
|
|||
have problems with targets cast to a wrong type. It's an invalid behaviour for
|
||||
a user to create children nodes of a wrong type and renderer code is supposed
|
||||
to trigger an assertion failure in this case to avoid wrong type casts later.
|
||||
*/
|
||||
*/
|
||||
public protocol Renderer: class {
|
||||
/** Function called by a reconciler when a new target instance should be
|
||||
created.
|
||||
- parameter parent: Parent target that will own a newly created target
|
||||
instance.
|
||||
instance.
|
||||
- parameter component: Type of the base component that renders to the
|
||||
newly created target.
|
||||
newly created target.
|
||||
- parameter props: Props used to configure the new target.
|
||||
- parameter children: Children of the rendered base component for the new
|
||||
target.
|
||||
target.
|
||||
- returns: The newly created target.
|
||||
*/
|
||||
*/
|
||||
func mountTarget(to parent: Any,
|
||||
with component: AnyHostComponent.Type,
|
||||
props: AnyEquatable,
|
||||
|
@ -42,14 +42,14 @@ public protocol Renderer: class {
|
|||
updated.
|
||||
- parameter target: Existing target instance to be updated.
|
||||
- parameter component: Type of the base component that renders to the
|
||||
updated target.
|
||||
updated target.
|
||||
- parameter props: Props used to configure the existing target. This props
|
||||
value can be different from props passed on previous
|
||||
updates or on target creation. The props value is wrapped
|
||||
with `AnyEquatable` for type-erasure purposes.
|
||||
value can be different from props passed on previous
|
||||
updates or on target creation. The props value is wrapped
|
||||
with `AnyEquatable` for type-erasure purposes.
|
||||
- parameter children: Children used to configure the existing target. These
|
||||
children can be different from children passed on
|
||||
previous updates or on target creation.
|
||||
children can be different from children passed on
|
||||
previous updates or on target creation.
|
||||
*/
|
||||
func update(target: Any,
|
||||
with component: AnyHostComponent.Type,
|
||||
|
|
|
@ -58,8 +58,8 @@ public protocol Store {
|
|||
}
|
||||
|
||||
// FIXME: need context working for its implementation
|
||||
//public final class StoreProvider<S>: Component<StoreProvider.Props, S>
|
||||
//where S: Store & StateType {
|
||||
// public final class StoreProvider<S>: Component<StoreProvider.Props, S>
|
||||
// where S: Store & StateType {
|
||||
// struct Props: Equatable {
|
||||
// /// FIXME: should store comparison be optimised this way?
|
||||
// let store: Unique<S>
|
||||
|
@ -73,13 +73,13 @@ public protocol Store {
|
|||
// // FIXME: create a context here
|
||||
// return Node(children)
|
||||
// }
|
||||
//}
|
||||
// }
|
||||
//
|
||||
//typealias Dispatch<Action> = (Action) -> ()
|
||||
//typealias Dispatcher<S: Store> = (state: S.State, dispatch: Dispatch<S.Action>)
|
||||
|
||||
// FIXME: when contexts are available read state and dispatch
|
||||
// from the context and pass it to the mapper
|
||||
//func storeAccess<S: Store>(_ mapper: (Dispatcher<S>) -> Node) {
|
||||
// func storeAccess<S: Store>(_ mapper: (Dispatcher<S>) -> Node) {
|
||||
//
|
||||
//}
|
||||
// }
|
||||
|
|
|
@ -8,14 +8,12 @@
|
|||
import Foundation
|
||||
|
||||
extension Never: Equatable {
|
||||
public static func == (lhs: Never, rhs: Never) -> Bool {
|
||||
switch (lhs, rhs) {
|
||||
}
|
||||
public static func ==(lhs: Never, rhs: Never) -> Bool {
|
||||
switch (lhs, rhs) {}
|
||||
}
|
||||
}
|
||||
|
||||
public protocol AnyHostComponent {
|
||||
}
|
||||
public protocol AnyHostComponent {}
|
||||
|
||||
public protocol HostComponent: AnyHostComponent {
|
||||
associatedtype Props: Equatable
|
||||
|
@ -39,7 +37,7 @@ public protocol CompositeComponent: AnyCompositeComponent {
|
|||
public extension CompositeComponent {
|
||||
static func render(props: AnyEquatable, children: AnyEquatable) -> Node {
|
||||
guard let props = props.value as? Props,
|
||||
let children = children.value as? Children else {
|
||||
let children = children.value as? Children else {
|
||||
fatalError("""
|
||||
incorrect types of `props` and `children` arguments passed to
|
||||
`AnyComponent.render`
|
||||
|
@ -54,13 +52,13 @@ public protocol LeafComponent: CompositeComponent where Children == Null {
|
|||
}
|
||||
|
||||
public extension LeafComponent {
|
||||
public static func render(props: Props, children: Children) -> Node {
|
||||
public static func render(props: Props, children _: Children) -> Node {
|
||||
return render(props: props)
|
||||
}
|
||||
}
|
||||
|
||||
enum ComponentType: Equatable {
|
||||
static func == (lhs: ComponentType, rhs: ComponentType) -> Bool {
|
||||
static func ==(lhs: ComponentType, rhs: ComponentType) -> Bool {
|
||||
switch (lhs, rhs) {
|
||||
case let (.base(ltype), .base(rtype)):
|
||||
return ltype == rtype
|
||||
|
@ -93,6 +91,5 @@ public struct View: HostComponent {
|
|||
public let props: Props
|
||||
public let children: [Node]
|
||||
|
||||
public struct Props: Equatable {
|
||||
}
|
||||
public struct Props: Equatable {}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,7 @@ enum ArrayChange<T> {
|
|||
case batchRemove(Range<Int>)
|
||||
}
|
||||
|
||||
struct ArrayChanges {
|
||||
|
||||
}
|
||||
struct ArrayChanges {}
|
||||
|
||||
struct VersionedArray<T> {
|
||||
let startIndex = 0
|
||||
|
@ -49,20 +47,15 @@ struct VersionedArray<T> {
|
|||
currentVersion = ArrayVersion()
|
||||
}
|
||||
|
||||
func changes(since: ArrayVersion) -> ArrayChanges? {
|
||||
func changes(since _: ArrayVersion) -> ArrayChanges? {
|
||||
return nil
|
||||
}
|
||||
|
||||
mutating func apply(_ changes: ArrayChanges) {
|
||||
mutating func apply(_: ArrayChanges) {}
|
||||
|
||||
}
|
||||
mutating func flush(_: ArrayVersion) {}
|
||||
|
||||
mutating func flush(_ version: ArrayVersion) {
|
||||
|
||||
}
|
||||
|
||||
mutating func flushAllVersions() {
|
||||
}
|
||||
mutating func flushAllVersions() {}
|
||||
}
|
||||
|
||||
extension VersionedArray: ExpressibleByArrayLiteral {
|
||||
|
|
|
@ -14,20 +14,16 @@ public class TestRenderer: Renderer {
|
|||
reconciler = StackReconciler(node: node, target: TestView(props: AnyEquatable(Null())), renderer: self)
|
||||
}
|
||||
|
||||
public func mountTarget(to parent: Any,
|
||||
with component: AnyHostComponent.Type,
|
||||
props: AnyEquatable, children: AnyEquatable) -> Any? {
|
||||
public func mountTarget(to _: Any,
|
||||
with _: AnyHostComponent.Type,
|
||||
props _: AnyEquatable, children _: AnyEquatable) -> Any? {
|
||||
return nil
|
||||
}
|
||||
|
||||
public func update(target: Any,
|
||||
with component: AnyHostComponent.Type,
|
||||
props: AnyEquatable,
|
||||
children: AnyEquatable) {
|
||||
public func update(target _: Any,
|
||||
with _: AnyHostComponent.Type,
|
||||
props _: AnyEquatable,
|
||||
children _: AnyEquatable) {}
|
||||
|
||||
}
|
||||
|
||||
public func unmount(target: Any, with component: AnyHostComponent.Type) {
|
||||
|
||||
}
|
||||
public func unmount(target _: Any, with _: AnyHostComponent.Type) {}
|
||||
}
|
||||
|
|
|
@ -13,27 +13,27 @@ import Gluon
|
|||
public final class TestView {
|
||||
/// Subviews of this test view.
|
||||
public private(set) var subviews = [TestView]()
|
||||
|
||||
|
||||
/// Props assigned to this test view.
|
||||
public internal(set) var props: AnyEquatable
|
||||
|
||||
|
||||
/** Initialize a new test view.
|
||||
- parameter props: base component props to initialize the test view
|
||||
*/
|
||||
- parameter props: base component props to initialize the test view
|
||||
*/
|
||||
init(props: AnyEquatable) {
|
||||
self.props = props
|
||||
}
|
||||
|
||||
|
||||
/** Add a subview to this test view.
|
||||
- parameter subview: the subview to be added to this view.
|
||||
*/
|
||||
- parameter subview: the subview to be added to this view.
|
||||
*/
|
||||
func add(subview: TestView) {
|
||||
subviews.append(subview)
|
||||
}
|
||||
|
||||
|
||||
/** Remove a subview from this test view.
|
||||
- parameter subview: the subview to be removed from this view.
|
||||
*/
|
||||
- parameter subview: the subview to be removed from this view.
|
||||
*/
|
||||
func remove(subview: TestView) {
|
||||
subviews.removeAll { $0 === subview }
|
||||
}
|
||||
|
|
|
@ -27,8 +27,7 @@ public struct Button: HostComponent {
|
|||
public typealias Children = String
|
||||
}
|
||||
|
||||
extension UIButton: Default {
|
||||
}
|
||||
extension UIButton: Default {}
|
||||
|
||||
extension Button: UIKitControlComponent {
|
||||
public static func update(_ view: UIButton,
|
||||
|
|
|
@ -13,11 +13,10 @@ public struct Label: HostComponent {
|
|||
public typealias Children = String
|
||||
}
|
||||
|
||||
extension UILabel: Default {
|
||||
}
|
||||
extension UILabel: Default {}
|
||||
|
||||
extension Label: UIKitViewComponent {
|
||||
public static func update(_ view: UILabel, _ props: Null, _ children: String) {
|
||||
public static func update(_ view: UILabel, _: Null, _ children: String) {
|
||||
view.text = children
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,7 @@ public struct StackView: HostComponent {
|
|||
public typealias Children = [Node]
|
||||
}
|
||||
|
||||
extension UIStackView: Default {
|
||||
}
|
||||
extension UIStackView: Default {}
|
||||
|
||||
extension StackViewProps.Axis {
|
||||
var value: NSLayoutConstraint.Axis {
|
||||
|
@ -71,7 +70,7 @@ extension StackViewProps.Distribution {
|
|||
extension StackView: UIKitViewComponent {
|
||||
public static func update(_ view: UIStackView,
|
||||
_ props: StackViewProps,
|
||||
_ children: [Node]) {
|
||||
_: [Node]) {
|
||||
view.axis = props.axis.value
|
||||
view.distribution = props.distribution.value
|
||||
view.frame = props.frame
|
||||
|
|
|
@ -9,7 +9,7 @@ import Gluon
|
|||
import UIKit
|
||||
|
||||
public protocol UIKitControlComponent: UIKitHostComponent, HostComponent
|
||||
where Props: EventHandlerProps {
|
||||
where Props: EventHandlerProps {
|
||||
associatedtype Target: UIControl & Default
|
||||
|
||||
static func update(_ view: Target, _ props: Props, _ children: Children)
|
||||
|
@ -18,7 +18,7 @@ where Props: EventHandlerProps {
|
|||
extension UIKitControlComponent {
|
||||
public static func bind(handlers: [Event: Handler<()>],
|
||||
for target: ControlWrapper<Target>)
|
||||
-> ControlWrapper<Target> {
|
||||
-> ControlWrapper<Target> {
|
||||
var target = target
|
||||
|
||||
for (e, h) in handlers {
|
||||
|
|
|
@ -24,6 +24,7 @@ extension UIKitHostComponent {
|
|||
static func targetAssertionFailure(_ function: String = #function) {
|
||||
typeAssertionFailure("target", function)
|
||||
}
|
||||
|
||||
static func childrenAssertionFailure(_ function: String = #function) {
|
||||
typeAssertionFailure("children", function)
|
||||
}
|
||||
|
@ -57,9 +58,9 @@ public class UIKitRenderer: Renderer {
|
|||
}
|
||||
|
||||
public func mountTarget(to parent: Any,
|
||||
with component: AnyHostComponent.Type,
|
||||
props: AnyEquatable,
|
||||
children: AnyEquatable) -> Any? {
|
||||
with component: AnyHostComponent.Type,
|
||||
props: AnyEquatable,
|
||||
children: AnyEquatable) -> Any? {
|
||||
guard let rendererComponent = component as? UIKitHostComponent.Type else {
|
||||
typeAssertionFailure(for: component)
|
||||
return nil
|
||||
|
@ -71,9 +72,9 @@ public class UIKitRenderer: Renderer {
|
|||
}
|
||||
|
||||
public func update(target: Any,
|
||||
with component: AnyHostComponent.Type,
|
||||
props: AnyEquatable,
|
||||
children: AnyEquatable) {
|
||||
with component: AnyHostComponent.Type,
|
||||
props: AnyEquatable,
|
||||
children: AnyEquatable) {
|
||||
guard let rendererComponent = component as? UIKitHostComponent.Type else {
|
||||
typeAssertionFailure(for: component)
|
||||
return
|
||||
|
@ -93,4 +94,3 @@ public class UIKitRenderer: Renderer {
|
|||
rendererComponent.unmount(target: target)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import XCTest
|
||||
import GluonTestRenderer
|
||||
import XCTest
|
||||
|
||||
@testable import Gluon
|
||||
|
||||
final class GluonTests: XCTestCase {
|
||||
func testExample() {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct
|
||||
// results.
|
||||
func testExample() {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct
|
||||
// results.
|
||||
// XCTAssertEqual(Gluon().text, "Hello, World!")
|
||||
}
|
||||
}
|
||||
|
||||
static var allTests = [
|
||||
("testExample", testExample),
|
||||
]
|
||||
static var allTests = [
|
||||
("testExample", testExample),
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import XCTest
|
||||
|
||||
#if os(Linux)
|
||||
public func allTests() -> [XCTestCaseEntry] {
|
||||
public func allTests() -> [XCTestCaseEntry] {
|
||||
return [
|
||||
testCase(GluonTests.allTests),
|
||||
testCase(GluonTests.allTests),
|
||||
]
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -4,4 +4,4 @@ import GluonTests
|
|||
|
||||
var tests = [XCTestCaseEntry]()
|
||||
tests += GluonTests.allTests()
|
||||
XCTMain(tests)
|
||||
XCTMain(tests)
|
||||
|
|
Loading…
Reference in New Issue