0

Typescript is so fucking frustrating sometimes to deal with

The snippet above AND below do the EXACT SAME FUCKING THING. But because you double tap, it loses the fucking (not needed) type before the mapTo. If you aren't paying attention, you get this extremely fucking aggravating wall of red.

God damn it, can't this be better? RxJS is pretty fucking important, so why is this so god damned hard to just get some coherent fucking code highlighting!?

/rantover

Comments
  • 0
    I'd be better concerned about such argument syntax. It doesn't explicitly say which key placed where, so much reliance on order.
  • 3
    There seems to be some missing parentheses in the second, while the first has a semicolon in the place you should have a comma.

    Especially parentheses can cause big problems as they can affect scope which can make the parser very sad.

    Another thing is to try to avoid such large constructs and build the argument lite separately or avoid so many arguments in the first place and use an object instead.

    Or build a list and use ... to send he list as arguments, that way you can build it in steps.
  • 1
    Honestly, this is self induced. You can pare this into at least 3 sub operators that'll enable reuse and increase clarity. You can also move the side effects out of the pipe series by either creating a late binding operator or externalizing the observable creation and have separate subscribers and using takeUntil for cleanup.

    Ex (shorthanded)
    // This can also be curried to do a pseudo-strategy
    private readonly getCompanyProject = (a,b,c,d) => pipe( // this is bat country
    mergeMap(...),
    mergeMap(...),
    mergeMap(...),
    mergeMap(...)
    );

    private readonly castastrophe = pipe(
    ofType(...),
    map(...) //Can probably just roll the cast in with filter,
    filter(...)
    )
    ...
    this.actions$.pipe(
    castastrophe,
    getCompanyProject(...)
    ....
    )

    Some catch error love would also not be inappropriate here. Probably switchmap as well for abandoning intermediaries.
  • 0
    This is down to RxJS typings for pipe: it supports up to 9 generics, if you put more operations into a single pipe it basically tells you "You've got some serious spaghetti code going on there, nobody can reasonably follow through"
Add Comment