adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
552 stars 45 forks source link

Error with code generation #218

Closed powerdude closed 4 months ago

powerdude commented 4 months ago

Describe the bug I'm trying to introduce these 2 classes:

public abstract  partial class BaseComponent2<TState> :Component<TState> where TState : class, new()
{
    [Inject] protected readonly IMediator Mediator;
    [Prop] protected MauiControls.Shell shellRef;
}

public abstract  partial class BaseComponent2<TState, TProps> :Component<TState,TProps> where TState : class, new()
    where TProps : class, new()
{
    [Inject] protected readonly IMediator Mediator;
    [Prop] protected MauiControls.Shell shellRef;   
}

To Reproduce Create these 2 classes in your project:

public partial class ModelsPage : BaseComponent2<ModelsPage.PageState>
{

    public override VisualNode Render() =>
        new ContentPage
        {
            new CollectionView().AutomationId("list")
                .ItemsSource(State.Items, Render)
        };

    protected override void OnMounted()
    {
        Routing.RegisterRoute<ModelPage>("Model");

        //Mediator.Send(new GetModelsQuery())
        //    .Await(items => SetState(s => s.Items = items.ToArray()), ex => Trace.WriteLine(ex));

        base.OnMounted();
    }

    private VisualNode Render(Model item) =>
        new VStack(5)
            {
                new Label(item.Name).AutomationId(item.Id + "-name"),
                new Label(item.Id).AutomationId("id")
                    .FontSize(12)
                    .TextColor(Colors.Gray)
            }
            .OnTapped(
                async () => await shellRef.GoToAsync<ModelPage.Props2>(
                    "Model",
                    props => props.Id = item.Id))
            .Margin(5, 10);

    public class PageState
    {
        public Model[] Items { get; set; } =
        [
        ];
    }
}

public partial class ModelPage : BaseComponent2<ModelPage.PageState, ModelPage.Props2>
{

    public override VisualNode Render() =>
        new ContentPage("Muscle Group")
        {
            new Label(State.Item?.Name).AutomationId("name")
                .VCenter()
                .HCenter()
        };

    protected override void OnMountedOrPropsChanged()
    {
       // Do something
        base.OnMounted();
    }

    public class PageState
    {
        public Model Item { get; set; }
    }

    public class Props2
    {
        public string Id { get; set; } = null!;
    }
}

public record Model(string Id, string Name);

Expected behavior Should work.

Additional context Can work around it by giving the base classes different names.

adospace commented 4 months ago

Sorry, what do you mean by "not working"? Do you see an exception? or it just doesn't compile?

powerdude commented 4 months ago

The second class's partial class doesn't seem to get generated so, the mediator field does not get initialized. Possibly due to a duplicate generated filename problem since the filename just uses the class name and doesn't account for the type parameters