From d9ee42f3592ffb05aec0e42fffe8579244797bc9 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 13 Jul 2023 15:59:44 -0700 Subject: [PATCH] (NFC) Civi\ESM - Doc cleanups --- Civi/Esm/BasicLoaderTrait.php | 12 +++++++++--- Civi/Esm/README.md | 25 +++++++++++++------------ Civi/Esm/ShimLoader.php | 6 +++--- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Civi/Esm/BasicLoaderTrait.php b/Civi/Esm/BasicLoaderTrait.php index c63a5e34f7..c7d94f6ae0 100644 --- a/Civi/Esm/BasicLoaderTrait.php +++ b/Civi/Esm/BasicLoaderTrait.php @@ -5,8 +5,10 @@ namespace Civi\Esm; use Civi; /** - * The AbstractLoader is a base-class BrowserLoader and ShimLoader. These are similar - * in that they load ESM's by displaying HTML, e.g. + * The BasicLoaderTrait is a building-block for BrowserLoader and ShimLoader. + * + * These are similar -- both need to get a list of modules and format the + * list as HTML markup, e.g. * * * - * However, subclasses may use different HTML. + * However, the HTML formatting is slightly different. Observe how `BrowserLoader` + * and `ShimLoader` both `BasicLoaderTrait` and then implements methods like `renderModuleScript()`. + * + * @see \Civi\Esm\BrowserLoader + * @see \Civi\Esm\ShimLoader */ trait BasicLoaderTrait { diff --git a/Civi/Esm/README.md b/Civi/Esm/README.md index 68048ef49c..93adf6d3c5 100644 --- a/Civi/Esm/README.md +++ b/Civi/Esm/README.md @@ -9,11 +9,11 @@ import { TableWidget } from 'https://example.com/sites/all/modules/civicrm/js/ta import { TableWidget } from 'civicrm/js/tab-widget.js'; ``` -CiviCRM source-trees may have a variety of file-structures, based on the hosting environment and local configuration. -Consequently, writing valid `import` statements for Civi-related code is much easier with logical-paths. They are -easier to read and easier to adapt. +Writing `import` statements is easier with logical-paths -- they're short, clean, and adaptable. +(Recall that CiviCRM is deployed with a variety of web-hosts, UFs, and configuration-options. This +means that the physical-paths change frequently and dramatically.) -Logical-paths must be defined with an import-map. For native browser-based imports, it looks like: +Logical-paths must be defined with an `importmap`. For native browser-based imports, it looks like: ```html \n"; + echo "\n"; ``` 2. Given that CiviCRM (as a whole; core+extensions) has defined an import-map, ensure that the import-map is properly loaded so that recursive-dependencies may be resolved. For example: ```php $civicrmImportMap = json_encode(Civi::service('esm.import_map')->get()); - echo "\n"; + echo "\n"; ``` -There are a few variations on how to perform these steps. Each variant defines a service `esm.loader.XXX` -(implemented in `Civi\Esm\XXX`). For example, these two are currently implemented: +There are multiple loaders, which perform these tasks in slightly different ways. + +Every loader defines a service (`esm.loader.XXX`) and class (`Civi\Esm\XXX`). For example: * `esm.loader.browser` (`Civi\Esm\BrowserLoader`): Use pure, browser-based loading with `