Improve docs, refine README

This commit is contained in:
Max Desiatov 2019-01-20 20:27:03 +00:00
parent 4000fbd155
commit 13e90cc79e
No known key found for this signature in database
GPG Key ID: FE08EBF9CF58CBA2
4 changed files with 37 additions and 5 deletions

View File

@ -1,7 +1,6 @@
disabled_rules:
- trailing_comma
- identifier_name
- private_over_fileprivate
- void_return
- operator_whitespace
- nesting

View File

@ -79,6 +79,9 @@ An example of a Gluon component that binds a button to a label, embedded
within an existing UIKit app, looks like this:
```swift
import Gluon
import GluonUIKit
struct Counter: LeafComponent {
struct Props: Equatable {
let countFrom: Int

View File

@ -5,6 +5,17 @@
// Created by Max Desiatov on 06/11/2018.
//
/** Type-erased version of `Equatable` that allows you to compare values of
different types. Main use of `AnyEquatable` in Gluon is to wrap `Props` and
`Children` before storing those in `AnyNode`.
Example:
```swift
AnyEquatable(42) == AnyEquatable(42) // is `true`
AnyEquatable(42) == AnyEquatable("forty two") // is `false`
```
*/
public struct AnyEquatable: Equatable {
public let value: Any
private let equals: (Any) -> Bool

View File

@ -18,10 +18,29 @@ extension UniqueReference: Equatable {
}
}
/// `Unique` works around the fact that `ObjectIdentifier` can't take
/// closures as arguments despite closures being reference types and having
/// identity. `Unique` implements `Equatable`, but will return `false` on
/// equality comparison of different identities (including closures).
/** `Unique` works around the fact that `ObjectIdentifier` can't take
closures as arguments despite closures being reference types and having
identity. You can pass any value or reference to `Unique.init`, which will
create a new identity. `Unique` implements `Equatable`, but will return
`false` on equality comparison of different identities (including closures)
Example:
```swift
let x = Unique(5)
let y = Unique(5)
let z = x
x == y // is `false`
x == z // is `true`
let closure1 = Unique { 5 }
let closure2 = Unique { 5 }
let closure3 = closure1
closure1 == closure2 // is `false`
closure3 == closure1 // is `true`
```
*/
public struct Unique<T> {
private let id = UniqueReference()