Commit Graph

27 Commits

Author SHA1 Message Date
Steve Sanderson e71db85149 Handle overlapping events (#1655)
* Add failing unit test to demonstrate overlapping events bug

* Handle overlapping events

* Make RemoteRenderer.UpdateDisplay's return task not complete until client sends explict ACK

* CR: Rename UpdateDisplay to UpdateDisplayAsync

* CR: Fix namespace

* CR: Catch synchronous SendAsync exceptions (if they can happen)
2018-11-13 12:08:08 +00:00
Adrian Wright 5e0aa0c0fa Fix typos 2018-11-09 10:17:10 -08:00
Ryan Nowak 8f072a0711 Add HTML Block rewriting (#1146)
* Add HTML Block rewriter

* Baseline updates

* test gaps

* Update some unit tests to represent same behavior as before

* Define Markup frame type. Tests for rendering markup frames into render tree.

* Support markup frames during diffing (retain, insert, update, delete)

* Support markup blocks on WebAssembly

* Support rendering markup frames with server-side execution too

* Support markup blocks with multiple top-level nodes. Support updating markup dynamically.

* Define MarkupString type as a way to insert dynamic markup without needing custom RenderFragment code

* Remove comment

* CR: Better null value handling
2018-07-23 18:18:07 +01:00
Steve Sanderson 767a2373c8 Eliminate ElementRef's static incrementing ID for remote rendering cases
... because it's important not to disclose cross-user state, such as the number of IDs that have been assigned. Plus we don't want to run out of unique IDs, which we could if it's limited by the range of an 'int'.
2018-07-10 09:52:19 +01:00
Steve Sanderson 4427b3b773 Add more struct readonlyness hints 2018-06-06 11:49:55 +01:00
Steve Sanderson 18b9a70dbe Encourage encapsulation of component parameter properties (#713)
* Before refactoring ParameterCollection assignment logic, add more test coverage

* Begin caching parameter assignment info

* Factor out some reflection code to a reusable location

* Use IPropertySetter to avoid all per-property-assignment reflection

* More error cases and tests for parameter assignment

* Enable binding to nonpublic properties

* Add analyzer to warn and provide fix for public component parameters

* Unit test for analyzer

* Component tag helper now includes private properties if they have [Parameter]

* CR feedback: Remove garbage from csproj

* CR feedback: Rename .Build.Analyzers to .Analyzers

* CR feedback: Move BlazorApi.cs to shared; use it from Analyzers test

* Fix incorrect test name

* Make as many parameters private as possible. Replace ILayoutComponent with BlazorLayoutComponent.

* In component tag helper discovery, consider private members too

* Reduce the work in component parameter discovery by not inspecting the BlazorComponent base class (or System.Object)
2018-05-01 10:08:01 +01:00
Ryan Nowak f661021324 Add [Parameter] for component parameters
This change introduces ParameterAttribute to specify a bindable
component parameter. As of the 0.3 release of Blazor we plan to make
[Parameter] required to make a property bindable by callers.

This also applies to parameters when their value is set by the
infrastructure, such as `Body` for layouts, and route paramters.

The rationale behind this change is that we think there is a need to
separate the definition of properties from their suitability for a
caller to set them through markup. We plan to introduce more features in
this area in the future such as marking parameters as required. This is
first step, and we think that this approach will scale nicely as we add
more functionaly.

The 0.3 release seems like the right time to change this behavior since
we're also introducing `ref` for captures in this release.
2018-04-30 13:35:08 -07:00
Steve Sanderson 4033560734 Support 'ref' syntax for capturing references to elements and components (#685) 2018-04-27 17:41:21 +01:00
Ryan Nowak ed06d7b12e Rough cut at async events 2018-04-26 13:31:28 -07:00
Ryan Nowak 05c166eafa Fix failing test
This is failing due to Steve and I's changes passing in the night.
2018-04-10 16:35:37 -07:00
Steve Sanderson bd2c8a09ef Improve JS-side event handling code. Fixes #433 2018-04-10 18:15:22 +01:00
Ryan Nowak df13669362 Improvements for delegate types (#516)
* Improve support for more types of event handlers

Improves support for for other types of event handlers with eventargs
types derived from UIEventArgs. Additionally fleshes out the set of
event handler types.

This change improves support for using more specific event handler types
like:

```
<button onclick="@Clicked" />

@functions {
    public void Clicked(UIMouseEventArgs e) { ... }
}
```

And:
```
builder.AddAttribute(12, "onkeypressed", KeyPressed);

...

void KeyPressed(UIKeyboardEventArgs e) { ... }

```

In particular what got better is:
- overload resolution for the AddAttribute method
- performance of different cases for AddAttribute

-----

The runtime now treats delegates as one of three types:
- arbitrary delegate: not attached to DOM events, not tracked by
renderer
- UIEventHandler: can attach to DOM events, tracked by renderer, first
class in IHandleEvents
- UIEventHandler-like: can attach to DOM events, tracked by renderer,
requires some special runtime support.

The set of overloads on AddAttribute has been tuned with a few specific
cases in mind.

Lambda expressions in an attribute will be inferred as UIEventHandler
unless the compiler does something more specific. So for instance,
passing a lambda as an attribute value for a component, where the
component doesn't define a matching attribute, will always be inferred
as UIEventHandler.

We now support method-group to delegate conversion for methods that
accept a derived UIEventArgs type. This means you can use a signature
like `void KeyPressed(UIKeyboardEventArgs e)` without any compiler
magic, and this will work in the runtime as long as the event type
produced by the runtime matches.

We also allow user-defined UIEventArgs-derived types. There's a pattern
for this and it requires defining an extension method and delegate type.

The method-group to delegate conversion part required some doing. It
doesn't play well with generics (Action<T> where T : UIEventArgs)
doesn't work at all. Adding more actual overloads (as opposed to
extensions) would cause lambda cases we want to work to be ambiguous.

----

The performance win here is to remove the need for a 'wrapper' delegate
created by the event handler tag helper code. This wrapper is now
created by the runtime, but only *after* we have checked the frame for
changes. This requires more heavy lifting in the runtime, but has the
advantage of producing no-op diffs as often as possible.

You will still get some inefficient behavior if your component uses a
capturing lambda in an event handler, so don't do that.

* Add selenium logs to test output

* Minor feedback

* WIP
2018-04-09 13:21:12 -07:00
Ryan Nowak d097190824 Add support for conditional attributes
Adds conditional attributes for HTML elements.

This means that an attribute with a 'false' .NET bool value or a null
.NET value of another type will not be rendered in the HTML.
2018-04-03 14:06:48 -07:00
Steve Sanderson 3ef78dcb7b Stop treating RenderFragment as immutable, because its output isn't 2018-03-05 02:02:26 +00:00
Steve Sanderson ce10e6fa19 In preparation for DI, give every Renderer an IServiceProvider 2018-02-23 09:32:26 +00:00
Steve Sanderson 25b76bc6dc Skip rerendering child components if their params are definitely unchanged 2018-02-22 13:23:52 +00:00
Steve Sanderson 95023c0300 In RazorCompiler, support components with children 2018-02-22 11:07:03 +00:00
Steve Sanderson df825de86d Reorganise some test helpers in shared locations 2018-02-16 17:23:04 +00:00
Steve Sanderson 29a6175ac1 Define RenderFragment concept 2018-02-16 10:10:10 +00:00
Steve Sanderson 1ac5ee25c1 Rename RenderTreeBuilder's AddText to AddContent, since it will be used for other types too 2018-02-16 10:10:08 +00:00
Steve Sanderson 848f24536a Support "Region" frames in diffing 2018-02-14 23:41:24 +00:00
Steve Sanderson 0eb0555303 Eliminate IComponent.BuildRenderTree to guarantee that components are only rendered by themselves 2018-02-13 19:47:37 +00:00
Steve Sanderson 861154764c Introduce IComponent.SetParameters, moving parameter-setting and rerendering logic into component base class 2018-02-13 15:00:53 +00:00
Steve Sanderson 695ddc0fd6 Add Init/RenderHandle concepts so components can rerender themselves arbitrarily (e.g., after internal state change) 2018-02-13 11:49:33 +00:00
Steve Sanderson e37e22aa27 Further renderer refactoring 2018-02-10 10:55:44 +00:00
Steve Sanderson 15ddcd03b0 Major refactor of responsibilities in rendering code. Not quite done
with this yet either.
2018-02-09 14:50:07 +00:00
Steve Sanderson 91314ee8c8 Rename RenderTreeDiffComputer -> RenderTreeDiffBuilder 2018-02-08 15:50:14 +00:00