Yamato DaiwaFrontend (2.0.0-beta.0)

Integration with @yamato-daiwa/es-extensions (YDEE)

Once the Functionality.pug file (located in the root directory of the @yamato-daiwa/frontend npm package) has been included, all functionality of version 1.7 of @yamato-daiwa/es-extensions (abbreviation: "YDEE") library becomes available. The exception is such functionality which ceases to exist during the transpiling from TypeScript to JavaScript, such as interfaces and type aliases.

The main use case of this functionality is primitive data mocking during the static preview stage. For example, the following code demonstrates how to quickly create 16 item cards with random data:

Here, the functions getRandomString, getRandomObjectPropertyValue, and getRandomInteger from YDEE have been used. The associative array-like constant DummyImagesURIs is part of YDF. As a result, for each card, HTML code similar to the following will be generated (avoiding taking up too much space, the src attribute of the img tag has been truncated):

Even if you are not planning such usage of YDEE, it still requires the correct functioning of the YDF functionality related to markup, for example, for Pug mixin's parameters validation:

Answers to FAQ and criticism

Criticism

Do you mean that almost the entire code of YDEE has been embedded in the Pug code? Is it not overkill?

Answer
Any functionality is added to YD-libraries only after practical demand arises. Concerning the YDEE integration, such demand was and is present (the use cases have been explained above). If some functionality is no longer required, we replace it with new one and rarely remove (although YDF has been published relatively recently, it and its prototypes have passed alpha testing for several years). However, the demand for YDEE integration is stable, thus removal is not planned.
Question

Will the usage of YDEE inside the Pug code on the backend with the MVC frameworks cause performance impact during Pug-to-HTML compilation?

Answer

It will, herewith significantly (about 2-3 seconds, but it is unacceptable for the case of generating the server response).

The YDEE integration is primarily intended for the static preview stage. However, if Pug-to-HTML conversion is performed preliminarily once per site or application deploy , there are basically no problems with using YDEE integration on other development stages.

Most likely, you are asking this because you want to know what you have to do when you need YDEE functionality on the stage of the interactive application with server-side rendering using MVC pattern (for example, to keep Pug mixins parameters validation , including mixins of the GUI components or to keep using the pages templates ), but without performance impact. There is a manual specialized in this problem , but in short it is required to provide two-stage Pug-to-HTML conversion. In the first stage, the intermediate template file is generated, and these files do not change due to dynamic data (such as data from the database). Also, these template files are generated only once before deploying each version of the website or the web application. At the second stage, the dynamic data is interpolated into the intermediate template, and the final HTML code is generated.