Skip to content
This repository was archived by the owner on Jul 23, 2021. It is now read-only.

updateIn doesn't properly handle notSetValue #113

Closed
Methuselah96 opened this issue Oct 17, 2020 · 4 comments
Closed

updateIn doesn't properly handle notSetValue #113

Methuselah96 opened this issue Oct 17, 2020 · 4 comments

Comments

@Methuselah96
Copy link

From @migueloller on Fri, 30 Nov 2018 21:50:42 GMT

What happened

updateIn doesn't properly handle notSetValue.

How to reproduce

const { updateIn } = require('immutable')
const original = { x: { y: { z: 123 } } }
const NOT_SET = { NOT_SET: true }
console.log(updateIn(original, ['x', 'y'], NOT_SET, val => NOT_SET)) // { x: { y: { NOT_SET: true } } }

Expected the log output to be { x: {} } instead. Is this intended behavior?

Copied from original issue: immutable-js#1657

@Methuselah96
Copy link
Author

Correct behavior.

@migueloller
Copy link

@Methuselah96, how is this correct behavior? If the updater returns the "not set" value, then the value at that key should be unset (i.e., removed).

@migueloller
Copy link

For any future readers, explanation is here: immutable-js#1657 (comment)

@migueloller
Copy link

migueloller commented Nov 21, 2020

Based on the implementation, it seems that notSetValue is returned back to the updateIn caller if the value itself is not set. So it seems that it is not just limited to the value passed to the updater function if there is no value at the key path.

return updatedValue === NOT_SET ? notSetValue : updatedValue;

I also do see, though, how notSetValue is indeed passed to the updater, and that makes sense:

const existingValue = wasNotSet ? notSetValue : existing;
const newValue = updater(existingValue);

I was just expecting setting something to notSetValue would be equivalent to "unsetting" it.

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

No branches or pull requests

2 participants