Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
A139516F2FAC867A00859397 /* EffectView in Frameworks */ = {isa = PBXBuildFile; productRef = A139516E2FAC867A00859397 /* EffectView */; };
A1C326A62FD21F7C00393BD8 /* EffectComponents in Frameworks */ = {isa = PBXBuildFile; productRef = A1C326A52FD21F7C00393BD8 /* EffectComponents */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -46,7 +46,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
A139516F2FAC867A00859397 /* EffectView in Frameworks */,
A1C326A62FD21F7C00393BD8 /* EffectComponents in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -113,7 +113,7 @@
);
name = EffectViewExample;
packageProductDependencies = (
A139516E2FAC867A00859397 /* EffectView */,
A1C326A52FD21F7C00393BD8 /* EffectComponents */,
);
productName = SimpleEffectView;
productReference = A13E260F2FA6014E00C324E5 /* EffectViewExample.app */;
Expand Down Expand Up @@ -192,7 +192,7 @@
mainGroup = A13E26062FA6014E00C324E5;
minimizedProjectReferenceProxies = 1;
packageReferences = (
A139516D2FAC867A00859397 /* XCLocalSwiftPackageReference "../../../EffectView" */,
A1C326A42FD21F7C00393BD8 /* XCLocalSwiftPackageReference "../../../EffectComponents" */,
);
preferredProjectObjectVersion = 77;
productRefGroup = A13E26102FA6014E00C324E5 /* Products */;
Expand Down Expand Up @@ -321,7 +321,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.4;
IPHONEOS_DEPLOYMENT_TARGET = 18.6;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -381,7 +381,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.4;
IPHONEOS_DEPLOYMENT_TARGET = 18.6;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand All @@ -408,7 +408,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -440,7 +440,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -465,7 +465,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = JQD365KZ66;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.4;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.andreas.grosam.home.SimpleEffectViewTests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -486,7 +486,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = JQD365KZ66;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.4;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.andreas.grosam.home.SimpleEffectViewTests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -506,6 +506,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = JQD365KZ66;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.andreas.grosam.home.SimpleEffectViewUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -525,6 +526,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = JQD365KZ66;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.andreas.grosam.home.SimpleEffectViewUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -579,16 +581,16 @@
/* End XCConfigurationList section */

/* Begin XCLocalSwiftPackageReference section */
A139516D2FAC867A00859397 /* XCLocalSwiftPackageReference "../../../EffectView" */ = {
A1C326A42FD21F7C00393BD8 /* XCLocalSwiftPackageReference "../../../EffectComponents" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = ../../../EffectView;
relativePath = ../../../EffectComponents;
};
/* End XCLocalSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
A139516E2FAC867A00859397 /* EffectView */ = {
A1C326A52FD21F7C00393BD8 /* EffectComponents */ = {
isa = XCSwiftPackageProductDependency;
productName = EffectView;
productName = EffectComponents;
};
/* End XCSwiftPackageProductDependency section */
};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions Examples/EffectViewExample/EffectViewExample/Counter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension EnvironmentValues {
}

// MARK: - Transducer
extension Counter.Transducer: EffectView::Transducer {
extension Counter.Transducer: Transducer {

struct State {
var counter = 0
Expand All @@ -40,12 +40,12 @@ extension Counter.Transducer: EffectView::Transducer {
switch event {
case .start:
state.counter = 0
return run(id: "Counter") { input, env in
return task(id: "Counter") { input, env in
while true {
do {
try await Task.sleep(nanoseconds: 1_000_000_000) // 1 sec
print("tick")
input(.tick)
try? input(.tick)
} catch {} // most likely, the counter task has been cancelled; ignore it.
}
}
Expand All @@ -61,6 +61,7 @@ extension Counter.Transducer: EffectView::Transducer {
// MARK: - Views
extension Counter.Views {

@MainActor
struct ContentView: View {
var body: some View {
EnvReader(\.counterViewEnv) {
Expand All @@ -69,6 +70,7 @@ extension Counter.Views {
}
}

@MainActor
struct CounterView: View {
typealias Transducer = Counter.Transducer
typealias Env = Transducer.Env
Expand All @@ -82,12 +84,12 @@ extension Counter.Views {
of: Transducer.self,
state: $state,
initialEnv: env,
) { state, send in
) { state, input in
VStack {
Text("\(state.counter)")
.font(Font.largeTitle.monospacedDigit())
Button("Start") { send(.start) }
Button("Stop") { send(.stop) }
Button("Start") { try? input(.start) }
Button("Stop") { try? input(.stop) }
}
}
.id(env.id) // restart the EffectView when the env changes
Expand Down
14 changes: 7 additions & 7 deletions Examples/EffectViewExample/EffectViewExample/Movies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,24 @@ extension Movies.Transducer: Transducer {


static func loadMovies() -> Effect {
run(id: "load") { input, env in
task(id: "load") { input, env in
do {
let movies = try await env.movieFetch()
input(.loaded(movies))
try input(.loaded(movies))
} catch {
input(.loadFailed(error))
try input(.loadFailed(error))
}
}
}

static func refreshMovies() -> Effect {
// Note: a refresh action
run(id: "refresh") { input, env in
task(id: "refresh") { input, env in
do {
let movies = try await env.movieFetch()
input(.loaded(movies))
try input(.loaded(movies))
} catch {
input(.loadFailed(error))
try input(.loadFailed(error))
}
}
}
Expand Down Expand Up @@ -215,7 +215,7 @@ extension Movies.Views {
isPresented: .constant(state.error != nil),
presenting: state.error
) { _ in
Button("OK") { input(.dismiss) }
Button("OK") { try? input(.dismiss) }
} message: { error in
Text(error.localizedDescription)
}
Expand Down
16 changes: 9 additions & 7 deletions Examples/EffectViewExample/EffectViewExample/RemoteCounter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ extension RemoteCounter {
/// Private state, a public read-only projection, and an event-driven mutation API.
/// Observers must use `withObservationTracking` (or wrap it) — the store itself
/// does not publish a stream.
@Observable @MainActor
@Observable
@MainActor
final class CounterStore: Sendable {

static let shared: CounterStore = .init()
Expand Down Expand Up @@ -91,19 +92,19 @@ extension RemoteCounter.Transducer: Transducer {

case .incrementTapped:
print("incrementTapped")
return run { input, env in
return task { input, env in
await env.store.send(.increment)
}

case .decrementTapped:
print("decrementTapped")
return run { _, env in
return task { _, env in
await env.store.send(.decrement)
}

case .resetTapped:
print("resetTapped")
return run { _, env in
return task { _, env in
await env.store.send(.reset)
}
}
Expand Down Expand Up @@ -146,9 +147,9 @@ extension RemoteCounter.Views {
Text(deltaLabel(state.lastDelta))
.foregroundStyle(.secondary)
HStack(spacing: 24) {
Button("−") { send(.decrementTapped) }
Button("+") { send(.incrementTapped) }
Button("Reset") { send(.resetTapped) }
Button("−") { try? send(.decrementTapped) }
Button("+") { try? send(.incrementTapped) }
Button("Reset") { try? send(.resetTapped) }
}
.buttonStyle(.bordered)
}
Expand All @@ -174,3 +175,4 @@ extension RemoteCounter.Views {
Text("RemoteCounter not available on this OS version")
}
}

Loading
Loading