News for hackers. Stuff that matters.
Re:OCaml for the Masses (2011) by atombender on Monday November 26, 2018 @07:40PM (#18538246)
I'm doing the ES6 + Immutable thing right now in some React apps. (I'd prefer to use TypeScript, but the codebases are too large to convert.)

It's an improvement over plain JS, but also a nightmare. For example, it's hard to create truly immutable classes. I ended up with this pattern:

  class Foo {
    #props
    
    constructor(props) {
      this.#props = Map(props)
    }

    get someField() {
      return this.#props.get('someField')
    }

    withSomeField(value) {
      return new Foo(this.#props.set('someField', value))
    }
  }
It works, but it's annoying. Then you have, as you say, all the coercion/conversions between Immutable and plain JS values.

TypeScript would help, but I think I'm going to look into Reason, too. I think I heard that it supports interoperating with ordinary JS. The problem with TS, last I tried it, was that while it supports JS, there are subtleties (like the lack of support for default imports) that mean it's not fully backwards compatible. You can't just run a JS codebase with the TS compiler and expect it to work, as I understand it.

There are no comments on this comment yet.