Giter VIP home page Giter VIP logo

Comments (1)

glennsl avatar glennsl commented on May 31, 2024 1

Hey. There's quite a few reasons why using records aren't a great idea:

  1. It would mean converting every object to a record at runtime, and that has to be done with the whole object hierarchy which is often very large and usually recursive, which doesn't work very well with records. This also has a significant runtime cost, of course, and to make matters even worse, will add a lot of code relative to the rest of the library. The library would most likely become an order of magnitude larger, since it's so slim as it is.

  2. The DOM isn't well-typed, meaning the type of some object may not be known completely, and therefore can't be fully converted. Using abstract types and functions to access properties means it can be evaluated later when that information is known.

  3. Records don't support subtyping, so you can't have functions operating on all kinds of events.

  4. Records aren't objects. They don't have methods or internal mutable state. So the actual object would have to be carried around as an ordinary field in the record to be used by functions that would then delegate to the object methods internally. And if a method alters internal state, a new record would have to be created to reflect this new state, which would incur more runtime costs, but also means the API would have to diverge further from its JS counterpart, negating the purpose of using records in the first place.

  5. Using functions to manipulate abstract types is more idiomatic. Hiding the structure of the data you're operating on is good practice because it affords you the flexibility of changing the implementation without changing the interface. This is why you have properties in C# and set/get methods in Java, for example, but in JavaScript good software engineering practices usually go out the window (which makes writing bindings for JS APIs often quite challenging).

Not all of these necessarily applies to DOM events specifically, but consistency across the whole of the DOM API is a goal in itself. You could also use JS object types instead of records and access properties via the ## operator. This solves many, but not all, of the above problems.

These reasons are just off the top of my head, so there may be more, but I hope this satisfies your curiosity at least :)

from bs-webapi-incubator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.