Closed KilianKilmister closed 3 years ago
I would love to have a better way of doing these things, but there are reasons. Admittedly it could be that I do not know any better, and if you can find a better way that would be great. As usual this will sound negative; please do not take it that way.
"The manipulation of the DOM using the Document.write method is not an optimal choice."
I know, but as usual I am constrained by the fact that this has to be easy to use by authors. It has to be possible for one author to write a set of library files, and for a second author to be able to easily add those files to his game.
ETA: Using the bundler would be the way, I guess.
"i'd also suggest not passing object properties and formatting options together with the text."
Not sure I get this entirely. I get that processing a string several times is going to be slower, and I think the changes I did a couple of days ago may have improved this slightly?
Also, note that output can be held up occasionally. If you open page-eg.html and type in the command "reveal" you will see various effects and pauses that the output system has to support.
Being able to pass a function as the an object property to be executed in the final output step enables easy use of of plugins.
For example a passed function could send send the display text to google translate and the returned string would just pass along the line and be printed to screen.
Through this, we expose a controle point at the very end of the chain where anything can be injected without affecting the core of the engine.
I well take a look at it, but it’s not my main focus for right now
I am going to close this as it has been hanging around so long.
I do not think there is an issue with document.write, as according to here it is only prohibited in fairly usual situations, including when the script is on another domain, so is not the case here. https://developers.google.com/web/updates/2016/08/removing-document-write
The manipulation of the DOM using the Document.write method is not an optimal choice.
It is in fact acitvely blocked in chrome when used on a 2G connection. ([src1](https: //developers.google.com/web/updates/2016/08/removing-document-write), [src2](https: //stackoverflow.com/a/27531116/12945644))
i'd also suggest not passing object properties and formatting options together with the text.
in general, parsing data in string form decrypting that at the target requires unnescessary resources and can massively decrease code-maintainability and readability.
Data should be passed in proper JavaScript objects. If any translation from and/or to another dataformat is required (plain text is a data format in itself) this should be done as the first/last step with before receving/outputting the data plain data.
(if we count the Just-In-Time compilation from JS into machine language you can double the translations)
examlpe taken from
/io.js
This function call in the test flow takes a Plain text string
this is the first translation from plain text to JS
The called function then has to translate another string
this function coud be skipped entirely as it doesn't add any nformation nescessary until it is outputted. All actual information dded here is a "debug"-flag.
this function does even more processing processing
all the information this entire function actually adds is
someArray.push(input)
the rest is utterly unneccesary.postprocessor/translator
this last part should do exactly two things:
the translator will recieves all instructions from the postprocessor and interpret it to translate it to another dataformat and send it off to the final destination.