Commit Graph

329 Commits

Author SHA1 Message Date
Stephen Celis
1a0c3f9326 Bump Xcode settings (#2042)
* Bump Xcode settings

We had some warnings related to new Xcode 14.3 settings.

* wip
2023-04-14 08:06:26 -07:00
Stephen Celis
4192a843ee Pass state to SwitchStore.init view builder (#2029)
* Pass state to `SwitchStore.init` view builder

Rather than rely on many, many overloads of `SwitchStore.init` to
strictly accept only `CaseLet`s and an optional, final `Default` view,
let's introduce a single initializer without constraints that is passed
the current state whenever the case changes. This state can be switched
on and route to the appropriate view via `CaseLet`.

The pros:

  * We get exhaustive switching at compile time.

  * We get more flexibility in the view layer. Previously, any
    customization needed to be pushed into the `CaseLet` builder, but
    now `CaseLet` can freely apply view modifiers.

  * We can deprecate and eventually remove the many, many initializer
    overloads, and hopefully slim down binary size in the process, and
    improve view builder compile times when dealing with `SwitchStore`.
    We can also deprecate and eventually remove `Default`.

The cons:

  * It's slightly more verbose and repetitive. You have a `SwitchStore`
    and then a `switch` inside it with many `case`s with `CaseLet`s
    inside them, and the `case .screen:` is followed by
    `CaseLet(/State.screen, ...)`.

  * One is free to extract the state's associated value(s) and use it to
    render a view, but this view will be inert and will not re-render if
    the value it depends on changes in the store. This can lead to some
    surprises, but we can document against the pattern, and maybe in the
    future we can use something like macros to prevent this from being
    possible.

  * You can still get things wrong if you're not careful: there's
    nothing enforcing that the `case` you switch on is the same case you
    send to `CaseLet`, so `case .screenA: CaseLet(/State.screenB, ...)`
    is possible. While unlikely, it's still a copy-paste error in
    waiting.

* wip

* wip

* wip

* Bump

* fix test

* clean up

* clean up

* clean up

* wip

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2023-04-10 11:37:02 -07:00
mbrandonw
3258ec34aa Run swift-format 2023-02-21 19:54:57 +00:00
Brandon Williams
ef0efdb94e Fix UI test for ForEach bindings. (#1933)
* Fix UI test for ForEach bindings.

* wip

* wip

* _withMainSerialExecutor testSendWhile
2023-02-21 11:42:17 -08:00
Stephen Celis
e294b24edb Add Effect.send (#1859)
* Add `Effect.send`

With the `Effect<Action, Failure>` -> `Effect<Action>` migration,
`Effect.init(value:)` and `Effect.init(error:)` no longer make sense. We
will be retiring the latter some time in the future, so let's also get a
head start and rename the former to `Effect.send`.

For now it will call `Effect.init(value:)` under the hood, but in the
future we will want a non-Combine-driven way of running synchronous
effects.

* format fix

* wip

* fix

* wip

* wip
2023-01-23 16:41:01 -08:00
Stephen Celis
0ed5c83d96 Deprecate TestStore.init that doesn't require equatable state (#1857)
And introduce `TestStore.init(initialState:reducer:observe:send:)` for
testing scoped state and actions.
2023-01-23 10:44:43 -08:00
Stephen Celis
52c4a01437 Rename BindableState to BindingState (#1855)
The -`able` naming evokes protocols in Swift, and is an outlier when
considered alongside the rest of TCA's binding tools:

- `BindingAction`: concrete type
- `BindableAction`: protocol
- `BindingReducer`: concrete type

So, let's make things consistent.

The one caveat is that Swift diagnostics for such a deprecation aren't
great, so users won't get proactive warnings here for the time being:

https://github.com/apple/swift/issues/63139

We may just want to keep the deprecation around till it does...
2023-01-20 14:56:53 -08:00
Stephen Celis
c5a7d1be9a Add prepareDependencies to Store.init (#1844)
* Add `prepareDependencies` to `Store.init`:wq

* wip

* test and doc

* update TTT previews to use new trailing closure style"

* wip

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2023-01-17 20:08:52 -08:00
mbrandonw
9e83d195fb Run swift-format 2023-01-11 22:02:42 +00:00
Thomas Grapperon
db39334dcc Add a UI test for escaped ViewStore from WithViewStore, and a Binding animations test bench (#1819)
* Add a UITest for escaped `ViewStore` from `WithViewStore`

* Add `BindingsAnimationsTestBench`

* Cleanup
2023-01-11 13:49:25 -08:00
stephencelis
09271d56f4 Run swift-format 2023-01-10 22:56:44 +00:00
Brandon Williams
82d2b78074 UI test to catch SwiftUI regressions (#1815)
* Add some UI tests to catch regressions.

* wip

* wip
2023-01-10 17:44:01 -05:00
Thomas Grapperon
f1d62bc413 Fix UIKit's "Navigate and Load" study (#1807) 2023-01-09 11:37:10 -05:00
Stephen Celis
9b5a510174 Depend on swift-dependencies (#1808)
Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2023-01-09 11:08:23 -05:00
Stephen Celis
30015d13a3 Revert #1790 (#1795)
It occurred to us that this solution unfortunately is incompatible with
view actions. We have an alternate solution that works, so I'll PR that
in the future if no others materialize!
2023-01-05 18:04:48 -05:00
stephencelis
d1c2e5b6d1 Run swift-format 2023-01-05 18:30:30 +00:00
Thomas Grapperon
c719fa1d39 Allow BindingReducer to work with ViewState (#1790)
* Simpler bindable view state

* wip

* wip

* Remove `BindingStore`

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Make BindingState conditionally sendable.

* Fixed tests

* Update bindings article

* Add some additional contextual information to the runtime warnings

* update some docs

* lots more docs

* test clean up

* Improve diagnostic

* Put back `BindingReducer()` in the form study

* clean up

* Improve DocC references

* Remove DocC references for `@`'d property wrappers.

* wip

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2023-01-05 13:18:34 -05:00
Pat Brown
fe5603ec38 Bump SwiftUINavigation and update examples (#1760)
* bump navigation

* bump swiftui-navigation

* Add SearchView preview

* make login sendable

* use button state builder

* format

* bump swift and platform version

* remove unused test clock

* Add quotes to scheme
2022-12-20 23:32:33 -05:00
Thomas Grapperon
1c50ffcf44 Typo (#1702)
wow!
2022-11-29 13:30:57 -06:00
Brandon Williams
1c19319aed Delete correct todo when filtering. (#1696) 2022-11-28 16:04:42 -06:00
유재호
ab020e81bd Fix typos in ReducerProtocol.swift and so on (#1638) 2022-11-08 12:37:07 -05:00
Stephen Celis
b21a7d5aad Update case studies/docs for Scope and reducer builders (#1623)
We still had some old copy around `pullback` and `combine` that I'm sure
are confusing.
2022-11-04 13:43:24 -07:00
Brandon Williams
3bfbc7f9b8 Removed unnecessary clock sleep. 2022-11-03 09:36:16 -04:00
Stephen Celis
5d687b6b41 Non-exhaustive testing (#1599)
* Allow for non-exhaustive test store.

* wip

* wip

* wip

* wip

* wip

* clean up

* docs

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* fix tests

* wip

* wip

* wip

* wip

* wip

* merge fixes

* fixes

* wip

* wip

* wip

* infrastructure

* add extraction based overload

* wip

* more tests

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* docs fix

* fix

* wip

* wip

* wip

* lots of doc fixes

* wip

* ci

* wip

* wip

* wip;

* wip

* Update .github/workflows/ci.yml

Co-authored-by: Brandon Williams <135203+mbrandonw@users.noreply.github.com>

* Update Sources/ComposableArchitecture/Documentation.docc/Articles/Testing.md

Co-authored-by: Brandon Williams <135203+mbrandonw@users.noreply.github.com>

* fix docs

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
Co-authored-by: Brandon Williams <135203+mbrandonw@users.noreply.github.com>
2022-10-31 11:23:10 -07:00
Stephen Celis
f8554f7088 Avoid failure when setting test dependency values (#1570)
* Avoid failure when setting test dependency values

It's currently possible to emit XCTest failures when testing reducers
that access dependency values that emit failure upon access, which
includes the calendar, locale, time zone, and URL session dependencies.

We may need a more holistic solution for folks that define these kinds
of dependencies outside the library, but this will make the
library-level failures a bit more lenient.

* wip

* a few more tests

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2022-10-25 12:26:55 -07:00
Brandon Williams
4ece153d6b Add swift-clocks to TCA (#1547)
* Convert schedulers to clocks.

* wip

* wip

* wip

* wip

* Update 01-GettingStarted-Animations.swift (#1512)

Typo

* bump

* wip

* wip

* fix

* doc fix

* wip

* update

* update

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* update clocks

* wip

* clocks

* wip

* wip

Co-authored-by: Ken Grigsby <kgrigsby@mac.com>
Co-authored-by: Stephen Celis <stephen@stephencelis.com>
2022-10-23 22:28:31 -07:00
유재호
95af6c10c4 Remove redundant error type in ReusableFavoritingTests.swift (#1538)
* Remove redundant error type in Reusable Favoriting Tests

* Revert AlertState's title to be concrete one
2022-10-21 17:46:30 -07:00
Inwoo Hwang
17ec3d9f81 refactor : remove unnecessary conformance to Sendable Protocol (#1535) 2022-10-20 09:01:38 -04:00
Stephen Celis
cc535c3e37 XCTUnimplemented -> unimplemented (#1530) 2022-10-19 16:17:48 -07:00
mbrandonw
847b47043c Run swift-format 2022-10-19 18:40:43 +00:00
유재호
c1302e5e20 Improve the layout of Web Socket case study (#1529)
* Improve layout of Web Socket case study

* Update Examples/CaseStudies/SwiftUICaseStudies/02-Effects-WebSocket.swift

Co-authored-by: Thomas Grapperon <35562418+tgrapperon@users.noreply.github.com>

Co-authored-by: Thomas Grapperon <35562418+tgrapperon@users.noreply.github.com>
2022-10-19 14:30:19 -04:00
mbrandonw
1e6df4a7ce Run swift-format 2022-10-18 20:17:14 +00:00
Thomas Grapperon
6fee86ba4f Store dependencies default values on first access (#1510)
* wip

* wip

* wip

* Fix lock

* Remove trailing spaces

* Simplify implementation

* Store default values in `DependencyValues`

* Simplify implementation again

* Make helper function private

* Rename `Default` to `DefaultValues`

* Fix spacing

* Fix spacing again

* Some changes to dependency caching logic.

* shorten

* fix tests

* fileprivate

* Update docs

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2022-10-18 16:08:17 -04:00
Thomas Grapperon
41f1cb9f3f Add a EffectTask<Action> typealias for Effect<Action, Never> and rename Effect to EffectPublisher (#1471)
* Add an `EffectOf<Action>` typealias for `Effect<Action, Never>`

* Fix doc

* Rename `EffectOf` to `EffectTask`

* Rename `Effect` to  `EffectPublisher`

* Soft-deprecate `Effect`

* Link to `EffectTask`

* Use `EffectPublisher` in Combine contexts

* Reword soft-deprecation message

* Remove `renamed:` fix-it for `Effect` deprecation

* Update Sources/ComposableArchitecture/Documentation.docc/Extensions/ReducerProtocol.md

Co-authored-by: Stephen Celis <stephen.celis@gmail.com>

* Update Sources/ComposableArchitecture/Documentation.docc/ComposableArchitecture.md

* Update Sources/ComposableArchitecture/Effect.swift

* Fix DocC identifiers

Co-authored-by: Stephen Celis <stephen.celis@gmail.com>
2022-10-17 15:16:46 -07:00
유재호
790469d1e5 Remove unnecessary dependencies in every CaseStudies (#1503)
* Remove unnecessary dependencies in SwiftUI-CaseStudies

* Remove unnecessary dependencies in other-CaseStudies

* Add MARK headers to every SwiftUI-CaseStudies
2022-10-15 14:23:01 -07:00
Stephen Celis
e11ca0eddc Require Swift 5.6 (#1491)
* Restore Swift 5.5 compatibility

As pointed out in #1489, we somehow lost compatibility with Swift 5.5
(Xcode 13.2). While we hope to drop support when we hit 1.0, let's try
to keep compatiblity in the meantime.

* Update DependencyValues.swift

* Update Sources/Dependencies/DependencyValues.swift

Co-authored-by: Brandon Williams <135203+mbrandonw@users.noreply.github.com>

* Require Swift 5.6

* Update ci.yml

Co-authored-by: Brandon Williams <135203+mbrandonw@users.noreply.github.com>
2022-10-13 14:55:32 -07:00
mbrandonw
d43ac98e4c Run swift-format 2022-10-13 19:59:44 +00:00
Thomas Grapperon
f220051aaa Remove a few dependencies to UIKit in SwiftUI's CaseStudies (#1492)
* Remove a few dependencies to UIKit in SwiftUI's CaseStudies

* Update Examples/CaseStudies/SwiftUICaseStudies/02-Effects-Basics.swift

* Update Examples/CaseStudies/SwiftUICaseStudies/02-Effects-Cancellation.swift

Co-authored-by: Brandon Williams <135203+mbrandonw@users.noreply.github.com>
2022-10-13 15:27:18 -04:00
stephencelis
bcae29f23d Run swift-format 2022-10-10 18:37:19 +00:00
Brandon Williams
b8294b89d5 ReducerProtocol (#1283)
* Add previewValue to DependencyKey, and fixed build errors on Xcode 13.

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Add Xcode 14 to CI (#1266)

* Add Xcode 14 to CI

* Update ci.yml

* wip

* wip

* Update Makefile

* Update Makefile

* wip

* runtime warning when no live dependency available for live app

* bring back live

* wip

* soft deprecate Reducer

* fusion test

* ternary clean up

* wip

* add some todos

* typealias Reducer inside AnyReducer

* Add `now` convenience property to date dependency (#1286)

* Remove type alias

* LiveDependencyKey: DependencyKey -> DependencyKey: TestDependencyKey (#1288)

* LiveDependencyKey: DependencyKey -> DependencyKey: TestDependencyKey

* wip

* wip

* wip

* wip

* wip

* fix

* wip

* fix navigate case studies

* wip

* fixes and docs

* more migration

* wip

* wip

* thread deps through ifLet and forEach examples.

* update

* clean up

* wip

* wip

* Update MigratingToReducerProtocols.md

* wip

* wip

* docs

* docs

* fix some docs

* Fix for CombineReducers compiler bug

* wip

* wip

* wip

* wip

* todos for docs

* Don't warn for overridden test dependencies (#1324)

* Don't warn while setting test dependencies

* wip

* fix conflict

* wip

* Docs and deprecations

* add binding info

* wip

* Add URL session

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Don't run debug reducer in tests

* wip

* updated reducer debugging

* Update UUID.swift (#1374)

* wip

* optional

* added Self as default associatedtype value for TestDependencyKey.value (#1395)

* added Self as default associatedtype value for TestDependencyKey.value

* Update Tests/ComposableArchitectureTests/DependencyKeyTests.swift

Co-authored-by: Brandon Williams <135203+mbrandonw@users.noreply.github.com>

* Update example to set badge to the unread count (#1391)

* Add store.finish().

* Fix warnings introduced in Xcode 14.1 (#1388)

* Fix warnings introduced in Xcode 14.1

* wip

* Conform dependency values to DependencyKey where convenient

* fix

* Fail if testValue is invoked without providing implementation (#1399)

* Update example to set badge to the unread count (#1391)

* Add store.finish().

* Fix the CaseStudies (UIKit) (#1392)

* Fix warnings introduced in Xcode 14.1 (#1388)

* Fix warnings introduced in Xcode 14.1

* wip

* Fail when accessing testValue when one hasn't been provided.

* wip

* wip

* wip

* test

Co-authored-by: Mark Adams <hyperspacemark@users.noreply.github.com>
Co-authored-by: Maciek Czarnik <Czajnikowski@users.noreply.github.com>
Co-authored-by: Stephen Celis <stephen@stephencelis.com>

* Add DateGenerator.init(_ generate:)

* Start running some tests in release config. (#1405)

* Start running some tests in release config.

* wip

* wip

* wip

* wip

* wip

* Update Sources/ComposableArchitecture/Store.swift

Co-authored-by: Thomas Grapperon <35562418+tgrapperon@users.noreply.github.com>

* wip

* wip

Co-authored-by: Thomas Grapperon <35562418+tgrapperon@users.noreply.github.com>

* added test that dependencies are transferred to effects

* wip

* self

* clean up

* simplify

* fix

* doc fixes

* wip

* fix

* wip

* wip

* wip

* fix

* Run dependencies tests on CI. (#1408)

* Run dependencies tests on CI.

* wip

* update makefile

* wtf

* more docs

* more docs

* wip

* docs

* wip

* docs

* wip

* message tweaks

* wip

* docs and clean up

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* typo fix

* docs clean up

* doc fixes

* cancel in progress

* cancel in progress

* no need to make recope release-only, and make more use of XCTAssert to get better release tests

* fix test

* Remove ActorIsolated from tests where it's not needed

* fix test

* wip

* wip

* Add a benchmark for dependency key writing.

* fix test

* make benchmark 5.7 compatible

* iflet docs

* more docs

* dependency docs

* rearrange

* @Dependency docs

* docs

* fix benchmark in 5.6

* doc fix

* wip

* wip

* wip

* wip

* more docs

* clean up

* fix

* wip

* Fixes compilation on watchOS (#1423)

Co-authored-by: Gunnar Herzog <gunnar.herzog@kf-interactive.com>

* move deprecation

* format

* wip

* Fix openURL

* wip

* wip

* wip

* wip

* fix

* Keep simple

* Reducer.debug -> Reducer._printChanges

We want to revisit some of these debugging APIs in the future, so let's
keep them around, but underscore them to allow for more flexible
evolution.

* `ReducerProtocol.debug` -> `ReducerProtocol._printChanges` (#1426)

* Reducer.debug -> Reducer._printChanges

We want to revisit some of these debugging APIs in the future, so let's
keep them around, but underscore them to allow for more flexible
evolution.

* Update DebugTests.swift

* OpenURL fix for macCatalyst (#1429)

* OpenURL fix for macCatalyst

Fixes #1428.

* Update Makefile

* Correct typo in "Designing dependencies" chapter (#1430)

protocol AudioPlayerClient should be a struct

* fix

* fix

* protocol docc

* docs

* Typos (#1439)

* remove unneeded internals

* wip

* Fix missing parameter in code sample (#1450)

* typo fix

* more docs for DependencyKeyWritingReducer

* wip

* wip

* update readme

* wip

* update image

* main actor

* Added withValue, added docs and tests

* public properties

* cleaned up overload

* changed reducer->feature in a bunch of spots of dependencies docs

* add articles to readme

* 6

* fix tests for swift 5.6

* tweak

* tweak

* Update ReducerProtocol.swift

* wip

* wip

* docs update

* docs for conforming dependency directly to DependencyKey

* typo fix

* performance article update

* fixes

* deprecate another effect timer API

* link to migration doc in deprecation messages

* make some tests that deal with line numbers less fragile

* package.swift clean up

* tweak to echos

* remove docs at root, not in docs-out

* remove todo

* update WithViewStore.init deprecation message to explain and link to performance doc

* Add back ReducerProtocolOf for 5.7.1 (#1444)

* Add back ReducerProtocolOf for 5.7.1

* wip

* Move scheme tests to matrix

* streamline

* try this

* store.finish

* wip

* dependencies -> transformDependency

* wip

* wip

* Compat

* fix

* preserve deps for combine publishers

* Remove dump calls (#1460)

* Fix compiler errors for library evolution. (#1443)

* Fix compiler errors for library evolution.

* wip

* wip

* work around ambiguous init

* Revert "work around ambiguous init"

This reverts commit 002a199d59.

* fix ambiguity errors

* remove _Observe for now

* wip

* wip

* wip

* longer timeout

* more waiting

* wip

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
Co-authored-by: Ken Grigsby <kgrigsby@mac.com>
Co-authored-by: Petr Sima <ptea.sima@gmail.com>
Co-authored-by: Mark Adams <hyperspacemark@users.noreply.github.com>
Co-authored-by: Maciek Czarnik <Czajnikowski@users.noreply.github.com>
Co-authored-by: Thomas Grapperon <35562418+tgrapperon@users.noreply.github.com>
Co-authored-by: Gunnar Herzog <github@trispo.de>
Co-authored-by: Gunnar Herzog <gunnar.herzog@kf-interactive.com>
Co-authored-by: Guttorm Aase <guttormaase@gmail.com>
Co-authored-by: Julien Sagot <contact@juliensagot.fr>
Co-authored-by: Jaanus Siim <jaanussiim+github@gmail.com>
2022-10-10 11:37:50 -04:00
Stephen Celis
3ba71b9787 Todos demo: fix sorting filtered todos (#1404)
* Todos demo: fix sorting filtered todos

* wip

* Update TodosTests.swift
2022-09-20 14:36:04 -07:00
mbrandonw
06d4d6e664 Run swift-format 2022-09-20 20:26:45 +00:00
Brandon Williams
99e493b178 Clean up the recursive case study. (#1403) 2022-09-20 15:53:12 -04:00
Stephen Celis
bcdcb3d709 Fix warnings introduced in Xcode 14.1 (#1388)
* Fix warnings introduced in Xcode 14.1

* wip
2022-09-19 11:31:34 -04:00
Maciek Czarnik
f8f0d52c65 Fix the CaseStudies (UIKit) (#1392) 2022-09-19 11:20:55 -04:00
Brandon Williams
c0f266b79a Add store.finish(). 2022-09-19 09:41:05 -04:00
Stephen Celis
5b78fbcb05 Allow re-entrant actions to be processed (#1352)
* wip

* wip

* clean up

* wip

* wip

* wip

* wip

* fix

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2022-09-08 11:47:28 -04:00
Brandon Williams
4c98b432b3 await store.finish() in voice memo test. 2022-09-08 08:19:20 -04:00
Brandon Williams
eb43df7d09 Fix a few flakey tests (#1344)
* Try fixing some flakey tests.

* store finish

* wip

* wip

* wip

* wip

* wip

* try out a timeout

* wip

* Update Package.swift

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
2022-09-07 14:46:18 -04:00
Stephen Celis
bef2084cb2 Introduce WithViewStore.init(_:observe:send:...) (#1339)
* wip

* Introduce `WithViewStore.init(_:observe:send:...)`

* Update examples

* wip

* typo

* wip
2022-09-07 10:08:20 -04:00