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

A place to record your ideas for the game.
Post Reply
Arthryxate
Joined: Sun Mar 10, 2024 2:17 pm
Byond Username: Arthryxate

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

Post by Arthryxate » #724810

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.
User avatar
oranges
Code Maintainer
Joined: Tue Apr 15, 2014 9:16 pm
Byond Username: Optimumtact
Github Username: optimumtact
Location: #CHATSHITGETBANGED

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

Post by oranges » #724898

you need to come to the discord to discuss this.
User avatar
san7890
In-Game Game Master
Joined: Mon Apr 15, 2019 8:12 pm
Byond Username: San7890
Github Username: san7890
Location: here
Contact:

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

Post by san7890 » #724920

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)
Simultaneously making both the best and worst jokes on the internet. I like looking at maps and code. Learn how to map today!. You may rate me here.
Post Reply

Who is online

Users browsing this forum: Zeckle