#bookbrainz

/

      • crazyshrut joined the channel
      • crazyshrut has quit
      • anonn joined the channel
      • kellnerd[m]
        Ugh, I am struggling to get a simple for loop working with immutable-js objects, it causes many of my refactored validator tests to fail 😓
      • We should really migrate away from this ancient version 3.x which we are using, I am getting TypeError: values is not iterable when I try a for-of-loop...
      • bitmap[m] joined the channel
      • bitmap[m]
        What's the data type of values? (I've used immutable-js in the past though my memory of it is a bit fuzzy.)
      • kellnerd[m]
        That's the question, immutable-js does some weird shit to obfuscate whether something is array-like or map-like, I'm trying to find that out currently.
      • And v3 is even weirder than v4 as its main object type is called Iterable, which is not (fully?) implementing the ES iterable protocol.
      • I am basically trying to replace [this `every` call to a boolean validation function](https://github.com/metabrainz/bookbrainz-site/blob/f9dbef82d282ca54b592727a0baa0237cf2f03eb/src/client/entity-editor/validators/common.ts#L50) (a weird mix of immutable and lodash) with a plain loop which is calling a throwing validation function.
      • monkey[m]
        I remember there was a custom function to iterate over the results
      • kellnerd[m]
        Ha, I got it!
      • monkey[m]
      • kellnerd[m]
        The issue is that the function's parameters are annotated misleadingly, it says `any[]` but it is really something like `Record<any, any> | Immutable.Iterable`.
      • Now 70 failing tests pass again, only 5 remaining
      • monkey[m]
        Phew
      • Must feel good :)
      • reosarevok[m] joined the channel
      • reosarevok[m]
        I'll take examples of how any is useless and dangerous for $500
      • bitmap[m]
        I thought Record was also supposed to be iterable though 🤔
      • kellnerd[m]
        Its keys are iterable with for-in, but not its values, for-of throws.
      • I had to use the following:... (full message at <https://matrix.chatbrainz.org/_matrix/media/v3/...>)
      • bitmap[m]
        Ah, IIRC for-of on a Record would iterate over [key, value] pairs, but maybe not in your version
      • But that makes sense if you want only the values anyway
      • anonn has quit
      • kellnerd[m]
        Phew, fixing the last five failing tests took a bit longer because their expected behaviour was a bit inconsistent and I broke it while refactoring. I've left comments about these, so we can discuss whether these test cases are worth changing.