From 7c3e78b2ee219a52acbb8535913c2598afebc668 Mon Sep 17 00:00:00 2001 From: sergdort Date: Sat, 12 Jun 2021 22:05:05 +0100 Subject: [PATCH] Rename Context and Widget --- CombineFeedback.xcodeproj/project.pbxproj | 16 ++++++++-------- Example/CounterExample/Counter.swift | 8 ++++---- Example/MoviesExample/Movies.swift | 8 ++++---- Example/SignIn/SignIn.swift | 8 ++++---- .../SingleStoreExampleView.swift | 6 +++--- Example/TrafficLight/TrafficLightView.swift | 8 ++++---- Example/Views/ContextExtensions.swift | 6 +++--- .../{Context.swift => ViewContext.swift} | 6 +++++- .../{Widget.swift => WithViewContext.swift} | 5 ++++- 9 files changed, 39 insertions(+), 32 deletions(-) rename Sources/CombineFeedbackUI/{Context.swift => ViewContext.swift} (94%) rename Sources/CombineFeedbackUI/{Widget.swift => WithViewContext.swift} (67%) diff --git a/CombineFeedback.xcodeproj/project.pbxproj b/CombineFeedback.xcodeproj/project.pbxproj index c1a6cdf..d356e84 100644 --- a/CombineFeedback.xcodeproj/project.pbxproj +++ b/CombineFeedback.xcodeproj/project.pbxproj @@ -11,14 +11,14 @@ 2510CDE1242BED63004A6422 /* ContextExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2510CDE0242BED63004A6422 /* ContextExtensions.swift */; }; 251445E724086A400062EE04 /* TrafficLightView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 251445E624086A400062EE04 /* TrafficLightView.swift */; }; 252BF08422BAE05700BC4265 /* SignIn.swift in Sources */ = {isa = PBXBuildFile; fileRef = 252BF08322BAE05700BC4265 /* SignIn.swift */; }; - 253D324122B185FA002F3B7F /* Context.swift in Sources */ = {isa = PBXBuildFile; fileRef = 253D323F22B1858C002F3B7F /* Context.swift */; }; + 253D324122B185FA002F3B7F /* ViewContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 253D323F22B1858C002F3B7F /* ViewContext.swift */; }; 25C57B2C22BC2C33007CB4D6 /* Activity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25C57B2B22BC2C33007CB4D6 /* Activity.swift */; }; 25EBC08C23FD61B100719826 /* Reducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 585CD878239AC7D3004BE9CC /* Reducer.swift */; }; 25F23C2922CA984E00894863 /* TrafficLight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25F23C2822CA984E00894863 /* TrafficLight.swift */; }; 5800000022A9DDE5005A860B /* CombineFeedbackUI.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5800FFEA22A9DDE5005A860B /* CombineFeedbackUI.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 5800000D22A9DE8F005A860B /* CombineFeedback.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5800FF9022A89BE6005A860B /* CombineFeedback.framework */; }; 5800000E22A9DE8F005A860B /* CombineFeedback.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5800FF9022A89BE6005A860B /* CombineFeedback.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 5800001522A9DEEA005A860B /* Widget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5800001422A9DEEA005A860B /* Widget.swift */; }; + 5800001522A9DEEA005A860B /* WithViewContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5800001422A9DEEA005A860B /* WithViewContext.swift */; }; 5800FF9A22A89BE6005A860B /* CombineFeedback.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5800FF9022A89BE6005A860B /* CombineFeedback.framework */; }; 5800FF9F22A89BE6005A860B /* CombineFeedbackTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5800FF9E22A89BE6005A860B /* CombineFeedbackTests.swift */; }; 5800FFAE22A89C09005A860B /* Feedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5800FFAA22A89C08005A860B /* Feedback.swift */; }; @@ -138,10 +138,10 @@ 2510CDE0242BED63004A6422 /* ContextExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextExtensions.swift; sourceTree = ""; }; 251445E624086A400062EE04 /* TrafficLightView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrafficLightView.swift; sourceTree = ""; }; 252BF08322BAE05700BC4265 /* SignIn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignIn.swift; sourceTree = ""; }; - 253D323F22B1858C002F3B7F /* Context.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Context.swift; sourceTree = ""; }; + 253D323F22B1858C002F3B7F /* ViewContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewContext.swift; sourceTree = ""; }; 25C57B2B22BC2C33007CB4D6 /* Activity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Activity.swift; sourceTree = ""; }; 25F23C2822CA984E00894863 /* TrafficLight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrafficLight.swift; sourceTree = ""; }; - 5800001422A9DEEA005A860B /* Widget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Widget.swift; sourceTree = ""; }; + 5800001422A9DEEA005A860B /* WithViewContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WithViewContext.swift; sourceTree = ""; }; 5800FF9022A89BE6005A860B /* CombineFeedback.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CombineFeedback.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 5800FF9422A89BE6005A860B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 5800FF9922A89BE6005A860B /* CombineFeedbackTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CombineFeedbackTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -360,9 +360,9 @@ children = ( 5800FFEC22A9DDE5005A860B /* CombineFeedbackUI.h */, 5800FFED22A9DDE5005A860B /* Info.plist */, - 253D323F22B1858C002F3B7F /* Context.swift */, + 253D323F22B1858C002F3B7F /* ViewContext.swift */, 583971C422ADFA1F00139CC0 /* Store.swift */, - 5800001422A9DEEA005A860B /* Widget.swift */, + 5800001422A9DEEA005A860B /* WithViewContext.swift */, ); path = CombineFeedbackUI; sourceTree = ""; @@ -783,9 +783,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 5800001522A9DEEA005A860B /* Widget.swift in Sources */, + 5800001522A9DEEA005A860B /* WithViewContext.swift in Sources */, 583971C522ADFA1F00139CC0 /* Store.swift in Sources */, - 253D324122B185FA002F3B7F /* Context.swift in Sources */, + 253D324122B185FA002F3B7F /* ViewContext.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Example/CounterExample/Counter.swift b/Example/CounterExample/Counter.swift index cf03a99..c5bf808 100644 --- a/Example/CounterExample/Counter.swift +++ b/Example/CounterExample/Counter.swift @@ -19,11 +19,11 @@ struct CounterView: View { typealias State = Counter.State typealias Event = Counter.Event - @ObservedObject - var context: Context + @StateObject + var context: ViewContext - init(context: Context) { - self.context = context + init(context: ViewContext) { + self._context = StateObject(wrappedValue: context) logInit(of: self) } diff --git a/Example/MoviesExample/Movies.swift b/Example/MoviesExample/Movies.swift index 0ead368..1f60c83 100644 --- a/Example/MoviesExample/Movies.swift +++ b/Example/MoviesExample/Movies.swift @@ -57,11 +57,11 @@ extension Movies { struct MoviesView: View { typealias State = Movies.State typealias Event = Movies.Event - @ObservedObject - var context: Context + @StateObject + var context: ViewContext - init(context: Context) { - self.context = context + init(context: ViewContext) { + self._context = StateObject(wrappedValue: context) logInit(of: self) } diff --git a/Example/SignIn/SignIn.swift b/Example/SignIn/SignIn.swift index 8b27f79..390b2c0 100644 --- a/Example/SignIn/SignIn.swift +++ b/Example/SignIn/SignIn.swift @@ -56,11 +56,11 @@ struct SignInView: View { typealias State = SignIn.State typealias Event = SignIn.Event - @ObservedObject - var context: Context + @StateObject + var context: ViewContext - init(context: Context) { - self.context = context + init(context: ViewContext) { + self._context = StateObject(wrappedValue: context) logInit(of: self) } diff --git a/Example/SingleStoreExample/SingleStoreExampleView.swift b/Example/SingleStoreExample/SingleStoreExampleView.swift index 500fbb8..27e9894 100644 --- a/Example/SingleStoreExample/SingleStoreExampleView.swift +++ b/Example/SingleStoreExample/SingleStoreExampleView.swift @@ -3,9 +3,9 @@ import CombineFeedbackUI import SwiftUI struct SingleStoreExampleView: View { - let context: Context - - init(context: Context) { + let context: ViewContext + + init(context: ViewContext) { self.context = context logInit(of: self) } diff --git a/Example/TrafficLight/TrafficLightView.swift b/Example/TrafficLight/TrafficLightView.swift index ac7e54b..57fb7ee 100644 --- a/Example/TrafficLight/TrafficLightView.swift +++ b/Example/TrafficLight/TrafficLightView.swift @@ -2,11 +2,11 @@ import SwiftUI import CombineFeedbackUI struct TrafficLightView: View { - @ObservedObject - var context: Context + @StateObject + var context: ViewContext - init(context: Context) { - self.context = context + init(context: ViewContext) { + self._context = StateObject(wrappedValue: context) logInit(of: self) } diff --git a/Example/Views/ContextExtensions.swift b/Example/Views/ContextExtensions.swift index 52a25d4..ecc8be7 100644 --- a/Example/Views/ContextExtensions.swift +++ b/Example/Views/ContextExtensions.swift @@ -1,8 +1,8 @@ import CombineFeedbackUI -extension Context { - static func empty(_ state: State) -> Context { - Context(state: state, send: { _ in }, mutate: { _ in }) +extension ViewContext { + static func empty(_ state: State) -> ViewContext { + ViewContext(state: state, send: { _ in }, mutate: { _ in }) } } diff --git a/Sources/CombineFeedbackUI/Context.swift b/Sources/CombineFeedbackUI/ViewContext.swift similarity index 94% rename from Sources/CombineFeedbackUI/Context.swift rename to Sources/CombineFeedbackUI/ViewContext.swift index d9ead62..0a7a3e6 100644 --- a/Sources/CombineFeedbackUI/Context.swift +++ b/Sources/CombineFeedbackUI/ViewContext.swift @@ -1,8 +1,12 @@ import SwiftUI import Combine + +@available(*, deprecated, renamed:"ViewContext") +public typealias Context = ViewContext + @dynamicMemberLookup -public final class Context: ObservableObject { +public final class ViewContext: ObservableObject { @Published private var state: State private var bag = Set() diff --git a/Sources/CombineFeedbackUI/Widget.swift b/Sources/CombineFeedbackUI/WithViewContext.swift similarity index 67% rename from Sources/CombineFeedbackUI/Widget.swift rename to Sources/CombineFeedbackUI/WithViewContext.swift index f747ff3..4f58ce7 100644 --- a/Sources/CombineFeedbackUI/Widget.swift +++ b/Sources/CombineFeedbackUI/WithViewContext.swift @@ -2,7 +2,10 @@ import Combine import CombineFeedback import SwiftUI -public struct Widget: View { +@available(*, deprecated, renamed:"WithViewContext") +public typealias Widget = WithViewContext + +public struct WithViewContext: View { private let store: Store private let content: (Context) -> Content