Skip to content

Commit f1f9985

Browse files
authored
Merge pull request #152 from liveviewnative/registry-defaults
Add defaults to `CustomRegistry` associated types
2 parents 4a0e032 + 25c3b7d commit f1f9985

File tree

6 files changed

+9
-45
lines changed

6 files changed

+9
-45
lines changed

Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public class LiveViewCoordinator<R: CustomRegistry>: ObservableObject {
133133
if let channel {
134134
guard !channel.isJoined, !channel.isJoining else { return }
135135
}
136+
internalState = .startingConnection
136137
do {
137138
try await connectLiveView()
138139
} catch {

Sources/LiveViewNative/CustomRegistry.swift

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,8 @@ public protocol CustomRegistry {
4848
/// }
4949
/// ```
5050
///
51-
/// If your registry does not support any custom tags, you can set this type alias to the ``EmptyRegistry/None`` type:
52-
/// ```swift
53-
/// struct MyRegistry: CustomRegistry {
54-
/// typealias TagName = EmptyRegistry.None
55-
/// }
56-
/// ```
57-
associatedtype TagName: RawRepresentable where TagName.RawValue == String
51+
/// This will default to the ``EmptyRegistry/None`` type if you don't support any custom tags.
52+
associatedtype TagName: RawRepresentable = EmptyRegistry.None where TagName.RawValue == String
5853
/// A type represnting the custom modifier types that this registry can handle.
5954
///
6055
/// This type must be `RawRepresentable` and its raw values must be strings.
@@ -69,21 +64,16 @@ public protocol CustomRegistry {
6964
/// }
7065
/// ```
7166
///
72-
/// If your registry does not support any custom modifiers, you can set this type alias to the ``EmptyRegistry/None`` type:
73-
/// ```swift
74-
/// struct MyRegistry: CustomRegistry {
75-
/// typealias ModifierType = EmptyRegistry.None
76-
/// }
77-
/// ```
78-
associatedtype ModifierType: RawRepresentable where ModifierType.RawValue == String
67+
/// This will default to the ``EmptyRegistry/None`` type if you don't support any custom modifiers.
68+
associatedtype ModifierType: RawRepresentable = EmptyRegistry.None where ModifierType.RawValue == String
7969
/// The type of view this registry returns from the `lookup` method.
8070
///
8171
/// Generally, implementors will use an opaque return type on their ``lookup(_:element:context:)-895au`` implementations and this will be inferred automatically.
82-
associatedtype CustomView: View
72+
associatedtype CustomView: View = Never
8373
/// The type of view this registry produces for loading views.
8474
///
8575
/// Generally, implementors will use an opaque return type on their ``loadingView(for:state:)-2uoy9`` implementations and this will be inferred automatically.
86-
associatedtype LoadingView: View
76+
associatedtype LoadingView: View = Never
8777

8878
/// This method is called by LiveView Native when it needs to construct a custom view.
8979
///

Sources/LiveViewNative/LiveViewNative.docc/Resources/04-01-03-modifier.swift

Lines changed: 0 additions & 16 deletions
This file was deleted.

Sources/LiveViewNative/LiveViewNative.docc/Resources/04-01-04-view.swift renamed to Sources/LiveViewNative/LiveViewNative.docc/Resources/04-01-03-view.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ struct MyRegistry: CustomRegistry {
55
enum TagName: String {
66
case catRating = "cat-rating"
77
}
8-
typealias ModifierType = EmptyRegistry.None
98

109
static func lookup(_ name: TagName, element: ElementNode, context: LiveContext<MyRegistry>) -> some View {
1110
switch name {

Sources/LiveViewNative/LiveViewNative.docc/Tutorials/04 Custom Element.tutorial

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@
3838
@Code(name: "MyRegistry.swift", file: 04-01-02-tag.swift)
3939
}
4040

41-
@Step {
42-
Then, define a type alias called `ModifierType` that is `EmptyRegistry.None`. This tells the framework that your registry doesn't support any custom modifiers.
43-
44-
@Comment {
45-
project = "app"
46-
path = "LVNTutorialApp/MyRegistry.swift"
47-
}
48-
@Code(name: "MyRegistry.swift", file: 04-01-03-modifier.swift)
49-
}
50-
5141
@Step {
5242
In the `lookup` method, we'll construct a `CatRatingView`, passing in the `context` parameter of the lookup method. This will cause a compiler error, but don't worry; in Section 3, we'll implement the view and resolve it.
5343

@@ -57,7 +47,7 @@
5747
project = "app"
5848
path = "LVNTutorialApp/MyRegistry.swift"
5949
}
60-
@Code(name: "MyRegistry.swift", file: 04-01-04-view.swift)
50+
@Code(name: "MyRegistry.swift", file: 04-01-03-view.swift)
6151
}
6252

6353
@Step {
@@ -78,7 +68,7 @@
7868
project = "app"
7969
path = "LVNTutorialApp/ContentView.swift"
8070
}
81-
@Code(name: "ContentView.swift", file: 04-01-05-coordinator.swift)
71+
@Code(name: "ContentView.swift", file: 04-01-04-coordinator.swift)
8272
}
8373
}
8474
}

0 commit comments

Comments
 (0)