Skip to content

Releases: 0xLeif/AppState

1.17.0

25 Apr 22:41
cb2eebd
Compare
Choose a tag to compare

What's Changed

Full Changelog: 1.16.0...1.17.0

1.16.0

10 Mar 17:17
6d47c27
Compare
Choose a tag to compare

What's Changed

  • Add setup parameter for Application by @0xLeif in #99

Now you can use the setup parameter to preform any operations you need before the Application starts consuming the cache and publishing changes. This is useful for loading default dependencies your custom application might use.

class SomeApplication: Application {
    static func someFunction() { /* no-op */ }

    required init(setup: (Application) -> Void = { _ in }) {
        super.init { application in
            application.load(dependency: \.icloudStore)
            setup(application)
        }
    }
}

Full Changelog: 1.15.0...1.16.0

1.15.0

08 Mar 01:01
fbffe58
Compare
Choose a tag to compare

What's Changed

  • Added new Application.preview to be used in #Preview to override the needed dependencies for the content view. (Leif/preview improvements by @0xLeif in #98)
class Service {
    var title: String { "Live Service" }
}

class MockService: Service {
    override var title: String { "Mock Service" }
}

extension Application {
    var service: Dependency<Service> {
        dependency(Service())
    }
}

struct ContentView: View {
    @AppDependency(\.service) private var service

    var body: some View {
        Text(service.title)
    }
}

#Preview {
    Application.preview(
        Application.override(\.service, with: MockService()),
        Application.override(\.userDefaults, with: UserDefaults())
    ) {
        ContentView()
    }
}

Full Changelog: 1.14.0...1.15.0

1.14.0

06 Mar 01:06
eeab0d2
Compare
Choose a tag to compare

What's Changed

  • Property wrapper @AppState now supports all types of state: FileState, StoredState, SyncState, SecureState, and State.
  • SecureState is now supported for Constant and Slice.

What's Changed

Full Changelog: 1.13.0...1.14.0

1.13.0

02 Mar 01:33
79a1087
Compare
Choose a tag to compare

What's Changed

  • SyncState is now backed by StoredState by @0xLeif in #96

Full Changelog: 1.12.0...1.13.0

1.12.0

24 Feb 19:35
83e2d80
Compare
Choose a tag to compare

What's Changed

Full Changelog: 1.11.0...1.12.0

1.11.0

04 Feb 20:47
ce10e98
Compare
Choose a tag to compare

What's Changed

Full Changelog: 1.10.2...1.11.0

1.10.2

26 Jan 23:30
5ce030f
Compare
Choose a tag to compare

What's Changed

  • Fix crash when StoredState needs to be Data by @0xLeif in #89
  • Addressing State being consistent in value from the first check (#90) by @0xLeif in #91

Full Changelog: 1.10.1...1.10.2

1.10.1

25 Jan 16:27
c72c820
Compare
Choose a tag to compare

What's Changed

  • Add objectWillChange notification by @0xLeif in #85

Full Changelog: 1.10.0...1.10.1

1.10.0

25 Jan 01:39
662afd6
Compare
Choose a tag to compare

Introducing DependencySlices and DependencyConstants in AppState!

AppState is all about improving the management of your application's state. Now we are taking it a step further with two new features: DependencySlices and DependencyConstants!

These features are designed to enhance the usage of values from ObservableObject dependencies, making it even easier to bind to a value.

For example, consider the following ViewModel:

class ViewModel: ObservableObject {
    @Published var isShowingSheet: Bool = false
    @Published var username: String?
}

extension Application {
    var viewModel: Dependency<ViewModel> {
        dependency(ViewModel())
    }
}

In the past, you would have accessed your ViewModel like this, where you would need to add @Published to any variables:

struct BasicViewModelAppState: View {
   @ObservedDependency(\.viewModel) private var viewModel

    var body: some View {
        InnerView(username: $viewModel.username)
    }
}

struct InnerView: View {
    @Binding var username: String?

    var body: some View {
        Text("[\(username ?? "World")]")
            .onTapGesture {
                username = "Tap"
            }
    }
}

But with the new DependencySlice feature, you can now access your ViewModel without needing to add @Published to any variables, and the SwiftUI views will still update:

class ViewModel: ObservableObject {
    var isShowingSheet: Bool = false
    var username: String?
}

extension Application {
    var viewModel: Dependency<ViewModel> {
        dependency(ViewModel())
    }
}

struct BasicViewModelAppState: View {
   @ObservedDependency(\.viewModel) private var viewModel

    var body: some View {
        InnerView()
    }
}

struct InnerView: View {
    @DependencySlice(\.viewModel, \.username) private var username

    var body: some View {
        Text("[\(username ?? "World")]")
            .onTapGesture {
                username = "Tap"
            }
    }
}

What's Changed

Full Changelog: 1.9.1...1.10.0