Skip to content

Commit

Permalink
Getting Prepared for Migration to v2.0 docs (#70)
Browse files Browse the repository at this point in the history
* updated docs

* updated migration docs

* updated migration docs

* moved to dif

* docs update
  • Loading branch information
KazaiMazai authored Sep 3, 2024
1 parent a686b4a commit bdd30a8
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 22 deletions.
File renamed without changes.
180 changes: 178 additions & 2 deletions Docs/Migration-Guides.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,182 @@
## Table Of Contents

## Puredux legacy to a single repository migration guide
- [Getting Prepared for Puredux 2.0](#getting-prepared-for-puredux-20)
* [StoreFactory Changes](#storefactory-changes)
* [Child Store Changes](#child-store-changes)
* [Scope Store Tranformation Changes](#scope-store-tranformation-changes)
* [SwiftUI Bindings Changes](#swiftui-bindings-changes)
* [UIKit Bindings changes](#uikit-bindings-changes)
- [Puredux 1.2.0 - 1.3.0 Minor breaking changes](#puredux-120---130-minor-breaking-changes)
* [Referenced StoreObject](#referenced-storeobject)
* [StoreObject constructor](#storeobject-constructor)
- [Puredux 1.2.0: From legacy multirepo to a single repository](#puredux-120--from-legacy-multirepo-to-a-single-repository)
* [1. Change the package:](#1-change-the-package-)
* [2. Fix imports:](#2-fix-imports-)
- [Puredux 1.0.x - 1.1.x Update](#puredux-10x---11x-update)
* [Store migration](#store-migration)
+ [1. Migrate From `RootStore` to `StoreFactory`:](#1-migrate-from--rootstore--to--storefactory--)
+ [2. Update actions interceptor and pass in to store factory:](#2-update-actions-interceptor-and-pass-in-to-store-factory-)
+ [3. Migrate from `proxy(...)` to `scope(...)`:](#3-migrate-from--proxy----to--scope----)
* [PureduxSwiftUI Bindings Migration Guide](#pureduxswiftui-bindings-migration-guide)
* [PureduxUIKit Bindings Migration Guide](#pureduxuikit-bindings-migration-guide)


## Getting Prepared for Puredux 2.0

1. Update for the latest 1.x version
2. Follow deprecation notices to get prepared for smooth migration

Here is an overview of what to be changed:

### StoreFactory Changes

1. Replace `StoreFactory` with `StateStore`.

```swift
// Before:

let storeFactory = StoreFactory(
MyInitialState(),
qos: .userInteractive,
reducer: myReducer
)

// After:

let store = StateStore(
MyInitialState(),
qos: .userInteractive,
reducer: myReducer
)
```

### Child Store Changes

```diff
- let childStore: StateStore<(AppState, LocalState), Action> = storeFactory.childStore(
- initialState: LocalState(),
- reducer: { localState, action in
- localState.reduce(action: action)
- }
- )


+ let childStore: StateStore<(AppState, LocalState), Action> = rootStore.with(
+ LocalState(),
+ reducer: { localState, action in
+ localState.reduce(action: action)
+ }
+ )

```

### Scope Store Tranformation Changes

```diff
- let scopeStore = storeFactory.scopeStore { appState in appState.subState }

+ let scopeStore = rootStore.map { appState in appState.subState }

```

Follow deprecation notices documentation for more details.

### SwiftUI Bindings Changes

Puredux 2.0 bind Stores with Views differently.
`StoreView` is a replacement for `ViewWithStore` provided to make the migration process easier.

1. Migrate from `StoreFactory` and `EnvStoreFactory` to `StateStore`
2. Inject root store with `@InjectEntry`:

```swift

extension Injected {
@InjectEntry var appState = StateStore<AppState, Action>(AppState()) { state, action in
state.reduce(action)
}
}

```

3. Wrap your `FancyView` in a container view with a`@State` store of a proper configuration
4. Depending on how `ViewWithStore` was condigured:
- `EnvStoreFactory` and an implicit single app store should use explicit `@StoreOf(\.appState)` store.
- `ViewWithStore(...).childStore(...)` should use `@StoreOf(\.appState).with(ChildState()) { ... }`
- `ViewWithStore(...).scopeStore(...)` should use `@StoreOf(\.appState).map { ... }`
- `ViewWithStore(...).store(...)` should use explicit `Store(...)` or `StateStore(...)`
5. Replace `ViewWithStore` with a `StoreView`

Follow deprecation notices documentation for more details.

### UIKit Bindings changes

The Presentable API is still available, so only minor changes are needed.

1. Replace deprecated methods:

```diff

- myViewController.with(
- store: store,
- props: { state, store in
- // ...
- },
- presentationQueue: .sharedPresentationQueue,
- removeStateDuplicates: .keyPath(\.lastUpdated)
- )

+ myViewController.setPresenter(
+ store: store,
+ props: { state, store in
+ // ...
+ },
+ presentationQueue: .sharedPresentationQueue,
+ removeStateDuplicates: .keyPath(\.lastUpdated)
+ )

```

Follow deprecation notices documentation for more details.

## Puredux 1.2.0 - 1.3.0 Minor breaking changes

There are a few breaking changes related to the replacement of StoreObject with a StateStore.

### Referenced StoreObject
StoreObject used to be a class, StateStore is a struct.

StoreObject that were weakly referenced wll require a fix.
Since is StoreObjectnow a typealias of StateStore the compiler will point you to all the places that require a fix:

```diff
- let storeObject: StoreObject = ....

- doSomethingWithStore() { [weak storeObject] in
- storeObject?.dispatch(...)
- }

+ let stateStore: StateStore = ....
+ let store = stateStore.store()
+ doSomethingWithStore() {
+ store.dispatch(...)
+ }
```

### StoreObject constructor

The following StoreObject's constructor is no longer available. It was not needed except for the cases when you wanted to mock your StoreObject.

It can be fixed by replacing StoreObject with a Store
```diff
- StoreObject(dispatch: { ... }, subscribe: { ... })
+ Store(dispatch: { ... }, subscribe: { ... })
```




## Puredux 1.2.0: From legacy multirepo to a single repository

Puredux was refactored from a set of packages to a single monorepository.

Expand Down Expand Up @@ -251,7 +428,6 @@ ViewWithStore(props: presenter.makeProps) {

```


### PureduxUIKit Bindings Migration Guide

Nothing needs to be changed.
43 changes: 23 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ streamline state management with a focus on unidirectional data flow and separat

## Table of Contents

* [Getting Started](#getting-started)
+ [Basics](#basics)
+ [Store Definitions](#store-definitions)
+ [UI Bindings](#ui-bindings)
* [Hierarchical Stores Tree Architecture](#hierarchical-stores-tree-architecture)
* [Side Effects](#side-effects)
+ [Async Actions](#async-actions)
* [Performance Tuning](#performance-tuning)
+ [Quality of Service](#quality-of-service)
+ [Deduplicated State Updates](#deduplicated-state-updates)
+ [UI Updates Debouncing](#ui-updates-debouncing)
+ [Extra Presentational Layer](#extra-presentational-layer)
* [Installation](#installation)
+ [Swift Package Manager.](#swift-package-manager)
* [Migration Guiges](#migration-guiges)
- [Getting Started](#getting-started)
* [Basics](#basics)
* [Store Definitions](#store-definitions)
* [UI Bindings](#ui-bindings)
- [Hierarchical Stores Tree Architecture](#hierarchical-stores-tree-architecture)
- [Side Effects](#side-effects)
* [Async Actions](#async-actions)
- [Performance Tuning](#performance-tuning)
* [Quality of Service](#quality-of-service)
* [Deduplicated State Updates](#deduplicated-state-updates)
* [UI Updates Debouncing](#ui-updates-debouncing)
* [Extra Presentational Layer](#extra-presentational-layer)
- [Installation](#installation)
* [Swift Package Manager.](#swift-package-manager)
- [Documentation](#documentation)
- [Migration Guiges](#migration-guiges)
- [Licensing](#licensing)


## Getting Started

### Basics
Expand Down Expand Up @@ -453,13 +453,16 @@ To install it, in Xcode 11.0 or later select File > Swift Packages > Add Package
```
https://github.com/KazaiMazai/Puredux
```

## Migration Guiges

- [Migration Guides](Docs/Migration-Guides.md)
## Documentation

- [Archive](https://github.com/KazaiMazai/Puredux/blob/main/Docs/Archive)

## Migration Guiges

- [Migration Guides](https://github.com/KazaiMazai/Puredux/blob/main/Docs/Migration-Guides.md)

# Licensing
## Licensing

Puredux and all its modules are licensed under MIT license.

Expand Down

0 comments on commit bdd30a8

Please sign in to comment.