diff --git a/Sources/AppState/Application/Types/Application+Dependency.swift b/Sources/AppState/Application/Types/Dependency/Application+Dependency.swift similarity index 100% rename from Sources/AppState/Application/Types/Application+Dependency.swift rename to Sources/AppState/Application/Types/Dependency/Application+Dependency.swift diff --git a/Sources/AppState/Application/Types/Application+Scope.swift b/Sources/AppState/Application/Types/Helper/Application+Scope.swift similarity index 82% rename from Sources/AppState/Application/Types/Application+Scope.swift rename to Sources/AppState/Application/Types/Helper/Application+Scope.swift index c611211..b6da680 100644 --- a/Sources/AppState/Application/Types/Application+Scope.swift +++ b/Sources/AppState/Application/Types/Helper/Application+Scope.swift @@ -4,15 +4,15 @@ extension Application { For example, it could be used to scope a state to a particular screen or user interaction flow. */ - struct Scope { + public struct Scope { /// The name of the scope context - let name: String + public let name: String /// The specific id for this scope context - let id: String + public let id: String /// Key computed property which builds a unique key for a given scope by combining `name` and `id` separated by "/" - var key: String { + public var key: String { "\(name)/\(id)" } } diff --git a/Sources/AppState/Application/Types/MutableApplicationState.swift b/Sources/AppState/Application/Types/Helper/MutableApplicationState.swift similarity index 100% rename from Sources/AppState/Application/Types/MutableApplicationState.swift rename to Sources/AppState/Application/Types/Helper/MutableApplicationState.swift diff --git a/Sources/AppState/Application/Types/Application+OptionalSlice.swift b/Sources/AppState/Application/Types/Slice/Application+OptionalSlice.swift similarity index 100% rename from Sources/AppState/Application/Types/Application+OptionalSlice.swift rename to Sources/AppState/Application/Types/Slice/Application+OptionalSlice.swift diff --git a/Sources/AppState/Application/Types/Application+OptionalSliceOptionalValue.swift b/Sources/AppState/Application/Types/Slice/Application+OptionalSliceOptionalValue.swift similarity index 100% rename from Sources/AppState/Application/Types/Application+OptionalSliceOptionalValue.swift rename to Sources/AppState/Application/Types/Slice/Application+OptionalSliceOptionalValue.swift diff --git a/Sources/AppState/Application/Types/Application+Slice.swift b/Sources/AppState/Application/Types/Slice/Application+Slice.swift similarity index 100% rename from Sources/AppState/Application/Types/Application+Slice.swift rename to Sources/AppState/Application/Types/Slice/Application+Slice.swift diff --git a/Sources/AppState/Application/Types/Application+SecureState.swift b/Sources/AppState/Application/Types/State/Application+SecureState.swift similarity index 100% rename from Sources/AppState/Application/Types/Application+SecureState.swift rename to Sources/AppState/Application/Types/State/Application+SecureState.swift diff --git a/Sources/AppState/Application/Types/Application+State.swift b/Sources/AppState/Application/Types/State/Application+State.swift similarity index 100% rename from Sources/AppState/Application/Types/Application+State.swift rename to Sources/AppState/Application/Types/State/Application+State.swift diff --git a/Sources/AppState/Application/Types/Application+StoredState.swift b/Sources/AppState/Application/Types/State/Application+StoredState.swift similarity index 89% rename from Sources/AppState/Application/Types/Application+StoredState.swift rename to Sources/AppState/Application/Types/State/Application+StoredState.swift index 650696e..3406e3f 100644 --- a/Sources/AppState/Application/Types/Application+StoredState.swift +++ b/Sources/AppState/Application/Types/State/Application+StoredState.swift @@ -18,11 +18,11 @@ extension Application { get { let cachedValue = shared.cache.get( scope.key, - as: Value.self + as: State.self ) if let cachedValue = cachedValue { - return cachedValue + return cachedValue.value } guard @@ -41,7 +41,11 @@ extension Application { userDefaults.removeObject(forKey: scope.key) } else { shared.cache.set( - value: newValue, + value: Application.State( + type: .stored, + initial: newValue, + scope: scope + ), forKey: scope.key ) userDefaults.set(newValue, forKey: scope.key) diff --git a/Sources/AppState/Application/Types/Application+SyncState.swift b/Sources/AppState/Application/Types/State/Application+SyncState.swift similarity index 95% rename from Sources/AppState/Application/Types/Application+SyncState.swift rename to Sources/AppState/Application/Types/State/Application+SyncState.swift index d554305..e31d235 100644 --- a/Sources/AppState/Application/Types/Application+SyncState.swift +++ b/Sources/AppState/Application/Types/State/Application+SyncState.swift @@ -54,11 +54,11 @@ extension Application { guard let cachedValue = shared.cache.get( scope.key, - as: Value.self + as: State.self ) else { return initial() } - return cachedValue + return cachedValue.value } set { let mirror = Mirror(reflecting: newValue) @@ -67,17 +67,19 @@ extension Application { mirror.children.isEmpty { shared.cache.remove(scope.key) icloudStore.removeObject(forKey: scope.key) - icloudStore.synchronize() } else { shared.cache.set( - value: newValue, + value: Application.State( + type: .sync, + initial: newValue, + scope: scope + ), forKey: scope.key ) do { let data = try JSONEncoder().encode(newValue) icloudStore.set(data, forKey: scope.key) - icloudStore.synchronize() } catch { Application.log( error: error, diff --git a/Sources/AppState/PropertyWrappers/AppDependency.swift b/Sources/AppState/PropertyWrappers/Dependency/AppDependency.swift similarity index 100% rename from Sources/AppState/PropertyWrappers/AppDependency.swift rename to Sources/AppState/PropertyWrappers/Dependency/AppDependency.swift diff --git a/Sources/AppState/PropertyWrappers/Constant.swift b/Sources/AppState/PropertyWrappers/Slice/Constant.swift similarity index 100% rename from Sources/AppState/PropertyWrappers/Constant.swift rename to Sources/AppState/PropertyWrappers/Slice/Constant.swift diff --git a/Sources/AppState/PropertyWrappers/OptionalConstant.swift b/Sources/AppState/PropertyWrappers/Slice/OptionalConstant.swift similarity index 100% rename from Sources/AppState/PropertyWrappers/OptionalConstant.swift rename to Sources/AppState/PropertyWrappers/Slice/OptionalConstant.swift diff --git a/Sources/AppState/PropertyWrappers/OptionalSlice.swift b/Sources/AppState/PropertyWrappers/Slice/OptionalSlice.swift similarity index 100% rename from Sources/AppState/PropertyWrappers/OptionalSlice.swift rename to Sources/AppState/PropertyWrappers/Slice/OptionalSlice.swift diff --git a/Sources/AppState/PropertyWrappers/Slice.swift b/Sources/AppState/PropertyWrappers/Slice/Slice.swift similarity index 100% rename from Sources/AppState/PropertyWrappers/Slice.swift rename to Sources/AppState/PropertyWrappers/Slice/Slice.swift diff --git a/Sources/AppState/PropertyWrappers/AppState.swift b/Sources/AppState/PropertyWrappers/State/AppState.swift similarity index 100% rename from Sources/AppState/PropertyWrappers/AppState.swift rename to Sources/AppState/PropertyWrappers/State/AppState.swift diff --git a/Sources/AppState/PropertyWrappers/SecureState.swift b/Sources/AppState/PropertyWrappers/State/SecureState.swift similarity index 100% rename from Sources/AppState/PropertyWrappers/SecureState.swift rename to Sources/AppState/PropertyWrappers/State/SecureState.swift diff --git a/Sources/AppState/PropertyWrappers/StoredState.swift b/Sources/AppState/PropertyWrappers/State/StoredState.swift similarity index 100% rename from Sources/AppState/PropertyWrappers/StoredState.swift rename to Sources/AppState/PropertyWrappers/State/StoredState.swift diff --git a/Sources/AppState/PropertyWrappers/SyncState.swift b/Sources/AppState/PropertyWrappers/State/SyncState.swift similarity index 100% rename from Sources/AppState/PropertyWrappers/SyncState.swift rename to Sources/AppState/PropertyWrappers/State/SyncState.swift