Skip to content

Commit cf303fc

Browse files
committed
AppVM observable
1 parent 2f09376 commit cf303fc

11 files changed

+26
-25
lines changed

SwiftPamphletApp/AppVM.swift

+10-9
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@ import Foundation
99
import Combine
1010
import AppKit
1111

12-
final class AppVM: ObservableObject {
12+
@Observable
13+
final class AppVM {
1314

14-
@Published var alertMsg = "" // 警告信息
15-
@Published var webLinkStr = "" // 导航上的外部链接
15+
var alertMsg = "" // 警告信息
16+
var webLinkStr = "" // 导航上的外部链接
1617

1718
// 开发者动态
18-
@Published var devsNotis = [String: Int]()
19-
@Published var devsCountNotis = 0
19+
var devsNotis = [String: Int]()
20+
var devsCountNotis = 0
2021

2122
// MARK: - 库存档
22-
@Published var archiveRepos = [SPReposModel]()
23+
var archiveRepos = [SPReposModel]()
2324

2425
// MARK: - CCY
2526
// 探索更多库
26-
@Published var expNotis = [String: DBRepoStore]()
27-
@Published var expCountNotis = 0
28-
@Published var exps = [SPReposModel]()
27+
var expNotis = [String: DBRepoStore]()
28+
var expCountNotis = 0
29+
var exps = [SPReposModel]()
2930

3031
// MARK: - Combine
3132
private var cc: [AnyCancellable] = []

SwiftPamphletApp/GitHubAPI/DetailView/GuideView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SwiftUI
99
import Ink
1010

1111
struct GuideView: View {
12-
@EnvironmentObject var appVM: AppVM
12+
@Environment(AppVM.self) var appVM
1313
var number: Int
1414
var title: String
1515
var body: some View {

SwiftPamphletApp/GitHubAPI/DetailView/RepoView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct RepoView: View {
1111
enum EnterType {
1212
case normal, readme
1313
}
14-
@EnvironmentObject var appVM: AppVM
14+
@Environment(AppVM.self) var appVM
1515
@State var vm: RepoVM
1616
@State private var tabSelct = 1
1717
@State var type: EnterType = .normal

SwiftPamphletApp/GitHubAPI/DetailView/RepoWebView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import SwiftUI
99

1010
struct RepoWebView: View {
11-
@EnvironmentObject var appVM: AppVM
11+
@Environment(AppVM.self) var appVM
1212
var urlStr: String
1313
var body: some View {
1414
WebUIView(urlStr: urlStr)

SwiftPamphletApp/GitHubAPI/DetailView/UserView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import SwiftUI
99

1010
struct UserView: View {
11-
@EnvironmentObject var appVM: AppVM
11+
@Environment(AppVM.self) var appVM
1212
@State var vm: UserVM
1313
var isShowUserEventLink = true
1414
var isCleanUnread = false

SwiftPamphletApp/GitHubAPI/ListView/ActiveDeveloperListView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import SwiftUI
99

1010
struct ActiveDeveloperListView: View {
11-
@EnvironmentObject var appVM: AppVM
11+
@Environment(AppVM.self) var appVM
1212
@State var vm: IssueVM
1313
var body: some View {
1414
List {
@@ -49,7 +49,7 @@ struct ActiveDeveloperListView: View {
4949
// MARK: - 碎视图
5050

5151
struct ActiveDeveloperUnreadLinkView: View {
52-
@EnvironmentObject var appVM: AppVM
52+
@Environment(AppVM.self) var appVM
5353
var u: ADeveloperModel
5454
var body: some View {
5555
if appVM.devsNotis[u.id] ?? 0 > 0 {

SwiftPamphletApp/GitHubAPI/ListView/ExploreRepoListView.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SwiftUI
99
import CodeEditorView
1010

1111
struct ExploreRepoListView: View {
12-
@EnvironmentObject var appVM: AppVM
12+
@Environment(AppVM.self) var appVM
1313
var showAsGroup: Bool = false
1414
var isArchive = false
1515
var body: some View {
@@ -91,7 +91,7 @@ struct ExploreRepoListView: View {
9191

9292
// MARK: - 碎视图
9393
struct ExpListUnreadLinkView: View {
94-
@EnvironmentObject var appVM: AppVM
94+
@Environment(AppVM.self) var appVM
9595
var r: ARepoModel
9696
var body: some View {
9797
if appVM.expNotis[r.id]?.unRead ?? 0 > 0 {
@@ -106,7 +106,7 @@ struct ExpListUnreadLinkView: View {
106106
}
107107

108108
struct ExpListLinkView: View {
109-
@EnvironmentObject var appVM: AppVM
109+
@Environment(AppVM.self) var appVM
110110
var r: ARepoModel
111111
var rIdArr: [String] {
112112
r.id.components(separatedBy: "/")

SwiftPamphletApp/GitHubAPI/ListView/IssuesListFromCustomView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import SwiftUI
99

1010
struct IssuesListFromCustomView: View {
11-
@EnvironmentObject var appVM: AppVM
11+
@Environment(AppVM.self) var appVM
1212
@State var vm: IssueVM
1313
var body: some View {
1414
List {

SwiftPamphletApp/HomeUI/HomeView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import SwiftUI
99

1010
struct HomeView: View {
11-
@StateObject var appVM = AppVM()
11+
@State var appVM = AppVM()
1212
@State private var selectedDataLinkString: String?
1313

1414
var body: some View {
@@ -17,6 +17,6 @@ struct HomeView: View {
1717
} detail: {
1818
DataLink.viewToShow(for: selectedDataLinkString)
1919
}
20-
.environmentObject(appVM)
20+
.environment(appVM)
2121
}
2222
}

SwiftPamphletApp/SPSidebar.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SwiftUI
99

1010
// MARK: - Sidebar
1111
struct SPSidebar: View {
12-
@EnvironmentObject var appVM: AppVM
12+
@Environment(AppVM.self) var appVM
1313
var body: some View {
1414
List {
1515
Section("新动态") {

SwiftPamphletApp/SwiftPamphletAppApp.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct Demo: View {
3838

3939
struct V: View {
4040

41-
@StateObject var appVM = AppVM()
41+
@State var appVM = AppVM()
4242
@State var isEnterFullScreen: Bool = false // 全屏控制
4343
var body: some View {
4444
Button {
@@ -52,7 +52,7 @@ struct V: View {
5252

5353
struct SwiftPamphletApp: View {
5454

55-
@StateObject var appVM = AppVM()
55+
@State var appVM = AppVM()
5656
@State var networkMonitor = NetworkMonitor()
5757

5858
@State var sb = Set<AnyCancellable>()
@@ -117,7 +117,7 @@ struct SwiftPamphletApp: View {
117117

118118
} // end ToolbarItemGroup
119119
} // end .toolbar
120-
.environmentObject(appVM)
120+
.environment(appVM)
121121
// 网络监控
122122
.environment(networkMonitor)
123123
.onChange(of: networkMonitor.hasNetworkConnection, { oldValue, newValue in

0 commit comments

Comments
 (0)