Commit Graph

1055 Commits

Author SHA1 Message Date
seanmrich
f248eff583 Shared initializers modified to lazy load the initial value (#3060)
Co-authored-by: Sean <sean@snowfort.software>
2024-05-09 14:17:28 -07:00
Won Heo (Woody)
179240217d Enable customDump only in debug mode (#3058)
* Enable customDump only in debug mode

* Change customDump to customDumping String init
2024-05-09 13:24:50 -07:00
Brandon Williams
307c851709 New tutorial: Building SyncUps. (#3039)
* New tutorial: Building SyncUps.

* fix

* clean up

* wip

* wip

* wip

* wip

* wip

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
2024-05-08 11:15:50 -07:00
seanmrich
4c36b18568 Make PersistenceKeyDefault load its default value lazily (#3057)
* Added autoclosure around default value for `PersistenceKeyDefault`

* Added autoclosure around default value for `PersistenceKeyDefault`

---------

Co-authored-by: Sean <sean@snowfort.software>
2024-05-08 11:15:14 -07:00
Stephen Celis
c0d10e2366 Precondition: persistence keys must match value (#3051)
* Precondition: persistence keys must match value

We currently soft-fail if a persistence key is reused across different
types. At runtime a persistence key will write over the other's value,
and vice versa, and data is lost.

Reusing the same file storage URL or app storage key with conflicting
types is a programmer error and ideally should crash over data
corruption.

* wip

* wip
2024-05-07 12:46:22 -07:00
Stephen Celis
eda999e483 Have store.finish() assert no received actions (#3054)
* Have `store.finish()` assert no received actions

`store.finish()` should do much of the same work as `store.deinit`, but
asynchronously with a timeout. This PR updates things so that folks with
long-living test stores (_e.g._ held onto by the test case) have the
ability to assert that there are no unreceived actions.

* test

* Add docs about long-living stores
2024-05-07 12:16:07 -07:00
Stephen Celis
c0a694451f Add a note about nested enum reducers in docs (#3050)
* Add a note about nested enum reducers in docs

* wip
2024-05-06 13:02:51 -07:00
stephencelis
5cb7526485 Run swift-format 2024-05-06 19:23:41 +00:00
Stephen Celis
c76914ee09 Runtime warn when stack integration is missing from store's reducer (#3048)
* Runtime warn when reducer is missing stack integration

If SwiftUI writes to a binding and the state is invalid (it is not
inserting or removing elements from the stack), then the most likely
cause is a missing `forEach` in the reducer (or a missing integration in
some parent reducer).

This commit adds a runtime warning to detect this issue.

* wip
2024-05-06 12:18:36 -07:00
Brandon Williams
096c5546ac Propagate dependencies to reducer all the time. (#3049) 2024-05-06 11:44:06 -07:00
Stephen Celis
5d73967c3e Cancel TestStore effects when root feature is dismissed (#3044)
* Cancel `TestStore` effects when root feature is dismissed

Right now, if a leaf feature is tested and it dismisses itself while
effects are in-flight, the only way to get tests passing is to
explicitly tell the store or any tasks returned by `store.send` to
cancel. Further, you must use an expectation in such tests to assert
that `dismiss` was called in the first place.

This PR changes this behavior to automatically cancel a test store's
effects if it is dismissed, and it prohibits sending more actions to it
after dismiss has been called.

* wip

* wip
2024-05-02 17:59:13 -07:00
Stephen Celis
402346e297 Add @CasePathable @dynamicMemberLookup to 1.4 migration guide (#3043)
* Add `@CasePathable @dynamicMemberLookup` to 1.4 migration guide

This came up recently and I was hoping to point to a part of the
migration guide that explained it, but it didn't exist.

* wip

* wip
2024-05-02 14:51:01 -07:00
Stephen Celis
e6c0959044 Revert perception availability changes (#3036) 2024-04-30 11:43:39 -07:00
Stephen Celis
b5f3786d23 Don't warn when dismissing two layers of tree nav (#3037)
Currently, popping two layers in a nav tree will cause intermediate,
invalid stores to send `dismiss` actions when they shouldn't. This
branch avoids this by checking the store's validity before sending the
action along.

Fixes #3031.
2024-04-30 11:31:33 -07:00
Brandon Williams
9de16b3e96 Fix @Shared initializer with default nil. (#3035)
* Fix @Shared initializer with default nil.

* wip
2024-04-30 11:03:50 -07:00
larryonoff
57cfcb6b92 Fix type in Reducers.md (#3034) 2024-04-30 09:25:24 -07:00
Stephen Celis
aec373a6cc Bump Perception availability (#3025)
* Bump Perception availability

An upstream fix to Perception needs to be applied here.

* Update ObservationStateRegistrar.swift
2024-04-29 13:12:03 -07:00
Brandon Williams
8191e361ec Emit test failure when warning in release. (#3024)
* Emit test failure when warning in release.

* wip
2024-04-29 12:44:29 -07:00
Daniel Lyons
7e22846c8f Add missing NSPrivacyCollectedDataTypes to PrivacyInfo.xcprivacy (#3027)
* Add missing NSPrivacyCollectedDataTypes to PrivacyInfo.xcprivacy

* Update Sources/ComposableArchitecture/Resources/PrivacyInfo.xcprivacy

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

---------

Co-authored-by: Stephen Celis <stephen.celis@gmail.com>
2024-04-29 12:35:22 -07:00
stephencelis
4680b5056d Run swift-format 2024-04-29 19:08:48 +00:00
Shoto Kobayashi
30334f971d Support nested enum reducer (#2813) (#2814)
* Support nested enum reducer (#2813)

* Support nested enum reducer without Macro (#2813)

* Support nested enum reducer without Macro (#2813)

* Support nested enum reducer with default initializer (#2813)

* Minor fixes (#2813)

* Minor fixes (#2813)

---------

Co-authored-by: kobayashi_shoto <kobayashi.shoto@colon.ne.jp>
2024-04-29 12:07:11 -07:00
Stephen Celis
ca0a0a920a Remove Reducer._Body workaround (#3023)
* Remove `Reducer._Body` workaround

This type was mainly introduced to improve Xcode autocomplete of the
`body` property, but since the `@Reducer` macro we don't really get any
autocomplete anyway...

* wip

* fix
2024-04-29 12:06:53 -07:00
Stephen Celis
fb532be3de Organize DocC (#3022) 2024-04-29 09:46:46 -07:00
Brandon Williams
48a43b1b3c Improve docs for 'Navigating to non-reducer features' 2024-04-29 09:13:34 -07:00
mbrandonw
8624a8e2c3 Run swift-format 2024-04-29 00:58:12 +00:00
Stephen Celis
e121b91fb4 Shared State (#2858)
* Shared State

* fix compiler errors in 5.7

* fixes and tests

* fix

* fix

* wip

* longer sleeps

* fix test

* fix tests

* Clean up some typos in SharingState.md (#2860)

* public inits

* wip

* wip

* add test for shared state and onChange

* Case study for sandboxing shared state

* tweaks to case study

* wip

* add tests to sandboxing case study

* rename files

* wip

* simplify sync up tests

* wip

* fix

* wip

* fix $shared.publisher non-determinism and write test that currently fails but ideally would not.

* more docs and a test for autoclosure

* more docs

* wip

* update todo with persistence

* wip

* wip

* support default `nil` optionals in `@Shared`

* Introduce unavailable overload for better diagnostics

* Fix autocomplete from `@Shared(.`

* Revert "Fix autocomplete from `@Shared(.`"

This reverts commit fd1798f9f5.

* Fix defaults

* wip

* Give persistence keys a synchronous update interface (#2880)

* Don't use async sequence for persistence

* wip

* wip

* wip

* Update Sources/ComposableArchitecture/SharedState/PersistenceKey.swift

Co-authored-by: Hal Lee <hal@lee.me>

---------

Co-authored-by: Hal Lee <hal@lee.me>

* Revert sharing in Todos for now

* wip

* wip

* Pass initial shared value to strategy / register app storage (#2904)

* Pass initial shared value to strategy / register app storage

This PR modifies the `PersistenceKey` protocol so that its `load` and
`subscribe` endpoints are handed the initial value and must return a
non-optional value. By feeding this value in, we can ensure that
`.appStorage` declared in a feature is registered outside the feature.

* wip

* wip

* wip

* wip

* wip

* wip

* swift-format

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

Co-authored-by: Pyry Jahkola <pyry.jahkola@iki.fi>

* non-exhaustive fix

* wip

* remove decodable for now

* Fix app storage registration with `nil` values

* fix

* wip

* tutorial

* fixes

* lots of tutorial fixes

* more tutorial fixes

* more tutorial fixes

* more tutorial fixes

* tutorial fixes

* wip

* re-arrange test

* Remove store shared preview quarantine

* Add support for \.defaultInMemoryStorage (#2965)

* fix

* Added Privacy Manifest file (#2930)

* Added Privacy Manifest file

* Update Package@swift-5.9.swift

---------

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

* remove warning overloads

* write default instead of register

this is more consistent with SwiftUI's property wrapper, and causes less
strangeness when multiple repeat properties have different defaults

* move privacy manifest

* wip

* wip

* EphemeralFileStorage -> InMemoryFileStorage

* documented gotcha

* add test

* Shared state beta task snaps (#2976)

* wip

* wip

* wip

* wip

* wip

* wip

* wip

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>

* wip

* Use notification center instead of KVO for user defaults observation. (#2978)

* Use notification center instead of KVO for user defaults observation.

* wip

* wip

* Introduce @SharedReader (#2979)

* wip

* wip

* wip

* wip

* wip

* wip

* Introduce @SharedReader.

* wip

* wip

* sendable

* wip

* wip

---------

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

* Make Shared.Subscription.cancel public (#2983)

* added failing test

* Add convenience initializers

* Save to file storage when app is about to be terminated (#2992)

* Save file storage on termination too.

* wip

* Shared change tracking enhancements (#2989)

* wip

* wip

* wip

* wip

* Add unavailable conformance

* wip

* wip

* wip

* Don't need to check for previews.

* Add default providing persistence key (#2980)

* wip - default providing key

* warn on default access

* Revert "warn on default access"

This reverts commit 38706450bef44a50f94afeaddbc4628e383b52b3.

* wip

* wip

* wip - tests

* wip - reader key

* fix docs

* A few changes.

* A few more changes.

* docs

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>

* Fix optional shared defaults.

* undo last commit but keep test

* wip

* Better shared state change tracking and `TestStore` interactions (#2995)

* A fix for shared assertion.

* fixes

* wip

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>

* docs

* docs

* wip

* Throttle for 1 second.

* fix typo in examples: `let` -> `var` (#2999)

Co-authored-by: Andreas Tielmann <atielmann@deloitte.de>

* wip

* wip

* fix observing projection

* Ping `Shared.publisher` in `willSet` so prev/next values observable

* wip

* wip

* remove sandbox demo

* wip

* wip

* recover inlining

* wip

* wip

* fix docc

* wip

* wip

* re-entrant test

* wip

* Don’t assume CastableLookup (#3011)

* Don’t assume CastableLookup

If the observed value in `UserDefaults` is a `RawRepresentable` type, simply casting to `Value` might fail because the raw representing type could be different from `Value`.  Instead of querying `UserDefaults` directly here, we should call `loadValue()` which will do the right thing for raw representable types (esp. try to call `Value.init(rawValue:)` with the value obtained from `UserDefaults`).

* Add test

---------

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

* Make `FileStorage` more opaque (#3010)

* Make `FileStorage` more opaque

Previously, we had a public protocol and conformances, but we don't
expect anyone to conform outside the library, so instead let's hide
things in a more opaque struct.

The downside of this PR is that it's a breaking API change pretty late
in the game:

```diff
-$0.defaultFileStorage = InMemoryFileStorage()
+$0.defaultFileStorage = .inMemory
```

We could add public deprecated functions that emulate the old
initializers if we think it's worth it...

* wip

* wip

* wip

* wip

* wip

* wip

* fix for 5.7.1

* sync ups clean up

* more docs

* more tests

* shared testing tiups

* wip

* wip

* Fix typo. (#3014)

* more shared state docs

* relax version of swift-dependencies.

* dep change

* fix == and hash on Shared and more tests

* revert == changes

* add test

* Remove hashable conformance from shared

* remove conditional encodability from shared

* wip

* remove syncups tutorial

* wip

* fix

* fix file storage deletion resubscription

* wip

* wip

* wip

* wip

* wip

* fix

* eager throttle

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
Co-authored-by: NF <4764329+NFulkerson@users.noreply.github.com>
Co-authored-by: Hal Lee <hal@lee.me>
Co-authored-by: Brandon Williams <135203+mbrandonw@users.noreply.github.com>
Co-authored-by: Pyry Jahkola <pyry.jahkola@iki.fi>
Co-authored-by: Daniel Lyons <72824209+DandyLyons@users.noreply.github.com>
Co-authored-by: Hilton Campbell <github@crosswaterbridge.com>
Co-authored-by: Luke Redpath <lredpath@community.com>
Co-authored-by: andtie <andreas.tielmann@gmail.com>
Co-authored-by: Andreas Tielmann <atielmann@deloitte.de>
Co-authored-by: Alex Kovács <alex@kobachi.jp>
Co-authored-by: Zev Eisenberg <zev@zeveisenberg.com>
2024-04-28 17:53:12 -07:00
Rhys Morgan
5c1d9b7137 Remove @unchecked from StackState's Sendable conformance (#2997)
* Updates Swift Collections to 1.1.0, and removes @unchecked from StackState's Sendable conformance

* Update Package.swift

---------

Co-authored-by: Stephen Celis <stephen.celis@gmail.com>
2024-04-23 10:26:19 -07:00
David Furman
83b2c1b4c9 Tutorial fixes and updates (#3003)
* Find-and-replace: Add `@testable import CounterApp`

* Typo Fix: "you" -> "your"

* Typo fix: It's -> its

* Typo: `CounterFeature` -> `ContactsFeature`

* Find-and-replace: Switch from deprecated `.navigationBarTitle()` to `navigationTitle()`

* Typo: `using` -> `uses`

* Add `@testable import CounterApp` to the Composing Feature section

* Typo: `closet` -> `closest`

* Remove mention of now-unused forward slash syntax for case paths
2024-04-19 16:52:54 -07:00
Stephen Celis
899a68ce3c Runtime warn for nested observe calls (#2996)
* Runtime warning when we detect nested observe.

* finesse

* wip

* add some tests

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2024-04-17 15:31:31 -07:00
Brandon Williams
7e90901bac Make Effect.publisher eager (#2968)
* Make Effect.publisher eager.

* wip
2024-04-08 19:43:49 -07:00
Brandon Williams
67f23771ac Improve docs for stack-based navigation (#2967)
* Improve docs for stack based navigation.

* wip

* Improve docs for stack based navigation

* wip

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

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

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
2024-04-05 12:41:32 -07:00
Sam Rayner
4514a164f9 Add package access modifier support to @Reducer on enums (#2939) 2024-04-01 11:50:44 -07:00
Takehiro Kaneko
2722a3466b Fix StackBasedNavigation.md (#2944) 2024-03-25 11:10:36 -07:00
Stephen Celis
aa4115145b Enum reducers: generate Never actions for non-features (#2943)
This adjusts the `@Reducer` macro to expand extra `case feature(Never)`
for actions that aren't TCA features.

This allows folks to scope down to stores of non-features for sheets,
etc.:

```swift
.sheet(
  item: $store.scope(state: \.meeting, action: \.meeting)
) { meetingStore in
  // Must use 'Store.withState' here for non-observed feature.
  MeetingView(meeting: meetingStore.withState(\.meeting))
}
```
2024-03-25 11:16:22 +09:00
Stephen Celis
0c22607ba4 Swift bug workaround for TestStore completion (#2923)
* Swift bug workaround for `TestStore` completion

* fix
2024-03-18 13:18:46 -07:00
Stephen Celis
5ab136f5dc Test store tutorial/documentation fixes (#2912)
* Test store tutorial/documentation fixes

* wip
2024-03-11 19:03:17 -07:00
stephencelis
e34b65e6e9 Run swift-format 2024-03-12 01:28:50 +00:00
Stephen Celis
c383ce6e94 Fix SwiftSyntax 510 / Xcode 15.3 warnings (#2909)
* Fix SwiftSyntax 510 / Xcode 15.3 warnings

* fix

* wip

* wip
2024-03-11 18:27:52 -07:00
LR.Snow
c90604418c fix (#2808)
'init(initialState:reducer:withDependencies:file:line:)' is deprecated: State must be equatable to perform assertions.
2024-03-11 14:51:26 -07:00
Brandon Williams
ed7a36651f Change "inert" state to have an ever-changing ID (#2910)
* re-record tests before inert change

* record after inert id change

* remove _$inert
2024-03-11 14:44:57 -07:00
Daiki Matsudate
8f0b35056b Add StackActionOf (#2906)
Signed-off-by: Daiki Matsudate <d.matsudate@gmail.com>
2024-03-11 14:03:26 -07:00
Luke Redpath
8907f4f8c3 fix: Give internal store an id. (#2908) 2024-03-11 11:53:13 -07:00
Takehiro Kaneko
a0acf426f7 Fix typo in TreeBasedNavigation.md (#2898) 2024-03-07 11:11:07 -08:00
Brandon Williams
115fe5af41 Update SwiftSyntax. (#2884)
* Update SwiftSyntax.

* wip

* fix

* wip

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
2024-03-04 22:18:31 -08:00
Stephen Celis
53af95ae3d Fix type-checking regression: remove dynamic case lookup on BindableAction (#2886) 2024-03-04 17:58:30 -08:00
Stephen Celis
9f849e748d Leverage dynamic case writability in example code (#2885)
* Support chainable writability for dynamic case lookup

* wip

* wip

* wip

* wip
2024-03-04 16:17:51 -08:00
Takehiro Kaneko
dfe8e576b7 Fixed document (#2882) 2024-03-03 09:13:06 -08:00
Takehiro Kaneko
687e27795a Fixed a small typo on migration guide 1.9 (#2876) 2024-02-29 20:41:49 -08:00
Brandon Williams
2ddf47f87b Disfavor new subscript (#2875)
* Disfavor case key path for binding actions.

* wip

* fix

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
2024-02-29 14:25:40 -08:00
Brandon Williams
9dcbfd91bd Make enum reducer state equatable in tutorial. (#2873) 2024-02-29 14:25:31 -08:00