ReSwift/ReSwift

add to docs: Instructions on how to clear the ReSwift state.

オープン

#367 opened on 2018/07/25

 (6 件のコメント) (1 件のリアクション) (0 人の担当者)Swift (522 件のフォーク)batch import
Good First IssueHelp Wanted

Repository metrics

Stars
 (7,603 個のスター)
PR merge metrics
 (30d に merged PR はありません)

説明

Took me 10 minutes to figure this out, actually, I just had forgotten to call store.dispatch(ClearStore()). I am sleepy, for my defense.

I thought this would help beginners with this lib. Maybe add it to the docs or somewhere? At least with this issue it can be found via search engines.

In your StoresReducer.swift file, add another case.

func storesReducer(action: Action, state: AppState?) -> AppState {
    // if no state has been provided, create the default state
    var state = state ?? AppState()
    switch action {
    case _ as ClearStore:
        state = AppState() // creates a new AppState, like 3 lines earlier
     // [..]
    default:
        break
    }

    return state

To your Actions.swift, add an empty Action:

struct ClearStore: Action { }

Finally, inside your clearing function (Maybe an Action for a debug button) add

store.dispatch(ClearStore())

If your views subscribe to store changes, the view should immediately behave how an initial installation of your app would.

コントリビューターガイド