Commit Graph

506 Commits

Author SHA1 Message Date
Ryan Nowak 15ba614e6f Remove old workaround @onclick and @bind
This change removes support for the old syntax used for event handlers
and two-way binding.

See the relevant issues for details on the new features and
improvements:

bind https://github.com/aspnet/Blazor/issues/409
event handlers https://github.com/aspnet/Blazor/issues/503

Along with this change we've removed a few additional things Blazor
could do that aren't part of Razor's usual syntax.

----

The features that was used to make something like:
```
<button @onclick(...) />
```

is an expression that's embedded in a an element's attribute. This
feature might be useful in the future if we want to support 'splatting'
arbitrary attributes into a tag, but the runtime support for this isn't
accessible outside the Blazor core.

----

The features that implement:
```
<button onclick=@{ } />
```

have been removed in favor of a better design for lambdas, method group
conversions and other things for event handler attributes.

use `<button onclick=@(x => ...} />` instead.

We think is a better approach in general, because we want the app
developer to write and see the parameter list.

----

Both syntactic features that have been removed have dedicated error
messages in the compiler. If you're porting old code it should help you
figure out what to do.
2018-04-10 16:54:15 -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
Steve Sanderson 281d5a8751 Enable same-origin credentials by default. Add E2E test to show they can be sent to different-origin domains too. 2018-04-09 12:54:13 +01:00
flash2048 e096d7e0b1 Correct the use of a parameter 'autoSpace' in the constructor 2018-04-09 12:08:20 +01:00
Ryan Nowak d3bdb987b0 Add a new feed dotnet-core
This is the *new* and most correct feed for our developer builds.
Leaving the old ones there for now because the other ASP.NET Repos also
left them there.
2018-04-08 14:24:06 -07:00
Ryan Nowak f2c78b0776 Update Razor dependency (non-template) 2018-04-08 14:24:06 -07:00
Ryan Nowak b106cf4d6c Update non-product dependencies 2018-04-08 14:24:06 -07:00
chassq 3f0c2b31a0 Update README.md
Wanted to make sure people knew to get the latest preview of VS 2017...
2018-04-07 19:29:41 -07:00
Daniel Roth 08d5a15013 Update survey links for 0.2.0 2018-04-06 15:15:48 -07:00
Ryan Nowak da3f686f0c Update KoreBuild and SDK
This updates the toolset the repo is using to build. Will merge this if
it passes.
2018-04-06 13:25:47 -07:00
Ryan Nowak c3366bc956 Add event handlers as tag helpers
This change adds support for mapping DOM event handlers as tag helpers
that function in a bi-modal way.

This is a new first-class feature for DOM events, and replaces a few
workarounds like using `@onclick(...)` or `click=@{ ... }`. I haven't
removed those things yet, this is a first pass to get the new support
in, we'll remove those things when we're totally satisfied.

When used with a string like `<button onclick="foo" />` the result is
a simple HTML attribute .

But when used with an implicit expression like
`<button onclick="@Foo" />` or
`<button onclick="@(x => Clicked = true)" />` a C# function is bound to
the click event from the DOM.
2018-04-06 13:00:04 -07:00
flash2048 3369208c28 Fix mistake in array index 2018-04-06 11:41:47 +01:00
Steve Sanderson a82fd5099e Force browsers to check for modifications to Blazor-served resources. Fixes #371 2018-04-06 10:58:23 +01:00
Steve Sanderson fef5a52183 Reference static content from referenced assemblies. Implements #340 2018-04-06 09:50:10 +01:00
Daniel Roth 05059d9aa3 Rename configure parameter to services 2018-04-05 12:03:54 -07:00
Daniel Roth 907832524a Add DI extension method namespace to Program.cs in templates 2018-04-05 12:03:54 -07:00
Steve Sanderson 902625579b For better consistency between VS and CLI, specify resource sources in csproj rather than NuGet.config
This was not possible before because of the
`Microsoft.NET.Sdk.Razor/2.1.0-preview2-30230` entry in `Sdk`, which
can't be loaded from a custom restore source. But since that's on
NuGet.org now, it's no longer a problem.
2018-04-05 10:41:13 +01:00
Steve Sanderson d3dc294d5e Revert live reloading implementation. See PR for explanation. 2018-04-04 18:10:12 +01:00
Ryan Nowak 707e781e5d Add Razor baseline test infrastructure
Ports somee infrastructure and converts Razor code generation tests to use
it. This makes it much easier to make cross cutting changes to code
generation and see the effect.

Use build /p:GenerateBaselines=true to update all of the generated code
in place or when adding new tests. Generally if tests are failing, the
easiest thing to do is to update the baselines and do a git diff to see
what the deltas are.

The changes to the tests here are to use the new baseline infrastructure
and to rename classes/methods to result in shorter file paths.
2018-04-04 08:05:59 -07:00
Steve Sanderson 2d89c11183 Update templates to Blazor 0.2.0-preview1-10168 2018-04-04 14:08:06 +01:00
Steve Sanderson f1283940b7 In live reloading, also reload if the server is being recycled. Plus rewrite LiveReloading.ts completely to be better organized. 2018-04-04 14:06:30 +01:00
Steve Sanderson de4d78f454 Only trigger live reloading from VS when enabled in MSBuild 2018-04-04 12:31:43 +01:00
Steve Sanderson 6f7c188a76 Revert the attempt to share signal file path between MSBuild and VS extension code, because it doesn't get populated at the right time 2018-04-04 12:26:51 +01:00
Guillaume ZAHRA 3b0f1313fe Resolution for "The path must be absolute" on published projects
Trying to replace the internal "." folder with the local assembly path in order to have an absolute path for the PhysicalFileStorage class at startup ("The path must be absolute" error at startup for published projects)

