Skip to content

Commit

Permalink
fix functional component name
Browse files Browse the repository at this point in the history
  • Loading branch information
beyaz committed Feb 18, 2024
1 parent 8720e81 commit 7f733a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,10 @@ function DefineComponent(componentDeclaration)
ComponentDefinitions[dotNetTypeOfReactComponent] = NewComponent;

NewComponent.displayName = dotNetTypeOfReactComponent.split(',')[0].split('.').pop();
if (NewComponent.displayName === 'FunctionalComponent')
{
NewComponent.displayName = componentDeclaration[DotNetProperties].Name;
}

return NewComponent;
}
Expand Down
15 changes: 11 additions & 4 deletions ReactWithDotNet/FC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IFunctionalComponent

partial class Mixin
{
public static Element FC(Func<IFunctionalComponent, Element> func)
public static Element FC(Func<IFunctionalComponent, Element> func, [CallerMemberName] string callerMemberName = null)
{
if (func == null)
{
Expand All @@ -35,15 +35,18 @@ public static Element FC(Func<IFunctionalComponent, Element> func)

RenderMethodNameWithToken = func.Method.GetNameWithToken(),

CompilerGeneratedType = targeType
CompilerGeneratedType = targeType,

Name = $"{targeType.DeclaringType?.Name}.{callerMemberName}"

};
}
}

throw DeveloperException("Invalid usage of Functional component");
}

public static Element FC(Func<IFunctionalComponent, Task<Element>> func)
public static Element FC(Func<IFunctionalComponent, Task<Element>> func, [CallerMemberName] string callerMemberName = null)
{
if (func == null)
{
Expand All @@ -66,7 +69,9 @@ public static Element FC(Func<IFunctionalComponent, Task<Element>> func)

RenderMethodNameWithToken = func.Method.GetNameWithToken(),

CompilerGeneratedType = targeType
CompilerGeneratedType = targeType,

Name = $"{targeType.DeclaringType?.Name}.{callerMemberName}"
};
}
}
Expand Down Expand Up @@ -283,6 +288,8 @@ sealed class FunctionalComponent : Component<FunctionalComponent.State>, IFuncti
public string RenderMethodNameWithToken { get; init; }

public bool IsAsyncFC { get; init; }

public required string Name { get; init; }

public void InitializeTarget()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,10 @@ function DefineComponent(componentDeclaration)
ComponentDefinitions[dotNetTypeOfReactComponent] = NewComponent;

NewComponent.displayName = dotNetTypeOfReactComponent.split(',')[0].split('.').pop();
if (NewComponent.displayName === 'FunctionalComponent')
{
NewComponent.displayName = componentDeclaration[DotNetProperties].Name;
}

return NewComponent;
}
Expand Down

0 comments on commit 7f733a5

Please sign in to comment.