Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: ComponentParameterInfo #4308

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

WIP: ComponentParameterInfo #4308

wants to merge 15 commits into from

Conversation

stsrki
Copy link
Collaborator

@stsrki stsrki commented Nov 17, 2022

I have noticed on the Button component( and in other places, too ) that we have an invalid condition for the Disabled parameter.

protected bool IsDisabled => ParentDropdown?.Disabled ?? Disabled;

the order should be reversed

protected bool IsDisabled => Disabled ?? ParentDropdown?.Disabled;

But the problem is that Button.Disabled parameter is bool type, and if we change it to bool? then it would break any component that tries to set it with a simplified syntax, eg.

<Button Disabled>


And so I'm now experimenting with a new concept of receiving the parameters. That is the new ComponentParameterInfo type. It tells us if the parameter is being received through the Blazor pipeline. No need to have a bool? Disabled parameter.

We can also have some other optimizations, like only calling DirtyClasses() if any of the wanted parameters is really received.

At the moment, the code is relatively crude. I need to see if it makes sense at all.

@stsrki stsrki changed the title Introduce ComponentParameterInfo WIP: ComponentParameterInfo Nov 17, 2022
@David-Moreira
Copy link
Contributor

David-Moreira commented Nov 17, 2022

I mean, it's similar to this && glutio's tripplet implementation, just that it's wrapped in a record and I guess it's easier to read & understand.
image

But seems like a good approach, I see the benefit in centralized the logic of how we detect if parameter was changed etc.

Would something like this be worth it at all?:

public record ButtonComponentParametersInfo
{
    public ComponentParameterInfo<bool> disabled = new ComponentParameterInfo<bool>( false );
    public ComponentParameterInfo<int> someNumber = new ComponentParameterInfo<int>( );

    event Changed; ??

        void Update( ParameterView parameters )
        {
            disabled = ResolveParameterStatus<bool>(parameters, nameof(Disabled));
            someNumber = ResolveParameterStatus<int>(parameters, nameof(SomeNumber));

            if ( disabled.Received )
            {
                Changed();
            }
        }
}

PS: Don't forget record is still a reference type... we're still a 3rd party library and should try to minize unecessary allocations, maybe try record struct or struct if possible? Like, having half a dozen of these across components quickly adds up I guess.

@stsrki
Copy link
Collaborator Author

stsrki commented Nov 18, 2022

Yes, that is exactly the idea I had in mind. I did this quick prototype in half an hour to not forget it. But yeah, I think it is much cleaner to read and write than the three-value system glutio had. I agree with changing it to the struct type. But as always, it might be good to benchmark it and see if it changes anything. Do you want to do that part?

@David-Moreira
Copy link
Contributor

Yes, that is exactly the idea I had in mind. I did this quick prototype in half an hour to not forget it. But yeah, I think it is much cleaner to read and write than the three-value system glutio had. I agree with changing it to the struct type. But as always, it might be good to benchmark it and see if it changes anything. Do you want to do that part?

Yea I can benchmark it.

@David-Moreira
Copy link
Contributor

@stsrki are you going to change anything, try record / struct implementation? Or want me to do some benchmarking first?

@stsrki
Copy link
Collaborator Author

stsrki commented Nov 30, 2022

@stsrki are you going to change anything, try record / struct implementation? Or want me to do some benchmarking first?

I will. Just that I had other stuff in the way. But you can try benchmarking if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants