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

Redesign TagHelper content modes. #250

Closed
wants to merge 4 commits into from

Conversation

NTaylorMullen
Copy link

Removed ContentBehavior

  • Removed all tests and instances of ContentBehavior in preparation for moving to a non-ContentBehavior based design.
  • Removed ContentBehavior specific CodeGeneration.

Re-design TagHelperOutput and runtime dependencies to allow all content modes.

  • Added PreContent, PostContent and ContentSet properties to TagHelperOutput.
  • Added GeneratePreContent, GeneratePostContent and SupressOutput methods to TagHelperOutput.
  • Added multile ExecuteChildContentAsync and GetChildContentAsync to the rendering phase, ultimately only exposing GetChildContentAsync to a TagHelper author.
  • Added more knowledge of StartWritingScope and EndWritingScope to the TagHelper runtime components. This is to enable the runtime components to utilize the RazorPage's infrastructure to render a delegate to a writer and retrieve its value to ultimately expose it to the user.

Modify tests to allow new content mode design for runtime components.

  • Added a new internal ctor for TagHelperExecutionContext since it's used in multiple tests to allow for less friction testing.

Added CodeGen for TagHelper content mode redesign.

  • Modified the CSharpTagHelperCodeRenderer to understand a single line of TagHelper rendering (instead of doing different things based on ContentBehavior).
  • Modified existing CodeGen output to reflect new content changes.
    Tag Helpers: Redesign of Tag Helpers content mode #221

_Note:_ Will add tests once design is good.

/cc @dougbu @pranavkm

/// <remarks>
/// Child content is only executed once. Successive calls to this delegate return a cached result.
/// </remarks>
public Func<Task<string>> GetChildContentAsync { get; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe call this GetChildContentDelegate - we have some precedence for naming delegates it in this fashion elsewhere in Mvc.

@NTaylorMullen
Copy link
Author

Updated to address comments (still design).

@NTaylorMullen NTaylorMullen force-pushed the thcontentmode.221 branch 3 times, most recently from a06a1d0 to 3eae637 Compare December 15, 2014 20:51
@NTaylorMullen NTaylorMullen changed the title [Design] Redesign TagHelper content modes. Redesign TagHelper content modes. Dec 18, 2014
@NTaylorMullen
Copy link
Author

Added tests.

/// </summary>
/// <returns>Content rendered by children.</returns>
/// <remarks>
/// Child content is only executed once. Successive calls to this delegate return a cached result.
Copy link
Contributor

Choose a reason for hiding this comment

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

currently will execute the Func on every call. to behave as described, need a Task<string> _childContentAsync field and

  if (_childContentAsync == null)
  {
    _childContentAsync = _getChildContentAsync();
  }

  return _childContentAsync;

nit: better names might be _getChildContentAsyncFunc and _getChildContentAsync since the Func itself isn't async and just returns a Task

Copy link
Author

Choose a reason for hiding this comment

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

It was a tough call, the caching logic is done indirectly in the TagHelperExecutionContext. The reason why it's done there is because the CodeGen needs access to it and CodeGen doesn't have access to the TagHelperContext since TagHelperContext is 1-1 with each TagHelper and created inside the TagHelperRunner.

It's a rough situation but I'm open to alternatives.

Copy link
Contributor

Choose a reason for hiding this comment

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

then <remarks/> make no sense here. remove.

N. Taylor Mullen added 4 commits December 19, 2014 17:34
- Removed all tests and instances of ContentBehavior in preparation for moving to a non-ContentBehavior based design.
- Removed ContentBehavior specific CodeGeneration.

#221
…nt modes.

- Added PreContent, PostContent and ContentSet properties to TagHelperOutput.
- Added GeneratePreContent, GeneratePostContent and SupressOutput methods to TagHelperOutput.
- Added multile ExecuteChildContentAsync and GetChildContentAsync to the rendering phase, ultimately only exposing GetChildContentAsync to a TagHelper author.
- Added more knowledge of StartWritingScope and EndWritingScope to the TagHelper runtime components. This is to enable the runtime components to utilize the RazorPage's infrastructure to render a delegate to a writer and retrieve its value to ultimately expose it to the user.

#221
- Added a new internal ctor for TagHelperExecutionContext since it's used in multiple tests to allow for less friction testing.

#221
- Modified the CSharpTagHelperCodeRenderer to understand a single line of TagHelper rendering (instead of doing different things based on ContentBehavior).
- Modified existing CodeGen output to reflect new content changes.

#221
@NTaylorMullen
Copy link
Author

Updated

@NTaylorMullen
Copy link
Author

Closing and re-opening against dev.

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.

3 participants