thebaselab / codeapp

Building a full-fledged code editor for iPad
https://code.thebaselab.com
MIT License
2.95k stars 202 forks source link

Refactor source control code #893

Closed bummoblizard closed 1 year ago

bummoblizard commented 1 year ago

Plan:

  1. Migrate to using async/await pattern as opposed to completion handlers in LocalGitServiceProvider
  2. Design better abstraction and implement local Git features as an extension

This allows us to:

bummoblizard commented 1 year ago

Extension API ideas:

While implementing these new features, explore the possibility of using generics in our APIs:

bummoblizard commented 1 year ago

Example of using generics to abstract the common operations of extension contribution points (ToolBar, StatusBar etc.): https://github.com/thebaselab/codeapp/blob/main/CodeApp/Managers/ExtensionViewItemManager.swift

protocol CodeAppContributionPointManager: ObservableObject {
    associatedtype Item where Item: Identifiable, Item.ID == UUID
    var items: [Item] { get set }
    func registerItem(item: Item)
    func deregisterItem(id: UUID)
}

extension CodeAppContributionPointManager {
    func registerItem(item: Item) {
        items.append(item)
    }
    func deregisterItem(id: UUID) {
        items.removeAll(where: { $0.id == id })
    }
}

class StatusBarManager: CodeAppContributionPointManager {
    @Published var items: [StatusBarItem] = []
}

class ToolbarManager: CodeAppContributionPointManager {
    @Published var items: [ToolbarItem] = []
}

// .. etc