oslabs-beta / ReactRPC

Full feature integration library for gRPC-Web into React
224 stars 9 forks source link

Bug in message marshaller #14

Open amin3141 opened 4 years ago

amin3141 commented 4 years ago

Imagine a I have a message like this:

message SomeMessage {
  uint32 customer_id = 5;
}

This generates a proto js that looks like this:

proto.SomeMessage.prototype.setCustomerId = function(value) {
  return jspb.Message.setProto3IntField(this, 5, value);
};

Now, imagine that my message is defined like this:

const message = { customerId: 234, msgType: "SomeMessage" }

Then this code in reactrpc/index.js causes a bug:

218        //Otherwise we just set the field with the value of the property
219        let newKey =
220          "set" + prop[0].toUpperCase() + prop.slice(1).toLowerCase();

newKey ends up being Customerid instead of CustomerId.

amin3141 commented 4 years ago

If you define:

function camelCase(prop) {
  let result = "";
  for (const part of prop.split("_")) {
    result += part.charAt(0).toUpperCase() + part.slice(1);
  }
  return result;
}

Then let newKey = "set" + camelCase(prop); fixes the problem for me.

karandeepahluwalia commented 4 years ago

Hey Amin, thanks for checking it out. We'll add that in there this weekend.