StateReader
to read the state partially.Verge provides 2 ways to create a store.
StoreComponentType
- It’s a protocol that indicates the class wraps a store inside and behaves like a store.Store
- a most basic way, but we need to define State and Activity outsideNow, we recommend using No.1 in order to manage the source code with better portability.
StoreComponentType
final class MyStore: StoreComponentType {
struct State: StateType {
var count: Int = 0
}
/// This means wrapping store inside. (Probably it should be renamed as like `innerStore` or `wrappedStore`)
/// `DefaultStore` is a typealias that declared by `StoreComponentType`.
/// You can use any class that inherited from `Store` for your use-cases.
let store: DefaultStore
init() {
self.store = .init(initialState: .init())
}
}
extension MyStore {
func increment() {
commit {
$0.count += 0
}
}
}
let store = MyStore()
store.increment()
Store
struct State: StateType {
var count: Int = 0
}
enum Activity {
case happen
}
final class MyStore: Store<State, Never> {
init() {
super.init(
initialState: .init(),
logger: DefaultStoreLogger.shared
)
}
}
extension MyStore {
func increment() {
commit {
$0.count += 0
}
}
}
let store = MyStore()
store.increment()