Skip to content

Commit

Permalink
Added repro for a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasherceg committed Feb 8, 2024
1 parent 7faf5a0 commit 4d43044
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Samples/Common/DotVVM.Samples.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
<None Remove="Views\FeatureSamples\LambdaExpressions\ClientSideFiltering.dothtml" />
<None Remove="Views\FeatureSamples\LambdaExpressions\LambdaExpressions.dothtml" />
<None Remove="Views\FeatureSamples\Localization\Globalize.dothtml" />
<None Remove="Views\FeatureSamples\MarkupControl\CommandAsProperty.dotcontrol" />
<None Remove="Views\FeatureSamples\MarkupControl\CommandAsPropertyPage.dothtml" />
<None Remove="Views\FeatureSamples\MarkupControl\CommandAsPropertyWrapper.dotcontrol" />
<None Remove="Views\FeatureSamples\MarkupControl\MarkupDefinedProperties.dothtml" />
<None Remove="Views\FeatureSamples\MarkupControl\MarkupDefinedPropertiesControl.dotcontrol" />
<None Remove="Views\FeatureSamples\MarkupControl\ServiceDependency\ServiceDependencyControl.dotcontrol" />
Expand Down
2 changes: 2 additions & 0 deletions src/Samples/Common/DotvvmStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ private static void AddControls(DotvvmConfiguration config)
config.Markup.AddCodeControls("cc", typeof(Loader));
config.Markup.AddMarkupControl("sample", "EmbeddedResourceControls_Button", "embedded://EmbeddedResourceControls/Button.dotcontrol");
config.Markup.AddMarkupControl("cc", "NodeControl", "Views/ControlSamples/HierarchyRepeater/NodeControl.dotcontrol");
config.Markup.AddMarkupControl("cc", "CommandAsProperty", "Views/FeatureSamples/MarkupControl/CommandAsProperty.dotcontrol");
config.Markup.AddMarkupControl("cc", "CommandAsPropertyWrapper", "Views/FeatureSamples/MarkupControl/CommandAsPropertyWrapper.dotcontrol");

config.Markup.AutoDiscoverControls(new DefaultControlRegistrationStrategy(config, "sample", "Views/"));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DotVVM.Framework.ViewModel;
using DotVVM.Framework.Hosting;

namespace DotVVM.Samples.Common.ViewModels.FeatureSamples.MarkupControl
{
public class CommandAsPropertyPageViewModel : DotvvmViewModelBase
{

public List<ItemModel> Items { get; set; } = new() {
new ItemModel() { Name = "One", IsTrue = true },
new ItemModel() { Name = "Two", IsTrue = false },
new ItemModel() { Name = "Three", IsTrue = true }
};

public ItemModel SelectedItem { get; set; }

public Task MyFunction(string name, bool isTrue)
{
SelectedItem = new ItemModel() { Name = name, IsTrue = isTrue };
return Task.CompletedTask;
}


public class ItemModel
{
public string Name { get; set; }
public bool IsTrue { get; set; }

}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DotVVM.Framework.Binding;
using DotVVM.Framework.Controls;

namespace DotVVM.Samples.Common.Views.FeatureSamples.MarkupControl
{
public class CommandAsProperty : DotvvmMarkupControl
{

public Func<string, bool, Task> Click
{
get => (Func<string, bool, Task>)GetValue(ClickProperty)!;
set => SetValue(ClickProperty, value);
}
public static readonly DotvvmProperty ClickProperty
= DotvvmProperty.Register<Func<string, bool, Task>, CommandAsProperty>(c => c.Click, null);

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@viewModel System.String, mscorlib
@baseType DotVVM.Samples.Common.Views.FeatureSamples.MarkupControl.CommandAsProperty, DotVVM.Samples.Common

<%-- When uncommented, it produces an error --%>
<%-- In Release mode, the error that is really hard to debug (maybe it was caused because the control was loaded from embedded resource). --%>
<%--<dot:Button Text="{value: _this}" Click="{command: _control.Click}" />--%>


<%--The following with ToString works somehow and I am not sure by what magic--%>
<dot:Button Text="{value: _this}" Click="{command: _control.Click.ToString()}" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@viewModel DotVVM.Samples.Common.ViewModels.FeatureSamples.MarkupControl.CommandAsPropertyPageViewModel, DotVVM.Samples.Common

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>

<cc:CommandAsPropertyWrapper Click="{command: (string name, bool isTrue) => _root.MyFunction(name, isTrue)}" />

<p DataContext="{value: SelectedItem}">Selected item: {{value: Name}}, {{value: IsTrue}}</p>

</body>
</html>


Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DotVVM.Framework.Binding;
using DotVVM.Framework.Controls;

namespace DotVVM.Samples.Common.Views.FeatureSamples.MarkupControl
{
public class CommandAsPropertyWrapper : DotvvmMarkupControl
{

public Func<string, bool, Task> Click
{
get { return (Func<string, bool, Task>)GetValue(ClickProperty); }
set { SetValue(ClickProperty, value); }
}
public static readonly DotvvmProperty ClickProperty
= DotvvmProperty.Register<Func<string, bool, Task>, CommandAsPropertyWrapper>(c => c.Click, null);

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@viewModel DotVVM.Samples.Common.ViewModels.FeatureSamples.MarkupControl.CommandAsPropertyPageViewModel, DotVVM.Samples.Common
@baseType DotVVM.Samples.Common.Views.FeatureSamples.MarkupControl.CommandAsPropertyWrapper, DotVVM.Samples.Common

<dot:Repeater DataSource="{value: Items}">
<%--
The correct syntax would be Click="{value: _control.Click(_parent.Name, _parent.IsTrue)}"
Btw is value binding the right thing, or shall we use resource binding here?
--%>
<cc:CommandAsProperty Click="{value: _control.Click(_parent.Name, _parent.IsTrue)}" DataContext="{value: Name}" />
</dot:Repeater>

0 comments on commit 4d43044

Please sign in to comment.