GithubHelp home page GithubHelp logo

Comments (2)

mluisbrown avatar mluisbrown commented on May 3, 2024

I'm noticing that the ifLet call on the store is called multiple times.

Do you mean that the then: closure is being called multiple times, causing your view controller to be presented multiple times?

When each modal is dismissed are you making sure, in your reducer, that the state for the modal (eg items or favourites) is reset to nil?

The "fix" is to use skipRepeats() instead of .skipRepeats { ($0 != nil) == ($1 != nil) }.

The { ($0 != nil) == ($1 != nil) } comparison test (instead of using the default ==) is to test for changes from nil to non-nil and vice-versa, which is what is needed for ifLet, otherwise any change in the state whilst it's non-nil would also cause the then: closure to be called, which is not what we want.

FWIW I'm using ifLet in my work project and have not run into the problem that you describe.

from reactiveswift-composable-architecture.

joshhaines avatar joshhaines commented on May 3, 2024

Thanks for the response! I think I found my issue. I was doing store.ifLet within viewStore.produced.activeRoute.startWithValues. I didn't realize that store.ifLet was creating new subscriptions to the store each time.

viewStore.produced.activeRoute.startWithValues { [weak self] route in
  switch route {
  ...
  case .favorites:
      let store = self.store.scope(state: \.favorites, action: Root.Action.favorites)
          store.ifLet { [weak self] store in
              guard let self = self else { return }
              let vc = FavoritesViewController(store: store)
              let nc = UINavigationController(rootViewController: vc)
              nc.presentationController?.delegate = self
              self.present(nc, animated: true, completion: nil)
          }
    }
}

So every time I got a new route I was attempting to unwrap the optional store, not realizing that the previously unwrapped store subscription was still hanging around. So the previous ifLet block was still getting called.

I think the wording on ifLet makes it seem as if you are doing an in-place unwrap once, but in reality you are creating a new subscription to an observable. I know the wording is inherited from the Point-Free repo, so I guess I can bring that concern up there. I'll close this issue. Thanks again!

from reactiveswift-composable-architecture.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.