I’m converting my app from Ionic v3. In v3, we were able to set a set of parameters to be sent to a tab from its parent with the rootParams property. It seems this isn’t possible anymore in the latest version. What is the preferred way of sending parameters to a tab? I want to send multiple values, not just one using the router url method. I want to send multiple values of any type (especially callback methods). I’ve seen some people suggest local storage. Others suggest using event publishing. But these solutions are hacky. What should I do?
If you wish, while you wait for better answers, convince me that this is a good idea, because it sounds like a recipe for action-at-a-distance spaghetti.
When a component accepts callback parameters, it becomes astronomically harder to test, isolate and diagnose, as you’ve totally broken isolation. You can’t look just at the component and define what it does, because you would need to know all the sorts of callbacks that might be coming in, and what other side effects they have.
I limit all my component interaction points to two types:
@Outputbindings, which are strictly defined and documented points of ingress and egress - they can be checked for sanity and tested considering only the code inside the component.
Injectable service providers. This flavor of interaction puts the component squarely in charge of saying what it wants, in what format, and when. It’s not dependent on anything outside what the component declares it’s dependent on. The service can be mocked out during testing.
I have found that allowing myself to expose any other methods of cross-component interaction leaves me with a tangled mess of unmaintainable code, and I’ve totally thrown out several early designs written as I was adjusting to life in webappland for exactly this reason.
Thanks for the response. I agree with everything you said. My code in this section of the app gets pretty messy. I’ve actually rarely used @Input and @Output but they seem very helpful in this situation. It looks like I’ll be going with that implementation. Thanks a bunch!