ScopedValue: Capturing current bindings
Attila Kelemen
attila.kelemen85 at gmail.com
Tue May 23 16:33:42 UTC 2023
Holo The Sage Wolf <holo3146 at gmail.com> ezt írta (időpont: 2023. máj.
23., K, 16:37):
>
> What you are trying to do is possible to implement, albeit a bit convoluted and wasteful.
>
> Ignoring all of the details, conceptually ScopedValues are made out of 2 parts:
>
> - The instances
> - The bindings
>
> You create instances, bind them to values, and run some code under the spe cific bindings.
>
> So to get the functionality you are looking for you need to wrap the SV instances with your own object "AwareScopedValue", ASV will hold onto a list of SV, when you bind a new value you can either override the top SV, or create a new SV and put it on the top of the stack.
>
> When binding a ASV you simply bind all of the SV.
>
> When trying to get value from it, you can choose from which layer to take.
I don't think what you are describing is possible, because I don't
know all the scoped value bindings available (that is, it is unknown
to the DI framework).
>
> But I'm not sure you really need this functionality, having a public SV is just begging for problems so *any* use of SV should be transparent to the user, and inside of your own library/framework you can make sure that are no double-bindings, and if you need several layers of bindings, then your use case is not what a single SV is meant to handle.
>
I don't need a public SV of course. I don't know what exactly you are
referring to. Also, it is possible to handle it I believe with a
single SV. Either I would create a linked list of the layers of
bindings, or I just copy the underlying map with updated entries
(which is actually possible to do in O(1) with appropriate map
implementation).
More information about the loom-dev
mailing list