Skip to content

Releases: 0xOpenBytes/CacheStore

2.2.0

19 May 01:38
0d05a3e

Choose a tag to compare

Unidirectional data flow for Store

What's Changed

Full Changelog: 2.1.1...2.2.0

2.1.1

18 May 01:49
fb0ee51

Choose a tag to compare

What's Changed

  • Fix Binding functions for Store by @0xLeif in #7

Full Changelog: 2.1.0...2.1.1

2.1.0

17 May 23:50
5b60bfc

Choose a tag to compare

Added

  • contains: Checks if the given key has a value or not
  • require: Checks to make sure the cache has the required keys, otherwise it will throw an error
  • valuesInCache: Returns a Dictionary containing only the key value pairs where the value is the same type as the generic type Value

What's Changed

Full Changelog: 2.0.0...2.1.0

2.0.0

15 May 16:17
55eeb16

Choose a tag to compare

Added

  • Store
  • ScopedStore
  • ActionHandler
  • CacheStore update

Store

A Store is an object that you send actions to and read state from. Stores use a private CacheStore to manage state behind the scenes. All state changes must be defined in a StoreActionHandler where the state gets modified depending on an action.

Basic Store Example

Here is a basic Store example where this is a Boolean variable called isOn. The only way you can modify that variable is be using defined actions for the given store. In this example there is only one action, toggle.

enum StoreKey {
    case isOn
}

enum Action {
    case toggle
}

let actionHandler = StoreActionHandler<StoreKey, Action, Void> { (store: inout CacheStore<StoreKey>, action: Action, _: Void) in
    switch action {
    case .toggle:
        store.update(.isOn, as: Bool.self, updater: { $0?.toggle() })
    }
}

let store = Store<StoreKey, Action, Void>(
    initialValues: [.isOn: false],
    actionHandler: actionHandler,
    dependency: ()
)

try t.assert(store.get(.isOn), isEqualTo: false)

store.handle(action: .toggle)

try t.assert(store.get(.isOn), isEqualTo: true)

What's Changed

Full Changelog: 1.3.0...2.0.0

1.3.0

14 May 22:29
d1ff424

Choose a tag to compare

What's Changed

Full Changelog: 1.2.0...1.3.0

1.2.0

07 May 21:05
b2e7825

Choose a tag to compare

What's Changed

  • Feature/binding and publishers by @0xLeif in #2

Full Changelog: 1.1.0...1.2.0

1.1.0

06 May 20:35
7d88695

Choose a tag to compare

What's Changed

Full Changelog: 1.0.1...1.1.0

1.0.1

03 May 23:00

Choose a tag to compare

CacheStore

SwiftUI Observable Cache

What is CacheStore?

CacheStore is a SwiftUI framework to help with state. Define keyed values that you can share locally or globally in your projects. CacheStore uses c, which a simple composition framework. c has the ability to create transformations that are either unidirectional or bidirectional. There is also a cache that values can be set and resolved, which is used in CacheStore.

Basic Example

Here is a simple application that has two files, an App file and ContentView file. The App contains the StateObject CacheStore. It then adds the CacheStore to the global cache using c. ContentView can then resolve the cache as an ObservableObject which can read or write to the cache. The cache can be injected into the ContentView directly, see ContentView_Previews, or indirectly, see ContentView.

DemoApp

import c
import CacheStore
import SwiftUI

enum CacheKey: Hashable {
    case someValue
}

@main
struct DemoApp: App {
    @StateObject var cacheStore = CacheStore<CacheKey>(
        initialValues: [.someValue: "🥳"]
    )
    
    var body: some Scene {
        c.set(value: cacheStore, forKey: "CacheStore")
        
        return WindowGroup {
            VStack {
                Text("@StateObject value: \(cacheStore.resolve(.someValue) as String)")
                ContentView()
            }
        }
    }
}

ContentView

import c
import CacheStore
import SwiftUI

struct ContentView: View {
    @ObservedObject var cacheStore: CacheStore<CacheKey> = c.resolve("CacheStore")
    
    var stringValue: String {
        cacheStore.resolve(.someValue)
    }
    
    var body: some View {
        VStack {
            Text("Current Value: \(stringValue)")
            Button("Update Value") {
                cacheStore.set(value: ":D", forKey: .someValue)
            }
        }
        .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView(
            cacheStore: CacheStore(
                initialValues: [.someValue: "Preview Cache Value"]
            )
        )
    }
}

Full Changelog: 1.0.0...1.0.1

1.0.0

01 May 00:04
480164c

Choose a tag to compare

CacheStore

SwiftUI Observable Cache

What is CacheStore?

CacheStore is a SwiftUI framework to help with state. Define keyed values that you can share locally or globally in your projects. CacheStore uses c, which a simple composition framework. c has the ability to create transformations that are either unidirectional or bidirectional. There is also a cache that values can be set and resolved, which is used in CacheStore.

Basic Example

Here is a simple application that has two files, an App file and ContentView file. The App contains the StateObject CacheStore. It then adds the CacheStore to the global cache using c. ContentView can then resolve the cache as an ObservableObject which can read or write to the cache. The cache can be injected into the ContentView directly, see ContentView_Previews, or indirectly, see ContentView.

DemoApp

import c
import CacheStore
import SwiftUI

enum CacheKey: Hashable {
    case someValue
}

@main
struct DemoApp: App {
    @StateObject var cacheStore = CacheStore<CacheKey>(
        initialValues: [.someValue: "🥳"]
    )
    
    var body: some Scene {
        c.set(value: cacheStore, forKey: "CacheStore")
        
        return WindowGroup {
            VStack {
                Text("@StateObject value: \(cacheStore.resolve(.someValue) as String)")
                ContentView()
            }
        }
    }
}

ContentView

import c
import CacheStore
import SwiftUI

struct ContentView: View {
    @ObservedObject var cacheStore: CacheStore<CacheKey> = c.resolve("CacheStore")
    
    var stringValue: String {
        cacheStore.resolve(.someValue)
    }
    
    var body: some View {
        VStack {
            Text("Current Value: \(stringValue)")
            Button("Update Value") {
                cacheStore.set(value: ":D", forKey: .someValue)
            }
        }
        .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView(
            cacheStore: CacheStore(
                initialValues: [.someValue: "Preview Cache Value"]
            )
        )
    }
}

Full Changelog: https://github.com/0xOpenBytes/CacheStore/commits/1.0.0