These are chat archives for ramda/ramda

11th
May 2018
Mike Lambert
@lax4mike
May 11 2018 17:42
is R.values different from Object.values?
klequis
@klequis
May 11 2018 18:47

I have a complex object:

state = {
  "exempt": true,
  "roles": [ ... ],
  "phone": [
    {
      "_id": "5aef93ac7fc94e4c7dc49c35",
      "phoneType": "Mobile",
      "phoneNumber": "000-000-0000"
    },
    {
      "_id": "5aef93ac7fc94e4c7dc49c36",
      "phoneType": "Mobile",
      "phoneNumber": "111-111-1111"
    }
  ],
  "_id": "5aef93ac7fc94e4c7dc49c37",
  "firstName": "First-0",
  "lastName": "Last-0",
  "comments": "Lorem ipsum ..",
}

I want to create a new object updated with

payload = {
  "field": "phoneNumber",
  "value": "111-111-111"
  "_id": "5aef93ac7fc94e4c7dc49c37",
}

As you can see, phone in state has an array of 2 so the _id in payload needs to be matched to find the correct phone before changing the data.
I could write code (JavaScript) to do this but wondering how to do with Ramda?

klequis
@klequis
May 11 2018 19:04
the _id in payload should have been 5aef93ac7fc94e4c7dc49c36
klequis
@klequis
May 11 2018 19:19
Here is my current solution
const newState = clone(prevState)
  newState.phone = prevState.phone.map(p => {
    if (p._id === payload._id) {
      return merge(p, {[payload.field]: payload.value})
    }
    return p
  })
  console.log(newState);