diff --git a/ReactWithDotNet/ElementSerializer.cs b/ReactWithDotNet/ElementSerializer.cs index ee55cb8a..48005190 100644 --- a/ReactWithDotNet/ElementSerializer.cs +++ b/ReactWithDotNet/ElementSerializer.cs @@ -404,12 +404,18 @@ propertyValue is Expression>|| transformFunction = transformValueInClientAttribute?.TransformFunction }; - var (success, handlerComponentUniqueIdentifier) = GetHandlerComponentUniqueIdentifierFromBindingExpression(context,propertyValueAsLambdaExpression); + var (success, handlerComponentUniqueIdentifier, handlerIsReactComponent) = GetHandlerComponentUniqueIdentifierFromBindingExpression(context,propertyValueAsLambdaExpression); if (!success) { throw HandlerMethodShouldBelongToReactComponent(propertyInfo, propertyValueAsLambdaExpression.ToString()); } + if (handlerIsReactComponent is false) + { + bindInfo.sourceIsState = true; + bindInfo.sourcePath = new[]{nameof(FunctionalComponent.State.Scope)}.Concat(bindInfo.sourcePath).ToList(); + } + bindInfo.HandlerComponentUniqueIdentifier = handlerComponentUniqueIdentifier; var debounceTimeout = instance.GetType().GetProperty(propertyInfo.Name + "DebounceTimeout")?.GetValue(instance) as int?; @@ -625,11 +631,17 @@ static async Task GetPropertyValueOfHtmlElement(ElementSerializerContext transformFunction = propertyDefinition.transformValueInClient }; - var (success, handlerComponentUniqueIdentifier) = GetHandlerComponentUniqueIdentifierFromBindingExpression(context,propertyValueAsLambdaExpression); + var (success, handlerComponentUniqueIdentifier, handlerIsReactComponent) = GetHandlerComponentUniqueIdentifierFromBindingExpression(context,propertyValueAsLambdaExpression); if (!success) { throw HandlerMethodShouldBelongToReactComponent(propertyDefinition.name, propertyValueAsLambdaExpression.ToString()); } + + if (handlerIsReactComponent is false) + { + bindInfo.sourceIsState = true; + bindInfo.sourcePath = new[]{nameof(FunctionalComponent.State.Scope)}.Concat(bindInfo.sourcePath).ToList(); + } bindInfo.HandlerComponentUniqueIdentifier = handlerComponentUniqueIdentifier; @@ -659,7 +671,7 @@ static async Task GetPropertyValueOfHtmlElement(ElementSerializerContext return propertyValue; } - static (bool success, int value) GetHandlerComponentUniqueIdentifierFromBindingExpression(ElementSerializerContext context, LambdaExpression lambdaExpression) + static (bool success, int value, bool handlerIsReactComponent) GetHandlerComponentUniqueIdentifierFromBindingExpression(ElementSerializerContext context, LambdaExpression lambdaExpression) { var (success, targetValue) = GetTargetValueFromExpression(lambdaExpression); if (success) @@ -668,7 +680,7 @@ static async Task GetPropertyValueOfHtmlElement(ElementSerializerContext if (handlerComponentUniqueIdentifier.HasValue) { - return (true, handlerComponentUniqueIdentifier.Value); + return (true, handlerComponentUniqueIdentifier.Value, targetValue is ReactComponentBase); } } diff --git a/ReactWithDotNet/FC.cs b/ReactWithDotNet/FC.cs index 0a9e7606..918b2861 100644 --- a/ReactWithDotNet/FC.cs +++ b/ReactWithDotNet/FC.cs @@ -183,6 +183,8 @@ protected override Element render() { return new FlexColumn(WidthMaximized, HeightMaximized) { + BindingSample(7), + AAAA(6), AAAA(7), AAAA(8), @@ -198,6 +200,35 @@ Task OnClickHandler(MouseEvent e) return Task.CompletedTask; } } + + static FC BindingSample(int start) + { + var count = start; + + var text = "label: "+ count; + + return cmp => + { + return new FlexColumn + { + new input + { + valueBind = ()=>count, + }, + new label{ text }, + new button(OnClick(OnClickHandler)){ "Update Count"} + }; + + Task OnClickHandler(MouseEvent e) + { + text = "label: "+ count; + + return Task.CompletedTask; + + } + }; + } + static FC AAAA(int start) {