Page 1 of 1

Remove collections.js and fp.js from tgui/common Package

Posted: Sun Mar 24, 2024 3:37 am
by Arthryxate
fp.js is a file inside the tgui/common package which contains two functions: compose and flow.

compose is a rarely used function, and as of March 03 of 2024, it does not appear to be used at all. It shares one common issue with flow: it is impossible to type. There is no guarantee about the return types of the functions passed in, and it is therefore impossible to type. Additionally, it takes its functions first before its input, so the functions have an unknown return type which can't be properly resolved. If a restriction is to be enforced such that the return types of all functions is equivalent, then that would make it somewhat possible to type, but that would limits its use and the effort is better spent rewriting code to remove its use. The same arguments apply to flow, but flow has more issues which is elaborated on in the next section.

flow is commonly used around complex combinations of filter, uniq, map, and so on. The function made sense in the past, at a time when JavaScript did not have the suitable built-in functions for operating on Arrays. However, that time is then and ES5 has become a common standard: it is even supported by IE10 and IE11.
ES5CanIUse.png

ES5 has introduced built-in functions such as filter and map which can be chained, unlike the old functions:

Code: Select all

// ES5
[].map(k => k + 3).filter(k => k > 10)

// collections.ts@tgui/common
filter(k => k > 10)(map(k => k + 3)([]))

// collections.ts + fp.js @ tgui/common
flow([map(k => k + 3), filter(k => k > 10)])([])
The new built-in ES5 functions render the old functions obsolete and the subsequent use of flow to promote such a pattern unnecessary. ES5 does not cover all functions which are defined in collections.js, however, but they can be polyfilled by core.js and/or lodash. Furthermore, lodash and core.js are large open-source projects which are rigorously tested. I believe that relying on these projects would allow the aforementioned files to be removed from tgui and reduce the technical debt contained within it.

In other words, I am on a mission to fully move tgui to TypeScript and I believe that removing these files is a step towards that mission.

Note: I am willing to work on this project if the idea is approved.

Re: Remove collections.js and fp.js from tgui/common Package

Posted: Mon Mar 25, 2024 1:56 am
by oranges
you need to come to the discord to discuss this.

Re: Remove collections.js and fp.js from tgui/common Package

Posted: Mon Mar 25, 2024 3:19 am
by san7890
for the record, any maintainer that I can think of with a vested interest in TGUI wants it all to be in typescript (jlsnow being a prominent example)