Skip to content

Commit

Permalink
Stores Huge Refactoring (#82)
Browse files Browse the repository at this point in the history
* refactoring

* refactor

* refactored store into anystore

* refactoring

* refactoring

* refactoring

* refactoring

* refactored tests

* refactoring

* refactoring

* store reference refactoring

* refactoring

* refactoring

* refactoring

* Breaking changes docs
  • Loading branch information
KazaiMazai authored Sep 5, 2024
1 parent 75ece80 commit 172149b
Show file tree
Hide file tree
Showing 28 changed files with 465 additions and 579 deletions.
20 changes: 20 additions & 0 deletions Docs/Migration-Guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@
* [PureduxUIKit Bindings Migration Guide](#pureduxuikit-bindings-migration-guide)


## Puredux 1.9.x - 2.0

## Store breaking changes

`Store<State, Action>` was renamed to `AnyStoreStore<State, Action>`

```diff
- Store<State, Action>
+ AnyStore<State, Action>

```

`StoreProtocol<State, Action>` was renamed to `Store<State, Action>`

```diff
- any StoreProtocol<State, Action>
+ any Store<State, Action>

```

## Getting Prepared for Puredux 2.0

1. Update for the latest 1.x version
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ https://github.com/KazaiMazai/Puredux

## Documentation

- [Documentation v.1.9.0](https://swiftpackageindex.com/KazaiMazai/Puredux/1.9.0/documentation/puredux)
- [Documentation v1.9.x](https://swiftpackageindex.com/KazaiMazai/Puredux/1.9.2/documentation/puredux)
- [Archive](https://github.com/KazaiMazai/Puredux/blob/main/Docs/Archive)
- [Migration Guides](https://github.com/KazaiMazai/Puredux/blob/main/Docs/Migration-Guides.md)

Expand Down
20 changes: 10 additions & 10 deletions Sources/Puredux/SideEffects/SideEffects.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import Dispatch
import Foundation

extension StoreProtocol {
extension Store {
typealias CreateForEachEffect = (State, Effect.State) -> Effect
typealias CreateEffect = (State, @escaping Dispatch<Action>) -> Effect
}

extension StoreProtocol {
extension Store {

@discardableResult
func effect(on queue: DispatchQueue = .main,
Expand Down Expand Up @@ -54,7 +54,7 @@ extension StoreProtocol {
}
}

extension StoreProtocol {
extension Store {
@discardableResult
func forEachEffect<Effects>(_ keyPath: KeyPath<State, Effects>,
on queue: DispatchQueue = .main,
Expand All @@ -67,7 +67,7 @@ extension StoreProtocol {
let weakStore = weakStore()

subscribe(observer: Observer(
weakStore.getStoreObject(),
storeObject(),
removeStateDuplicates: .keyPath(keyPath)) { [effectOperator] state, prevState, complete in

let allEffects = state[keyPath: keyPath]
Expand All @@ -91,7 +91,7 @@ extension StoreProtocol {
let weakStore = weakStore()

subscribe(observer: Observer(
weakStore.getStoreObject(),
storeObject(),
removeStateDuplicates: .keyPath(keyPath)) { [effectOperator] state, prevState, complete in

let effect = state[keyPath: keyPath]
Expand All @@ -116,7 +116,7 @@ extension StoreProtocol {
let weakStore = weakStore()

subscribe(observer: Observer(
weakStore.getStoreObject(),
storeObject(),
removeStateDuplicates: .keyPath(keyPath)) { [effectOperator] state, prevState, complete in
let effect: Effect.State = prevState == nil ? .idle() : .running()
effectOperator.run(effect, on: queue) { _ in
Expand All @@ -139,7 +139,7 @@ extension StoreProtocol {
let weakStore = weakStore()

subscribe(observer: Observer(
weakStore.getStoreObject(),
storeObject(),
removeStateDuplicates: .keyPath(keyPath)) { [effectOperator] state, prevState, complete in
let isRunning = state[keyPath: keyPath]
effectOperator.run(isRunning, on: queue) { _ in
Expand All @@ -163,7 +163,7 @@ extension StoreProtocol {
let weakStore = weakStore()

subscribe(observer: Observer(
weakStore.getStoreObject(),
storeObject(),
removeStateDuplicates: removeStateDuplicates) { [effectOperator] state, prevState, complete in
effectOperator.run(.running(delay: timeInterval), on: queue) { _ in
create(state, weakStore.dispatch)
Expand All @@ -177,7 +177,7 @@ extension StoreProtocol {
}
}

extension StoreProtocol {
extension Store {

@discardableResult
func effect(_ cancellable: AnyCancellableEffect,
Expand Down Expand Up @@ -214,7 +214,7 @@ extension StoreProtocol {
}
}

extension StoreProtocol {
extension Store {
@discardableResult
func forEachEffect<Effects>(_ cancellable: AnyCancellableEffect,
_ keyPath: KeyPath<State, Effects>,
Expand Down
Loading

0 comments on commit 172149b

Please sign in to comment.