GithubHelp home page GithubHelp logo

camelize keys about apisauce HOT 5 CLOSED

infinitered avatar infinitered commented on August 20, 2024
camelize keys

from apisauce.

Comments (5)

mmahalwy avatar mmahalwy commented on August 20, 2024

The way I am getting around this is:

api.addResponseTransform(response => {
    if (response.data) {
      const data = camelizeKeys(response.data);

      Object.keys(response.data).forEach(key => {
        delete response.data[key];
      });

      Object.keys(data).forEach(key => response.data[key] = data[key]);
    }
  });

It's not elegant at all. Seems like I cannot change response.data by assigning a new object. I can only change keys and values.

from apisauce.

skellock avatar skellock commented on August 20, 2024

Agreed. I really didn't like how I implemented that at all.

The problem is I wanted to play it safe by passing a new object to each transform. I was encountering situations where I was able to break things if i mutated the wrong object (like config).

So although, it looks like the transform is receiving the response. It's not. It's receiving a decoy.

That's why changing references is messing up your evening.

I started out on the immutable route, but after seeing how slow transforms were once you started passing large data (like file uploads), i opted for the solution you see now.

from apisauce.

mmahalwy avatar mmahalwy commented on August 20, 2024

@skellock makes sense. What do you suggest is the best way then? My solution works for now, but it's... not great.

from apisauce.

skellock avatar skellock commented on August 20, 2024

Ok @mmahalwy , [email protected] is now out. Reassigning data (and everything else) is now a thing.

response.data = camelizeKeys(response.data)

from apisauce.

mmahalwy avatar mmahalwy commented on August 20, 2024

woohooo! Thank you!

from apisauce.

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.