Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Added view component tag helper updates. #823

Merged
merged 1 commit into from
Aug 24, 2016

Conversation

cjqian
Copy link
Contributor

@cjqian cjqian commented Aug 22, 2016

  • Exposed ToHtmlCase for use in creating tag names for view component tag helper descriptors.
  • Added a WriteAutoPropertyDeclaration method.
  • Added DecorateChunks as an opportunity to modify chunks before parsing in code generation, and BuildAfterExecuteContent to append extra generated code. Check these out in action here! (Still in progress, but hopefully you get the idea.)

@dnfclas
Copy link

dnfclas commented Aug 22, 2016

Hi @cjqian, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;

@davidfowl
Copy link
Member

No tests?

}
}

return new CodeGeneratorResult(writer.GenerateCode(), writer.LineMappingManager.Mappings);
}

protected virtual void BuildAfterExecuteContent(CSharpCodeWriter writer, IList<Chunk> chunks)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you mutate the chunks list here (add/remove)?

Copy link
Contributor Author

@cjqian cjqian Aug 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that we would DecorateChunks at BuildAfterExecuteContent?

For view component tag helpers, we need to mutate their chunks such that the type name includes the name of the page (ex. AspNetCore._Views_Index_Cshtml) since we'll be appending the after execute content within that class.

This needs to be done before the logic in lines 68-71, since that's when the type names of the chunks are written in the generated code. We could actually call DecorateChunks directly before that instead of at line 51?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both here and in DecorateChunks, what happens if I add a new chunk to the list of chunks? I know the view component tag helpers story required mutating the existing chunks, but what happens if new ones are added or removed. Should this list be readonly or are there valid things you could do.

Similarly, what happens if chunks are removed. Will code that runs later blow up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, understood. I don't think anything would blow up... It would be similar to adding/deleting parts of the .cshtml file, maybe. Worst case, you could change the content of the chunks and rewrite the view? If the chunks were invalid, perhaps things would just not render? (I'm not sure on this, what do you think?) The chunk list has to be modifiable in our current implementation so we can modify the type names. Is this valid?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, DecorateChunks() is about mucking w/ the chunks collection and this method is about writing stuff out. Suggest this method use IReadOnlyList<Chunk> chunks to make things more clear.

@cjqian
Copy link
Contributor Author

cjqian commented Aug 23, 2016

@davidfowl Tests for which part? We're just exposing ToHtmlCase, and there didn't seem to be tests for CSharpCodeWriter. I plan on writing tests for MvcCSharpCodeGenerator (which implements DecorateChunks and BuildAfterExecuteContent) when that gets pushed.

@davidfowl
Copy link
Member

@cjqian Tests verifying that the new public method you exposed does what you expect. Also that the new virtual method gets called with the right arguments.

@@ -711,7 +711,7 @@ private static bool IsAccessibleProperty(PropertyInfo property)
/// ONE1TWO2THREE3 => one1two2three3
/// First_Second_ThirdHi => first_second_third-hi
/// </example>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix the <example> since this is now public. Right now all the lines will be shown as one messy line. Easiest to surround the lines w/ <code>...</code>.

@dougbu
Copy link
Member

dougbu commented Aug 24, 2016

Like the coverage of the new tests and the new extension points. My comments suggest alternatives but I don't such anything that's Just Wrong™️.

@dougbu
Copy link
Member

dougbu commented Aug 24, 2016

/// Provides an entry point to append code (after execute content) to a generator razor class.
/// </summary>
/// <param name="writer"></param>
/// <param name="chunks"></param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls fill in the blanks.

@dougbu
Copy link
Member

dougbu commented Aug 24, 2016

⌚ almost done!

}
}

return new CodeGeneratorResult(writer.GenerateCode(), writer.LineMappingManager.Mappings);
}

/// <summary>
/// Provides an entry point to append code (after execute content) to a generator razor class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Razor

@dougbu
Copy link
Member

dougbu commented Aug 24, 2016

⌚ for one last touch-up of the doc comments.

@cjqian
Copy link
Contributor Author

cjqian commented Aug 24, 2016

🆙 📅

/// <summary>
/// Provides an entry point to modify chunk data before code generation.
/// </summary>
/// <param name="context">The <see cref="CodeGeneratorContext"/> of the chunks."/> </param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last "/> is a typo. Remove those 3 characters.

/// </summary>
/// <param name="writer">The <see cref="CSharpCodeWriter"/> to receive the additional content.</param>
/// <param name="chunks">The list of <see cref="Chunk"/>s for the generated program.</param>
protected virtual void BuildAfterExecuteContent(CSharpCodeWriter writer, IList<Chunk> chunks)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot: Does IReadOnlyList<Chunk> not work for your feature?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided offline to leave this as is b/c Tree.Children is an IList<Chunk> and creating another List<Chunk> isn't worth it.

@dougbu
Copy link
Member

dougbu commented Aug 24, 2016

:shipit:

/// </summary>
/// <param name="context">The <see cref="CodeGeneratorContext"/> of the chunks."/> </param>
/// <param name="chunks">The list of <see cref="Chunk"/>s for the generated program.</param>
protected virtual void DecorateChunks(CodeGeneratorContext context, IList<Chunk> chunks)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we don't technically need this piece. MVC already semi-decorates the chunk tree by merging in _ViewImports chunks.

See: https://github.com/aspnet/Mvc/blob/c942eab6e268714f23f0d3b31e35036901d3b2e0/src/Microsoft.AspNetCore.Mvc.Razor.Host/MvcRazorHost.cs#L328-L331

@cjqian
Copy link
Contributor Author

cjqian commented Aug 24, 2016

🆙 📅

.Write(typeName)
.Write(" ")
.Write(name)
.Write(" {")
Copy link
Contributor

@NTaylorMullen NTaylorMullen Aug 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.WriteLine(" { get; set; }"); 👍

@cjqian
Copy link
Contributor Author

cjqian commented Aug 24, 2016

🆙 📅

@dougbu
Copy link
Member

dougbu commented Aug 24, 2016

:shipit:

1 similar comment
@NTaylorMullen
Copy link
Contributor

:shipit:

@cjqian cjqian force-pushed the ViewComponentTagHelperUpdates branch from cc9c536 to 2deafd4 Compare August 24, 2016 22:59
@cjqian cjqian merged commit 489c0d9 into aspnet:dev Aug 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants