AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Can we add some concrete examples for JavaScript initializers in this page?

Open javiercn opened this issue 2 years ago • 1 comments

[EDIT by guardrex to change the metadata to point to the Startup topic, where we can place the examples with existing ones.]

Examples are:

  • Ensuring that your library is loaded before Blazor Starts.
  • Automatically loading the scripts that your library needs.
  • Ensuring that Blazor has been initialized before calling into it from your library.

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

javiercn avatar Jul 08 '22 10:07 javiercn

I'm changing the metadata for this b/c this was classified as a fundamental startup concept and placed in the Startup doc at ...

https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/startup?view=aspnetcore-6.0#javascript-initializers

... which is cross-linked from the JS interop topic. I think I'll adjust the cross-link to make it more obvious in the JS interop overview section.

We'll add the scenario examples to the Startup topic.

... and there's an orphan scenario that could either be moved or doubled in an INCLUDE file to appear in both places ...

https://docs.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/?view=aspnetcore-6.0#inject-a-script-after-blazor-starts

Note to self: I've isolated a group of PU repo dev issues that pertain to this. See YOUR 🦖 "JSinit #26363" bookmark folder!

guardrex avatar Jul 08 '22 11:07 guardrex

I'm going to place my notes here and mark this back off of In progress to P1 until I get a clearer understanding for each ask. Right now, here are the directions that I was thinking ...

  1. Ensuring that your library is loaded before Blazor Starts.

    Covered by loading a script in beforeStart.

  2. Automatically loading the scripts that your library needs.

    Load them in order in beforeStart.

    Do you want to add the approach for modules of using an import statement ... and if so ...

    (a) What should the doc say about adding an import statement to the top of the *.lib.module.js file? ... anything in particular about it?

    (b) Using a dynamic import({MODULE PATH}); statement within beforeStart? ... anything in particular?

  3. Ensuring that Blazor has been initialized before calling into it from your library.

    This doesn't just mean calling the library's initialization FN from afterStarted? I guess I'm not clear on where/when you mean for the "calling into it" part of that.

  4. Another ? ...

    Does the IIFE pattern play a role in any JS initializer scnearios?

  5. Another ? ...

    Should the guidance state that it's OK for a dev to export custom JS FNs from within the *.lib.module.js file SxS with beforeStart/afterStarted?

guardrex avatar Feb 16 '23 15:02 guardrex