Hi! I'm trying to figure out how to don't provide value at all by a some condition. F.e I have shared scope that I link to another. In my VM I have a nullable property. On one condition i want to provide value and in another one I wouldn't. I need to pass some value in the scopeю Before that I created new module every time with a function. In this func I passed my value, f.e value: T? and checked it for null. Code looks like if (value != null) scoped { smth }. Then it doesn't appears in the scope and I get null when retrieve VM as expected. But as I understand, it would be better to have one singleton module and do not create new one with a function every time. How can I solve it?
c
curioustechizen
06/26/2023, 2:33 PM
This is not an answer to your question; but I suggest to try to formulate your question in a different way, with some minimal code/pseudocode.
The way it is written right now, it is very hard to follow what you have and what you're trying to achieve.
m
Merseyside
06/26/2023, 3:01 PM
Ok, I have few screens, I navigate to them and pass some id. This id could be null. If this id is null, then I don't want to create instance, lets call it A, that gets to pass in my ViewModel. I get it with getOrNull() koin function. Providing logic of instance A in the shared scope, which links to the fragment's scopes. Also I load module with shared scope by using loadKoinModules() function when I navigate to the screen. Than I did smth like loadKoinModules(getMySharedScope(ID)). In this function I wrote smth like if (id != null) scoped<A>().
Merseyside
06/27/2023, 7:01 AM
Now I tried to do scope.declare(Id). Dk why it works like that, but now I can get this Id in every scope, and doesn't matter what scopeId it has.
Merseyside
06/27/2023, 7:05 AM
Also tried with source value, that passed when scope creates. In my case it's fragment. But get() requires real type of source, so I can not get by relative type.