GithubHelp home page GithubHelp logo

Comments (5)

rudro avatar rudro commented on August 15, 2024

We use RxSwift heavily so my Combine API calls may be a bit off. I think the setup in the Child seems fine to me I ignore the one of type Int. Let's focus on the aStream var. That seems good. So the parent creates a subset and the child get's access to it using Needle. So in the parent I would have expected to see something like :

    var aStreamSetupByParent: AnyPublisher<Int, Never> { // note: type must match what is asked for by the child dependency protocol
          return shared { PassthroughSubject<CGPoint, Never>().eraseToAnyPublisher() } // note: the shared makes it so you get the same instance each time you access the var
  }

from needle.

rudro avatar rudro commented on August 15, 2024

Also, it's a bit confusing, but streams are not considered "dynamic" dependencies as the instances of the streams are known at compile time. "Dynamic" dependencies are say a passcode the user types in and then you would pass that Int into the constructor of a component class.

from needle.

aurelienp avatar aurelienp commented on August 15, 2024

If I understand correctly, you are saying that the pattern of forwarding to myVC in MyComponent.aStreamSetupByParent is not correct. Instead, components should be in charge of creating the instances.

I guess this also means you encourage injecting such streams in MyVC.init? But doesn't that force us to change MyVC implementation, hence breaking the promise that Needle will not interfere with code that is outside of Component?

Also, it's a bit confusing, but streams are not considered "dynamic" dependencies as the instances of the streams are known at compile time.

Sorry if my message was confusing. The code I shared was to illustrate the infinite-loop issue, hence does not rely on dynamic dependency. Could you follow the trace after the call to aChildVCBuilder.myChildVC and see how it end up in an infinite loop (because shared relies on a recursive lock I guess).

from needle.

rudro avatar rudro commented on August 15, 2024

Right, the stream instance should be created at the parent. e.g here https://github.com/uber/needle/blob/master/Sample/MVC/TicTacToe/Sources/Root/RootComponent.swift#L27.

Then a child VC will ask for this stream and constructor inject it (into the VC) as seen in this file: https://github.com/uber/needle/blob/master/Sample/MVC/TicTacToe/Sources/ScoreSheet/ScoreSheetComponent.swift

I'm not sure I understand why this breaks the promise Needle will interfere with code outside of the Component.

from needle.

aurelienp avatar aurelienp commented on August 15, 2024

I'm not sure I understand why this breaks the promise Needle will interfere with code outside of the Component.

You're right, indeed. It seems arbitrary to say that when it comes to injecting streams rather than injecting other sort of things such as VC builders.

It just seems somewhat unnatural to me that so much ends up being injected in a VC, just because a VC lower in the hierarchy depends on something. But that's a matter of habit and nothing wrong with this from a theoretical point of view. Needle is encouraging to be a DI maximalist :)

Thanks for all the replies. I'll mark as resolved.

from needle.

Related Issues (20)

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.