onevcat / swift-ui-book-issue

76 stars 0 forks source link

关于Store.dispatch 函数【在非主线程中修改UI】 的警告 #34

Closed Jooc closed 4 years ago

Jooc commented 4 years ago
    func dispatch(_ action: AppAction) {
        #if DEBUG
        print("[ACTION]: \(action)")
        #endif
        let result = Store.reduce(state: appState, action: action)
        appState = result.0
        if let command = result.1 {
            #if DEBUG
            print("[COMMAND]: \(command)")
            #endif
            command.execute(in: self)
        }
    }

以上代码是原书示例PokemonMaster 中Storedispatch 函数

但是在加载Pokemons 的LoadPokemonsCommand对应的excute() 函数里明明有通过sink 的回调闭包调用了该dispatch 函数

请问为什么appState = result.0 在运行时并没有出现“在非主线程中修改UI”的错误呢? (我自己尝试时出现了该警告

是我忽略了什么细节吗?

Jooc commented 4 years ago

Store 中的dispatch() 函数是static 函数,打扰了