Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Filter on updates not working #501

Open
@sarensw

Description

@sarensw

Hi All, given the following class that inherits fromStoreSubscriber, I'm trying to subscribe only to a sub-state. But even if another sub-state is updated, then this subscriber is notified about an update.

classPortWindowService:StoreSubscriber{typealiasStoreSubscriberStateType=ModelStatefunc start(){        store.subscribe(self){ $0.select{ $0.modelState}}}deinit{        store.unsubscribe(self)}func newState(state:ModelState){print(state.ports.count)print("ports changed")}}

My app state is:

structAppState{varmodelState:ModelState=ModelState()varvolumeState:VolumeState=VolumeState()}structModelState{varmodel:StoredModel?=nilvarports:[Port]=[]}structVolumeState{varvolumes:[VolumeInfo]=[]}

And my reducers are:

func appReducer(action:Action, state:AppState?)->AppState{returnAppState(        modelState:modelReducer(action: action, state: state?.modelState),        volumeState:volumeReducer(action: action, state: state?.volumeState))}func modelReducer(action:Action, state:ModelState?)->ModelState{varstate= state??ModelState()switch action{caseletaction asSetModel:        state.model= action.model        state.model?.usbPortsLeft.enumerated().forEach{(index, portNumber)in            state.ports.append(Port(portNumber: portNumber, state:.unknown, area:.left))}        state.model?.usbPortsRight.enumerated().forEach{(index, portNumber)in            state.ports.append(Port(portNumber: portNumber, state:.unknown, area:.right))}        state.model?.usbPortsBack.enumerated().forEach{(index, portNumber)in            state.ports.append(Port(portNumber: portNumber, state:.unknown, area:.back))}default:break}return state}func volumeReducer(action:Action, state:VolumeState?)->VolumeState{varstate= state??VolumeState()switch action{caseletaction asAddVolume:iflet volumeInfo= action.volume{            state.volumes.append(volumeInfo)}caseletaction asRemoveVolume:iflet basePath= action.basePath{            state.volumes.removeAll(where:{ $0.volumePath== basePath})}default:break}return state}

TheSetModel action is only called twice during startup. So I assume that "ports changed" is only printed twice (seefunc newState in thePortWindowService class). But even when the actionsAddVolume orRemoveVolume are called in a different reducer, in a different sub-state, which is not selected during subscription in theStoreSubscriber initialization, I'll get an event andnewState is called.

What am I missing here? How can I make sure that withstore.subscribe(self) { $0.select { $0.modelState } }newState is only called when anything inmodelState changes, but not involumeState?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp