How can I somehow combine EventCallback<T>?

S

Sinaesthetic

Guest
Sinaesthetic Asks: How can I somehow combine EventCallback<T>?
So I found myself in a situation where I need to subclass a few Blazor components, but one of the reasons is that I need to essentially create a decorator that extends it's functionality. Part of that extension is to tack on some additional event handling. Since components use EventCallback now which isn't a delegate time, I can't simply add another handler to it like you could with multicast delegates. I can replace it, but then that means any consumer of that component cannot register any handler of their own, so now I'm trying to wrap it. Here's a pseudo representation of the scenario and what I'm trying to do

Code:
public class OriginalBlazorComponent : ComponentBase
{
    [Parameter]
    public EventCallback<int> SomethingChanged { get; set; }

    private async Task SomeInternalProcess()
    {
        // ... some work here
        await SomethingChanged.InvokeAsync(1);
    }
}

public class MySubclassedComponent : OriginalBlazorComponent
{
    public override async Task SetParametersAsync(ParameterView parameters)
    {
        // I want to combine anything that the user may have registered with my own handling
        SomethingChanged = EventCallback.Factory.Create(this, async (int i) => 
        {
            // this causes a stack overflow because i just replaced it with this callback
            // so it's essentially calling itself by this point.
            await SomethingChanged.InvokeAsync(i); 

            await DoMyOwnStuff(i);
        });
        
        await base.SetParametersAsync(this);
    }
}

The idea here is that I'm just making sure that the user's handler has been bound by addressing this in SetParametersAsync() so that I can wrap it in a new callback that will call their handler first and then run mine after. But since it's the base component that has the logic which will invoke the EventCallback, that means I need to replace that specific property with my new handler, but in doing so, that means the new handler is calling the old handler which is actually now the new handler, so it's now an infinitely recursive call stack, and causes a stack overflow.

So my first thought was that if I could somehow get a copy of the original EventCallback, or at least extract its delegate so I can create a new callback, then it wouldn't be referencing itself anymore (confused because it's a struct, I thought it would always naturally be a copy), but I can't find any way to do that. I tried just using EventCallback.Factory.Create(this, SomethingChanged) in hopes that it would create a completely new instance of the callback using the same delegate, but it didn't change anything; same result.

This would of course be a non-issue if I could override the original component's SomeInternalProcess() method so that I could insert my process there before or after calling the base method, but it's a 3rd party library.

So in short, is there some way to achieve the same effect as a multicast delegate so that I can preserve any registered handlers but combine with my own? Or is there at least some way dereference the original EventCallback or extract its delegate so that I can create a new one?

e.g.

Code:
// how do I acheive something akin to
SomethingChanged += MyDelegate;

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.
 

Unreplied Threads

How to perform feature engineering on columns with multiple categories?

Prateek Coder Asks: How to perform feature engineering on columns with multiple categories?
I want to perform feature engineering on a data that mostly contains textual data and lot of columns with multiple categories like Supervisor, location code, employee class, business unit, job title, etc. What should be the best approach to do this? I have binary encoded the column with 2-3 categories or performed one hot encoding, but these columns contains different categories from 8 to 150. Different location will play major role in prediction, so will the employee class or business unit etc and I believe they will be very important for my model.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

[Solved] Create Buffer but keep original Attribute table

J.Beer Asks: Create Buffer but keep original Attribute table
I want to create a buffer around a number of features. It is important for me to keep the attributes of the features in the new buffer.shp layer. When I try to write a new VectorLayer with a QgsVectorFileWriter, I do get the buffered polygons and also the fields of the original layer get copied over, however the attribute table stays empty.

How can I copy over the attributes of the original layer to the buffer layer?

As you can see I already tried to load the attributes using the . attributes() method on the QgsFeature object and setting the attributes. However I feel I am missing something here.

Code:
for f in feats:
    attributes = f.attributes()
    f.setAttributes(attributes)

See full code below:

Code:
path = '/Volumes/VAW_ETH-Z/M.Thesis/data/geospatial/'

# load filtered sgi
sgi_filtered = QgsVectorLayer(path + 'sgi_filtered.shp')

## Create buffer around filtered sgi
outFn = path + 'gl_buffer3.shp'
bufferDist = 50 # in map units

fields = sgi_filtered.fields()
feats = sgi_filtered.getFeatures()

writer = QgsVectorFileWriter(
            outFn,
            'utf-8',
            fields,
            QgsWkbTypes.Polygon,
            sgi_filtered.sourceCrs(), # loads the reference system of the source feature
            'ESRI Shapefile')

for f in feats:
    attributes = f.attributes()
    f.setAttributes(attributes)
    geom = f.geometry()
    buff = geom.buffer(bufferDist, 5)
    f.setGeometry(buff)
    
    writer.addFeature(f)

Screenshot of the Attribute Table below (it shows the fields but no attributes):

Empty Attribute table. The fields are displayed however no attributes have been added.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.

[Solved] Saving a Project Folder as a template (QGIS 3.28)

  • Ben Sear
  • Geography
  • Replies: 0
Ben Sear Asks: Saving a Project Folder as a template (QGIS 3.28)
I am looking to create a template for easy layout integration for new QGIS project files, but when saving the project file to a template using save to > template, the file does not appear in the project templates as a template file, but just a new project file. I read that you need to restart GIS once you saved a project file as a template but restarting does not change the project file to being a template. Has anyone experienced saving template before and have any suggestions? Thank you.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, solveforum.

Method of cooling a gas without liquid evaporation for Sci-fi novel

  • user2765977
  • Chemistry
  • Replies: 0
user2765977 Asks: Method of cooling a gas without liquid evaporation for Sci-fi novel
sorry for the amateur question here.

I know little about science, but regardless am writing a fictional amateur novel that deals with a lot of chemistry stuff, especially gasses.

My protagonist needs a clever method of cooling a gas. He has access to several gasses (CO2, O2, H2, nitrogen) in varying temperatures (70c and up). Unfortunately no water (at least not more than a few bottles). The atmosphere he is working under (planet atmosphere) is in the range of 150c and at a pressure of roughly 150kpa in the novel.

He also has access to sci-fi style manufacturing machines that can simply 'make' parts, like pipes, valves, pumps, that sort of thing.

I am looking for a clever way or really any way at all, that he can use to cool down some O2 to at least under 40c in such a situation.

My amateur reading online suggests the main way, is via liquid evaporation, but I doubt that would work in the above scenario easily.

Does anybody have any ideas? Is this even possible?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

Is there a "fundamental problem of thermodynamics"?

  • agaminon
  • Physics
  • Replies: 0
agaminon Asks: Is there a "fundamental problem of thermodynamics"?
The "fundamental problem of mechanics" can be boiled down to finding and solving the equation of motion of a system. Similar statements can be said for quantum mechanics for the Schrödinger equation and for electrodynamics and Maxwell's equations, etc. But is there such a thing for thermodynamics? Is there a formulation that allows for this kind of perspective?

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

What does this vertical line notation mean?

  • Lambda
  • Physics
  • Replies: 0
Lambda Asks: What does this vertical line notation mean?
Here is the definition of the Noether momentum in my script.

$$I = \left.\frac{\partial L}{\partial \dot{x}} \frac{d x}{d \alpha} \right|_{\alpha=0} = \frac{\partial L}{\partial \dot{x}} = m \dot{x} = p_x.$$ But I don't understand exactly what this vertical line with $\alpha=0$ means, I would have interpreted it as $\frac{dx}{d0}$ now.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

Does diffusion of a spring depend on the spring’s equilibrium length?

  • Robert S. Pierre
  • Physics
  • Replies: 0
Robert S. Pierre Asks: Does diffusion of a spring depend on the spring’s equilibrium length?
Say we perform a random walk on $\mathbb{Z}$ with two equal particles that are connected by a spring with spring constant $K$ and equilibrium length $a$, where at each time step each particle has probability $\frac{1}{2}$ of making a step $\pm1$. However, at each step a random number $q\in[0,1]$ is sampled in order to refuse the move if $$q\geq\exp\left(\Delta E\right),$$ where $\Delta E$ is the difference in elastic energy between the two time steps.

Does the diffusion coefficient depend on the equilibrium length $a$?

I know that the diffusion is independent of the spring constant $K$, so we find the same diffusion coefficient for all $K$, namely that of two independent particles. I assume the same holds for the equilibrium length, but is this true and how can I see this?
And furthermore, what role does the initial extension of the spring play? Say the initial length of the spring $x_0$ is not equal to $a$, then the whole system will need a while to equilibrize, as opposed to when we start with $x_0=a$.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.