Skip to content

Commit d0133ce

Browse files
committed
replace binding with class
1 parent a553fb6 commit d0133ce

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

Coder-Desktop/Coder-Desktop/Views/FileSync/FilePicker.swift

+6-9
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class FilePickerModel: ObservableObject {
9292
do throws(ClientError) {
9393
rootFiles = try await client
9494
.listAgentDirectory(.init(path: [], relativity: .root))
95-
.toModels(client: Binding(get: { self.client }, set: { _ in }), path: [])
95+
.toModels(client: client, path: [])
9696
} catch {
9797
self.error = error
9898
}
@@ -173,10 +173,7 @@ class FilePickerItemModel: Identifiable, ObservableObject {
173173
let absolute_path: String
174174
let dir: Bool
175175

176-
// This being a binding is pretty important performance-wise, as it's a struct
177-
// that would otherwise be recreated every time the the item row is rendered.
178-
// Removing the binding results in very noticeable lag when scrolling a file tree.
179-
@Binding var client: AgentClient
176+
let client: AgentClient
180177

181178
@Published var contents: [FilePickerItemModel]?
182179
@Published var isLoading = false
@@ -197,14 +194,14 @@ class FilePickerItemModel: Identifiable, ObservableObject {
197194

198195
init(
199196
name: String,
200-
client: Binding<AgentClient>,
197+
client: AgentClient,
201198
absolute_path: String,
202199
path: [String],
203200
dir: Bool = false,
204201
contents: [FilePickerItemModel]? = nil
205202
) {
206203
self.name = name
207-
_client = client
204+
self.client = client
208205
self.path = path
209206
self.dir = dir
210207
self.absolute_path = absolute_path
@@ -227,7 +224,7 @@ class FilePickerItemModel: Identifiable, ObservableObject {
227224
do throws(ClientError) {
228225
contents = try await client
229226
.listAgentDirectory(.init(path: path, relativity: .root))
230-
.toModels(client: $client, path: path)
227+
.toModels(client: client, path: path)
231228
} catch {
232229
self.error = error
233230
}
@@ -237,7 +234,7 @@ class FilePickerItemModel: Identifiable, ObservableObject {
237234

238235
extension LSResponse {
239236
@MainActor
240-
func toModels(client: Binding<AgentClient>, path: [String]) -> [FilePickerItemModel] {
237+
func toModels(client: AgentClient, path: [String]) -> [FilePickerItemModel] {
241238
contents.compactMap { file in
242239
// Filter dotfiles from the picker
243240
guard !file.name.hasPrefix(".") else { return nil }

Coder-Desktop/CoderSDK/AgentClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public struct AgentClient: Sendable {
1+
public final class AgentClient: Sendable {
22
let client: Client
33

44
public init(agentHost: String) {

0 commit comments

Comments
 (0)