Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set does not update a single, non nested field #431

Open
gabrielstuff opened this issue Oct 3, 2024 · 1 comment
Open

set does not update a single, non nested field #431

gabrielstuff opened this issue Oct 3, 2024 · 1 comment

Comments

@gabrielstuff
Copy link

The set function in the radash library is expected to update object properties, both for nested and simple keys. However, in our tests, it correctly modifies nested keys but fails to update simple keys.

Specifically, attempting to update a simple key like url does not produce the expected result, whereas updating nested keys (e.g., details.thumbnail.url) works as expected

here is a simple repro:

import { set, get } from 'radash'

async function main() {
  const media = {
    url: 'https://original-url.com',
    details: {
      thumbnail: {
        url: 'https://thumbnail.com'
      }
    }
  }

  console.log('Original media object:', media)
  const verifiedUrl = 'https://new-url.com'
  const thumbnailVerifiedUrl = 'https://new-thumbnail-url.com'

  set(media, 'url', verifiedUrl)
  set(media, 'details.thumbnail.url', thumbnailVerifiedUrl)

  console.log('Modified media object:', media)

  console.log('Updated url:', get(media, 'url'))
  console.log('Updated thumbnail url:', get(media, 'details.thumbnail.url'))
}

main()

Thanks for this amazing work

@aleclarson
Copy link

aleclarson commented Oct 14, 2024

The set function does not mutate the target object. It returns a copy.

P.S. Come check out the radashi fork, which is actively maintained and an improved version of Radash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants