Commit Graph

46 Commits

Author SHA1 Message Date
Stephen Celis
ef432a7ae1 wip 2024-10-24 10:40:22 -07:00
Stephen Celis
2009b9c3cb wip 2024-10-17 14:30:12 -07:00
Stephen Celis
d468b45abb wip 2024-10-17 14:17:30 -07:00
Stephen Celis
160bebb7a8 Shared: Simplify internal reference protocol 2024-10-16 14:31:38 -07:00
Brandon Williams
2d0590bedd Clean up key path bitcasting. (#3411)
* Clean up key path bitcasting.

* wip

* wip

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
2024-10-14 13:08:23 -04:00
stephencelis
4c0866420f Run swift-format 2024-09-18 21:39:29 +00:00
Stephen Celis
912192b619 Remove unused perception branches (#3376) 2024-09-12 08:10:06 -07:00
Mason Kim
71cfb1ef2d Existential any to protocol for Swift 6 (#3370)
* Apply existential any to protocol for Swift 6

* Update Package@swift-6.0.swift

* Update Package.swift

* Apply any to Macro.Type

* Apply any for the rest

* Applying the any keyword internally for typealias in a _KeyPath

* Undoing accidental syntax

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
Co-authored-by: Stephen Celis <stephen.celis@gmail.com>
2024-09-10 08:01:24 -07:00
mbrandonw
12280a2253 Run swift-format 2024-09-06 20:47:24 +00:00
Brandon Williams
7c6fb26700 Address @Shared sendability. (#3329)
* Address @Shared sendability.

* Undo UncheckedSendable<UserDefaults>.

* clean up

* wip

* drop AnySendable.

* wip

* Address `Effect.throttle` sendability (#3325)

* Address effect cancellation sendability (#3326)

* Address effect cancellation sendability

* fix

* wip

* wip

* Separate SendableDefaultSubscript from DefaultSubscript.

* fix test

* drop escaping

* switch on swift 6 language mode

* xcode 16

* update test

* wip

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
2024-09-06 16:28:23 -04:00
Brandon Williams
2c8b1c0cad Fix potential deadlock in Shared (#3356)
* Fixed shared deadlock.

* Fix deadlock>

* wip

* wip

* Improve test.
2024-09-06 12:11:40 -04:00
stephencelis
f02d8f6650 Run swift-format 2024-08-29 21:09:34 +00:00
Stephen Celis
a7e2e73f83 Swift 6: Key path sendability (#3282)
* `@preconcurrency @MainActor` isolation of `Store`

* Remove unneeded `@MainActor`s

* Remove thread checking code

* Remove unneeded `@MainActor`s

* Swift 5.10 compatibility fixes

* wip

* More 5.10 fixes

* wip

* fixes

* wip

* wip

* up the timeout

* wip

* Fixes

* wip

* wip

* wip

* wip

* wip

* Fix binding action sendability

* Address more binding action sendability

* more bindable action sendability

* more bindable action warnings

* fix

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2024-08-29 13:46:39 -07:00
Stephen Celis
08faf84fe3 MainActor Store Isolation (#3277)
* `@preconcurrency @MainActor` isolation of `Store`

* Remove unneeded `@MainActor`s

* Remove thread checking code

* Remove unneeded `@MainActor`s

* Swift 5.10 compatibility fixes

* wip

* More 5.10 fixes

* wip

* fixes

* wip

* wip

* up the timeout

* wip

* Fixes

* Remove mainActorASAP in favor of mainActorNow. (#3288)

* wip

* Run swift-format

* Update README.md

* Fix integration tests. (#3294)

* Fix integration tests.

* wip

* wip

* Run swift-format

* mainActorNow doesnt need escaping closure

* wip

* migration guide

* wip

* Update MigratingTo1.14.md

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
Co-authored-by: Brandon Williams <135203+mbrandonw@users.noreply.github.com>
Co-authored-by: mbrandonw <mbrandonw@users.noreply.github.com>
2024-08-27 10:57:46 -07:00
Mason Kim
8821d58ea1 [DOCS] fix minor typo in FileStorageKey (#3305) 2024-08-26 08:47:38 -04:00
Brandon Williams
3a02c5e9fe Fix a bunch of DocC references. (#3287)
* Fix a bunch of DocC references.

* wip

* doc fix

* issue message fix

* swift-navigation 2.0.5
2024-08-15 13:02:49 -04:00
larryonoff
833792ec0f Fix: Crash when writing to user defaults in background thread (#3285)
* Fix: Crash when writing to user defaults in background thread

* Update tests

* Update Tests/ComposableArchitectureTests/AppStorageTests.swift

---------

Co-authored-by: Brandon Williams <135203+mbrandonw@users.noreply.github.com>
2024-08-15 12:59:31 -04:00
Stephen Celis
e1f07facd9 Fix some warnings (#3279)
We have a few warnings, mostly in the test suite, that have cropped up
with deprecations and Xcode 16 strict concurrency, so let's address
them.
2024-08-12 08:24:30 -07:00
Stephen Celis
8343030d8d Shared: Update XCTFail to reportIssue (#3258) 2024-07-24 16:33:32 -07:00
Stephen Celis
3e830b575a Swift Testing support (#3229)
* wip

* wip

* Update Testing.md

* wip

* wip

* wip

* wip

* wip:

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* disable library evolution

* bump

* wip

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2024-07-22 17:52:04 -07:00
Oskar Ek
1b627dcdaa Add support for custom decoding/encoding to fileStorage (#3225)
* Add support for custom decoding/encoding to `fileStorage`

* Update FileStorageKey.swift

---------

Co-authored-by: Stephen Celis <stephen.celis@gmail.com>
2024-07-22 08:41:01 -07:00
Brandon Williams
54eb417336 Make 'didSet' main actor. (#3206)
* Make 'didSet' main actor.

* tests for AppStorageKey

* wip

* tests

* clean up

* Update Sources/ComposableArchitecture/SharedState/PersistenceKey/AppStorageKey.swift

* Update Sources/ComposableArchitecture/SharedState/PersistenceKey/AppStorageKeyPathKey.swift

* try working around CI problem

* Added NB

* wip

* Update MigratingTo1.11.md

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
2024-07-17 08:57:43 -07:00
larryonoff
b5828b231e Fix Shared publisher docs (#3201) 2024-06-24 15:22:23 -04:00
mbrandonw
15d2b12c84 Run swift-format 2024-06-21 19:23:42 +00:00
Brandon Williams
3d343f1fce Some improvements to throttling (#3079)
* Improvements to throttling.

* wip
2024-06-21 15:19:17 -04:00
Ikko Eltociear Ashimine
c0d3ba84e4 Update PersistenceKeyDefault.swift (#3194)
deafult -> default
2024-06-21 10:06:58 -04:00
Brandon Williams
662fee0304 Restrict Shared.elements to IdentifiedArray only. (#3187)
* Restrict Shared.elements to IdentifiedArray only.

* wip

* wip

* wip

* fix test

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
2024-06-19 12:26:55 -07:00
Stephen Celis
bc8f27b1d0 Swift Language Support: Drop <5.9 (#3185)
* Swift Language Support: Drop <5.9

* wip

* wip

* wip

* wip

* wip
2024-06-19 07:40:15 -07:00
stephencelis
53bc869b08 Run swift-format 2024-06-19 05:23:17 +00:00
Brandon Williams
32dadd496b Remove duplicates in app storage key. (#3186) 2024-06-18 22:08:25 -07:00
Stephen Celis
31a7045b49 Disfavor shared optional dynamic member lookup (#3170)
* Disfavor shared optional dynamic member lookup

This makes the default work as expected, avoiding the issue brought up
in #3169.

Technically this breaks the following invocation:

```swift
if let wrapped = $shared.optional { /* ... */ }
```

And limits the warning to:

```swift
func share<T>(_: Shared<T>?) {}
share($shared.optional)
```

We consider this lookup to be a bug, though, which is already deprecated
in 1.11.0.

Since we encourage folks to migrate by one minor version at a time, we
should only merge this when we plan on releasing 1.12.0.

* wip
2024-06-18 16:01:46 -07:00
Brandon Williams
ba82946434 Make withLock main actor. (#3178)
* Make withLock main actor.

* Correct backwards compat article.
2024-06-18 12:17:54 -04:00
Sergio Fernández
964c9aa983 Share state appstorage nullable (#3174)
* failing AppStorageKey stored value and set to nil

* setting SharedAppStorageLocals when removing

* Clean up

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2024-06-17 13:25:12 -07:00
Stephen Celis
7461262608 Allow values to be returned from withLock (#3154) 2024-06-07 07:43:52 -07:00
Brandon Williams
1eeca17b21 Make Shared.wrappedValue setter unavailable from async and introduce Shared.withLock (#3136)
* Add withValue to Shared, deprecate direct mutation.

* updates

* wip

* wip

* wip

* wip

* Available noasync

* withLock

* clean up

* wip

* wip

* Update SyncUpsListTests.swift

* wip

* wip

* wip

* wip

* wip

---------

Co-authored-by: Stephen Celis <stephen@stephencelis.com>
2024-06-06 15:16:34 -07:00
stephencelis
3caaba502b Run swift-format 2024-06-05 16:44:37 +00:00
Brandon Williams
4167b3c0ce Add a SharedReader.constant helper. (#3127) 2024-06-05 09:43:19 -07:00
Stephen Celis
b529ff52d0 Deprecate Shared's optional dynamic member lookup overload (#3145)
* Deprecate `Shared`'s optional dynamic member lookup overload

Currently, `Shared`'s dynamic member lookup is overloaded for
convenience:

```swift
$shared                // Shared<Root>
$shared.value          // Shared<Value>
$shared.optionalValue  // Shared<Value>?
```

Unfortunately, this is also perhaps surprising, and goes against the
grain when folks might expect to be handed a `Shared<Value?>`.

Also, there are times when you have a `Shared<Value?>` already, and you
want to unwrap it. Dynamic member lookup doesn't help there (unless you
know you can call `$shared[dynamicMember: \.self]`), and so you need a
totally different operation to handle it:

```swift
if let unwrappedShared = Shared($optional) {
  // Do something with 'Shared<Value>'
}
```

So let's avoid this confusion in the future and focus on a single API
for unwrapping shared values, which is the failable initializer that
mirrors an API on `Binding`.

* wip

* Update SharedReader.swift

* Update Shared.swift

* Update SharedReader.swift
2024-06-05 09:38:41 -07:00
Paweł Wszeborowski
452155f129 Fix exception when using AppStorageKey with URL Value (#3098) 2024-05-16 15:00:32 -07:00
Brandon Williams
433a23118f Fix for throttle logic. (#3075) 2024-05-11 14:57:32 -07:00
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
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
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
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