Comments (5)
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.
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.
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.
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.
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)
- Proper usage of shared to avoid memory cycles HOT 5
- Generated Code doesn't work with package specification
- Getting double results HOT 4
- How to resolve dependency cycle? HOT 2
- Failed to read source paths from list file at iOS HOT 1
- Very high compile times in release mode for our largest app
- How to pass values in Views in SwiftUI HOT 2
- Needle's parsing of Component's properties is going "too deep"
- Runtime error with "properly generated needle code" HOT 2
- Improve Optional Dependencies HOT 3
- Internal properties of Components should be ignored
- Needle Cocoapods spec is outdated
- Needle Usage for Integration testing
- SPM product 'NeedleFoundation' required by package 'xxx' target 'xxx' not found. HOT 1
- public properties HOT 3
- Apple M1: "Some dependencies are missing" HOT 2
- Sample MVVM project is not compiling HOT 1
- The property is not passed from the parent to the child HOT 1
- Showing Recent Issues 💩 Some dependencies are missing, please look at the warnings above for the list.
- needle generate malfunctioning HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from needle.