Skip to content

Commit c15861e

Browse files
committed
Cleanup.
1 parent 788a7d7 commit c15861e

File tree

13 files changed

+77
-56
lines changed

13 files changed

+77
-56
lines changed
-729 Bytes
Loading
-1.26 KB
Loading

Examples/DiffableTextAppXUIKit/App/Views/Example.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct Example<Style: DiffableTextStyle>: View {
6262
}
6363

6464
var diffableTextField: some View {
65-
DiffableTextField("Much wow. Very empty.", value: value, style: style)
65+
DiffableTextField("Much wow. Such empty.", value: value, style: style)
6666
.focused($focus).padding()
6767
.background(Color(uiColor: .tertiarySystemBackground).ignoresSafeArea(.container, edges: []))
6868
}

Examples/DiffableTextAppXUIKit/Modules/IntervalSliders/Sources/IntervalSliders/Models/Context.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import SwiftUI
1313
// MARK: Declaration
1414
//*============================================================================*
1515

16-
@dynamicMemberLookup @usableFromInline final class Context {
16+
@usableFromInline @dynamicMemberLookup final class Context {
1717

1818
//=------------------------------------------------------------------------=
1919
// MARK: State

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ struct DiffableTextFieldXPhone: View {
195195
}
196196
```
197197

198-
## [WrapperTextStyle(s)](Notes/WrapperTextStyle.md) ([Source](Sources/DiffableTextStylesXWrapper/), [Tests](Tests/DiffableTextStylesXWrapperTests))
198+
## [WrapperTextStyle(s)](Notes/WrapperTextStyle.md) ([Source](Sources/DiffableTextStylesXWrappers/), [Tests](Tests/DiffableTextStylesXWrappersTests))
199199

200200
Decorative styles that modify the behavior of their content.
201201

Sources/DiffableTextKit/Helpers/Field.swift renamed to Sources/DiffableTextKit/Helpers/Layout.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/// - Autocorrects selection when the snapshot changes.
1717
/// - Autocorrects selection when the selection changes.
1818
///
19-
@usableFromInline struct Field {
19+
@usableFromInline struct Layout {
2020

2121
//=------------------------------------------------------------------------=
2222
// MARK: State
@@ -50,7 +50,7 @@
5050
// MARK: Transformations
5151
//=----------------------------------------------------------------------------=
5252

53-
extension Field {
53+
extension Layout {
5454

5555
//=------------------------------------------------------------------------=
5656
// MARK: Snapshot

Sources/DiffableTextKit/Models/Context.swift

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
///
1818
public struct Context<Style: DiffableTextStyle> {
1919
public typealias Value = Style.Value
20-
public typealias State = DiffableTextKit.Remote<Style>
20+
public typealias Status = DiffableTextKit.Status<Style>
2121
public typealias Commit = DiffableTextKit.Commit<Value>
2222

2323
//=------------------------------------------------------------------------=
@@ -30,14 +30,14 @@ public struct Context<Style: DiffableTextStyle> {
3030
// MARK: Initializers
3131
//=------------------------------------------------------------------------=
3232

33-
@inlinable init(_ state: State, _ field: Field) {
34-
self._storage = Storage(state, field)
33+
@inlinable init(_ status: Status, _ layout: Layout) {
34+
self._storage = Storage(status, layout)
3535
}
3636

37-
@inlinable public init(_ state: State) {
38-
switch state.focus.wrapped {
39-
case true: self = .focused(state.style, state.value)
40-
case false: self = .unfocused(state.style, state.value)
37+
@inlinable public init(_ status: Status) {
38+
switch status.focus.wrapped {
39+
case true: self = .focused(status.style, status.value)
40+
case false: self = .unfocused(status.style, status.value)
4141
}
4242
}
4343

@@ -50,11 +50,11 @@ public struct Context<Style: DiffableTextStyle> {
5050
}
5151

5252
@inlinable static func focused(_ style: Style, _ commit: Commit) -> Self {
53-
Self(State(style, commit.value, true), Field((commit.snapshot)))
53+
Self(Status(style, commit.value, true), Layout((commit.snapshot)))
5454
}
5555

5656
@inlinable static func unfocused(_ style: Style, _ value: Value) -> Self {
57-
Self(State(style, value, false), Field(Snapshot(style.format(value), as: .phantom)))
57+
Self(Status(style, value, false), Layout(Snapshot(style.format(value), as: .phantom)))
5858
}
5959

6060
//=------------------------------------------------------------------------=
@@ -85,24 +85,24 @@ public struct Context<Style: DiffableTextStyle> {
8585
// MARK: State
8686
//=--------------------------------------------------------------------=
8787

88-
@usableFromInline var state: State
89-
@usableFromInline var field: Field
88+
@usableFromInline var status: Status
89+
@usableFromInline var layout: Layout
9090

9191
//=--------------------------------------------------------------------=
9292
// MARK: Initializers
9393
//=--------------------------------------------------------------------=
9494

95-
@inlinable init(_ state: State, _ field: Field) {
96-
self.state = state
97-
self.field = field
95+
@inlinable init(_ status: Status, _ layout: Layout) {
96+
self.status = status
97+
self.layout = layout
9898
}
9999

100100
//=--------------------------------------------------------------------=
101101
// MARK: Utilities
102102
//=--------------------------------------------------------------------=
103103

104104
@inlinable func copy() -> Self {
105-
Self(state, field)
105+
Self(status, layout)
106106
}
107107
}
108108
}
@@ -117,45 +117,45 @@ public extension Context {
117117
// MARK: 1st
118118
//=------------------------------------------------------------------------=
119119

120-
@inlinable internal var state: State {
121-
_storage.state
120+
@inlinable internal var status: Status {
121+
_storage.status
122122
}
123123

124-
@inlinable internal var field: Field {
125-
_storage.field
124+
@inlinable internal var layout: Layout {
125+
_storage.layout
126126
}
127127

128128
//=------------------------------------------------------------------------=
129129
// MARK: 2nd
130130
//=------------------------------------------------------------------------=
131131

132132
@inlinable var style: Style {
133-
state.style
133+
status.style
134134
}
135135

136136
@inlinable var value: Value {
137-
state.value
137+
status.value
138138
}
139139

140140
@inlinable var focus: Focus {
141-
state.focus
141+
status.focus
142142
}
143143

144144
//=------------------------------------------------------------------------=
145145
// MARK: 3rd
146146
//=------------------------------------------------------------------------=
147147

148148
@inlinable var snapshot: Snapshot {
149-
field.snapshot
149+
layout.snapshot
150150
}
151151

152152
@inlinable var text: String {
153-
field.snapshot.characters
153+
layout.snapshot.characters
154154
}
155155

156156
@inlinable func selection<T>(as type: Position<T>.Type =
157157
Position<T>.self) -> Range<T.Position> where T: Offset {
158-
field.positions(at: field.selection).bounds
158+
layout.positions(at: layout.selection).bounds
159159
}
160160
}
161161

@@ -175,8 +175,8 @@ public extension Context {
175175
//=--------------------------------------=
176176
if other.focus.wrapped {
177177
self.write {
178-
$0.state = other.state
179-
$0.field.update(snapshot: other.snapshot)
178+
$0.status = other.status
179+
$0.layout.update(snapshot: other.snapshot)
180180
}
181181
//=--------------------------------------=
182182
// Unfocused
@@ -185,22 +185,20 @@ public extension Context {
185185
}
186186

187187
//=------------------------------------------------------------------------=
188-
// MARK: Remote
188+
// MARK: Status
189189
//=------------------------------------------------------------------------=
190190

191-
@inlinable mutating func merge(_ remote: State) -> Bool {
191+
@inlinable mutating func merge(_ status: Status) -> Bool {
192192
//=--------------------------------------=
193193
// Update
194194
//=--------------------------------------=
195-
let (result, update) = self.state + remote
195+
let (result, update) = self.status + status
196196
//=--------------------------------------=
197-
// At Least On Value Must Be Unique
197+
// At Least One Must Be Different
198198
//=--------------------------------------=
199-
guard !update.isEmpty else { return false }
200-
//=--------------------------------------=
201-
// Insert
202-
//=--------------------------------------=
203-
self.merge(Self(result)); return true
199+
return (!update.isEmpty).on(true) {
200+
self.merge(Self.init(result))
201+
}
204202
}
205203

206204
//=------------------------------------------------------------------------=
@@ -212,7 +210,7 @@ public extension Context {
212210
//=--------------------------------------=
213211
// Values
214212
//=--------------------------------------=
215-
let carets = field.indices(at: Carets(range))
213+
let carets = layout.indices(at: Carets(range))
216214
let commit = try style.merge(Proposal(
217215
snapshot, with: characters, in: carets.bounds))
218216
//=--------------------------------------=
@@ -227,10 +225,10 @@ public extension Context {
227225
//=------------------------------------------------------------------------=
228226

229227
@inlinable internal mutating func set(selection: Index) {
230-
self.write({ $0.field.selection = Carets(selection) })
228+
self.write({ $0.layout.selection = Carets(selection) })
231229
}
232230

233231
@inlinable mutating func update<T>(selection: Range<T.Position>, momentum: Bool) where T: Offset {
234-
self.write({ $0.field .update(selection: Carets(selection), momentum: momentum) })
232+
self.write({ $0.layout .update(selection: Carets(selection), momentum: momentum) })
235233
}
236234
}

Sources/DiffableTextKit/Models/Remote.swift renamed to Sources/DiffableTextKit/Models/Status.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//*===========================================================================
1313

1414
/// A model used to collect upstream and downstream values.
15-
public struct Remote<Style: DiffableTextStyle> {
15+
public struct Status<Style: DiffableTextStyle> {
1616
public typealias Value = Style.Value
1717

1818
//=------------------------------------------------------------------------=
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//=----------------------------------------------------------------------------=
2+
// This source file is part of the DiffableTextViews open source project.
3+
//
4+
// Copyright (c) 2022 Oscar Byström Ericsson
5+
// Licensed under Apache License, Version 2.0
6+
//
7+
// See http://www.apache.org/licenses/LICENSE-2.0 for license information.
8+
//=----------------------------------------------------------------------------=
9+
10+
//*============================================================================*
11+
// MARK: Extension
12+
//*============================================================================*
13+
14+
public extension Bool {
15+
16+
//=------------------------------------------------------------------------=
17+
// MARK: Utilities
18+
//=------------------------------------------------------------------------=
19+
20+
@inlinable @discardableResult func on(_ value: Bool,
21+
perform action: () throws -> Void) rethrows -> Bool {
22+
if value { try action() }; return self
23+
}
24+
}

Sources/DiffableTextViewsXUIKit/DiffableTextField.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import SwiftUI
3535
///
3636
public struct DiffableTextField<Style: DiffableTextStyle>: UIViewRepresentable {
3737
public typealias Value = Style.Value
38-
38+
3939
//=------------------------------------------------------------------------=
4040
// MARK: State
4141
//=------------------------------------------------------------------------=
@@ -69,7 +69,7 @@ public struct DiffableTextField<Style: DiffableTextStyle>: UIViewRepresentable {
6969
@inlinable @inline(__always) func locale(_ locale: Locale) -> Self {
7070
Self(title, value: value, style: style.locale(locale))
7171
}
72-
72+
7373
//=------------------------------------------------------------------------=
7474
// MARK: View Life Cycle
7575
//=------------------------------------------------------------------------=
@@ -86,7 +86,7 @@ public struct DiffableTextField<Style: DiffableTextStyle>: UIViewRepresentable {
8686
@inlinable public func updateUIView(_ view: UITextField, context: Self.Context) {
8787
context.coordinator.update(self, context.environment)
8888
}
89-
89+
9090
//*========================================================================*
9191
// MARK: Coordinator
9292
//*========================================================================*
@@ -95,7 +95,7 @@ public struct DiffableTextField<Style: DiffableTextStyle>: UIViewRepresentable {
9595
@usableFromInline typealias Upstream = DiffableTextField
9696
@usableFromInline typealias Environment = EnvironmentValues
9797
@usableFromInline typealias Position = Unicode.UTF16.Position
98-
@usableFromInline typealias Remote = DiffableTextKit.Remote<Style>
98+
@usableFromInline typealias Status = DiffableTextKit.Status<Style>
9999
@usableFromInline typealias Context = DiffableTextKit.Context<Style>
100100

101101
//=--------------------------------------------------------------------=
@@ -150,7 +150,7 @@ public struct DiffableTextField<Style: DiffableTextStyle>: UIViewRepresentable {
150150
self.downstream.setTextContentType(environment)
151151
self.downstream.setTextInputAutocapitalization(environment)
152152
//=----------------------------------=
153-
// Miscellaneous
153+
// Coordinator
154154
//=----------------------------------=
155155
self.onSubmit = environment.diffableTextViews_onSubmit
156156
//=----------------------------------=
@@ -259,11 +259,11 @@ public struct DiffableTextField<Style: DiffableTextStyle>: UIViewRepresentable {
259259
// MARK: Synchronization
260260
//=--------------------------------------------------------------------=
261261

262-
@inlinable func pull() -> Remote {
262+
@inlinable func pull() -> Status {
263263
//=----------------------------------=
264264
// Upstream, Downstream
265265
//=----------------------------------=
266-
Remote(upstream.style, upstream.value.wrappedValue, downstream.focus)
266+
Status(upstream.style, upstream.value.wrappedValue, downstream.focus)
267267
}
268268

269269
@inlinable func push() {

0 commit comments

Comments
 (0)