May resolve the issue of #376 on dev
2018-04-04 11:41:56 +01:00
Steve Sanderson 049673db0d Update templates to Blazor 0.2.0-preview1-10165 2018-04-04 11:31:36 +01:00
Steve Sanderson 71a3e31799 Trigger live reload feature after successful builds in VS 2018-04-04 11:29:59 +01:00
Steve Sanderson 5dfa857eab Minor NavLink cleanups 2018-04-04 10:21:07 +01:00
Austin Cummings 30ec582767 Add `ActiveClass` option to NavLink component 2018-04-04 10:16:49 +01:00
Olivier Lefebvre 1626b3b8c8 Support arbitrary 'fetch' arguments 2018-04-04 10:12:42 +01:00
Ryan Nowak 0c942ccc76 Fix for #453
This fix adds missing line mappings for the Blazor runtime code
generation. We had the correct line mappings for design time code, but
they were missing in this case for runtime code - where they are used
for error messages and debugging (not yet supported).

Once this fix is is in the error window and output log will report the
file/line/column of the original source in .cshtml.

It looks like jumping to the code from the error window is currently not
working correctly in VS. It works from the output window.

I'm going to follow up on the VS issue in the Razor repo, since the fix
won't come from the Blazor side.
2018-04-03 15:34:41 -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
flash2048 ff5e6a78c3 Fix some tests with DateTime in German culture 2018-04-03 15:09:26 +01:00
Steve Sanderson 2c268a4eca Live reloading (currently enabled only for command-line builds - will
add VS support next)
2018-04-02 15:33:00 +01:00
Steve Sanderson 1fe90e2c0f Avoid unnecessary assembly/type lookups when retrieving cached method handles 2018-04-02 13:14:48 +01:00
Grahame Horner 590a47f6c7 Mono Platform Method Caching 2018-04-02 13:11:12 +01:00
flash2048 e696325b76 Corrects spelling of some comments 2018-04-02 12:34:08 +01:00
Steve Sanderson 0f73aca42e Different attempt to fix AppVeyor CI issues 2018-03-30 13:39:22 +01:00
Steve Sanderson e7573e00da Hopefully fix the AppVeyor CI issues 2018-03-30 13:09:03 +01:00
Steve Sanderson 38cdb870f8 Update templates to Blazor 0.2.0-preview1-10152 2018-03-30 12:22:58 +01:00
Steve Sanderson b596d0d9f8 Reorder package-lock.json to make NPM happy 2018-03-30 12:22:58 +01:00
Steve Sanderson b52912a460 Handle ternary expressions inside interpolated attributes. Fixes #446 2018-03-30 11:38:10 +01:00
Luke Latham 2a8d06b539 Double-quote attribute values? 2018-03-30 10:12:35 +01:00
Ryouko Konpaku ef3db51bbf Text Area Bind Fix for issue #434 (#439)
* Text Area Bind Fix for issue #434

* Correct Typo/Mispelling on test method name.
2018-03-30 10:10:23 +01:00
Stephen Roe cda3692d0b Added SVG support (#366) (#435)
* Added SVG support (#366)

* Added E2E tests for SVG
2018-03-30 10:07:10 +01:00
Ryan Nowak 5b658c80a1 Replace @bind with bind-...
This change introduces a 'tag helper' that replaces @bind with custom
code generation that accomplishes roughly the same thing.

This feature lights up by dynamically generating tag helpers that are
visible to tooling and affect the code generation based on:
- pattern recognition of component properties
- attributes that create definitions for elements
- a 'fallback' case for elements

'bind' also supports format strings (currently only for DateTime) via
a separate attribute.

This change introduces the basic framework for bind and tooling support.
We know that we'll have to do more work to define the set of default
'bind' cases for the DOM and to flesh out the conversion/formatting
infrastructure.

This change gets us far enough to replace all of the cases we currently
have tests for :) with the new features. The old @bind technique still
works for now.

Examples:

@* bind an input element to an expression *@
<input bind="@SelectedDate" format="mm/dd/yyyy" />
@functions {
    public DateTime SelectedDate { get; set; }
}

@* bind an arbitrary expression to an arbitrary set of attributes *@
<div bind-myvalue-myevent="@SomeExpression">...</div>

@* write a component that supports bind *@

@* in Counter.cshtml *@
<div>...html omitted for brevity...</div>
@functions {
    public int Value { get; set; } = 1;
    public Action<int> ValueChanged { get; set; }
}

@* in another file *@
<Counter bind-Value="@CurrentValue" />
@functions {
    public int CurrentValue { get; set; }
}
2018-03-29 22:04:24 -07:00
flash2048 b53d39e16f Corrects spelling of some comments, method name and remove an excess flag 2018-03-29 14:20:04 +01:00
Steve Sanderson f15c995a2a Ensure JSON deserializer only uses Activator.CreateInstance implicitly for structs 2018-03-29 10:41:07 +01:00
Matthew Lazarow 25cf73ed80 Json to struct error 388 2018-03-29 10:41:07 +01:00