65

Ahh the gems you find in codebases where only one person each is in charge of the frontend and the backend.

Comments
  • 3
    Just a few mins ago, did something like this.

    “data.data.something” (this is not too bad though)
  • 6
    Me, a gentleman.

    if( data1.data2.data3.status === 'success') {
  • 2
    Not pretty... not the end times, but yeah that's a lot of data ... data .... and so on.
  • 3
    Are you sure you've got the data after all? Asking for a friend.
  • 1
    Reminds me of axios. Needed to do response.data just to access to the response sent from the backend api, which has its own data object, so response.data.data.
  • 0
    I'm in a project like that with a friend. Thing is he handles the backend in a language I don't really know. I'll be interested to see if I'll find some gems once I'm more familiar with it (which I'm working on doing)
  • 13
    You forgot the null checks

    if(data && data.data && data.data.data && data.data.data.status && data.data.data.status === "success") 😬
  • 0
    @nitnip yeah that happens with Axios a lot. Plus Django REST framework wraps it in a {"detail": error}
  • 2
    How is each _data_ pronounced?
  • 3
    @ReverendLovejoy we like to live dangerously, null checks are for grannies!

    Cya later, gonna drive with a bandage on my eyes, i am getting better at it!
  • 0
    Let me guess: Of course this isn't typescript, but plain js, right?
  • 1
    @ReverendLovejoy and that's why typescript should be a norm
  • 1
    @3rdWorldPoison Types aside, optional chaining is in ES too (actually that's where TS snagged it from IIRC), so the whole thing would be data?.data?.data?.status === "success".
  • 1
    @ReverendLovejoy
    me an intellectual
    data?.data?.data?.data?.data?.data?. data?.data?.data?.data?.data?.data
  • 4
    Replace data with na

    Then you will get na.na.na.na.na.batman!
  • 2
    At least it isn’t

    data[“data”].data?
Add Comment