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
Patch handlePersisting(), and set correct structure during add, change, delete events. #8
Conversation
One gotcha I found is that you cannot add a new key path with a value I think this is a bug |
99f5409
to
19e3681
Compare
structure doesn't set correct new structure when deleting by key paths via `Cursor.remove(key)` or `Cursor.delete(key)`. Instead, value at key path gets set to undefined. This behaviour is corrected.
19e3681
to
d3cb7bb
Compare
This properly emit correct events such as updating the value at key path to a falsey value.
c9857e4
to
9b2d1e5
Compare
Since immutable-js/immutable-js@335b312, if an identity function is set as an Example: var
Immutable = require('immutable');
var map1 = Immutable.Map({a: true});
var
notSetValue = 'red',
updater = function() {
return notSetValue;
},
key = 'b'
var map2 = map1.update(key, notSetValue, updater);
console.log(map2.toJS());
// { a: true } <-- wrong? I PR'd to relax this condition: immutable-js/immutable-js#246 This isn't a blocker for what I'm trying to do; but I'm hoping to smooth out the correctness 😄 |
LGTM. Thanks! Good test coverage and the changes make sense. Especially the |
Patchs handlePersisting(), and sets correct structure during add, change, delete events.
Awesome thanks. Will this be pushed to npm anytime soon? |
It will be fairly soon. Just need to go over the code once more and test it out manually, see if there are any more changes we need to make and group that in the same patch release. |
Alright, no problem. By the way, I'm mulling over the following test case: immstruct/tests/structure_test.js Lines 236 to 239 in c824b06
I may consider dropping it until behaviour is resolved on immutable-js's end. |
It seems to me that it is testing the possibly only way for Immutable.js to solve it. Undefined might be tricky in this setting. |
@mikaelbr This case isn't exclusive of function pathExists(iterable, path) {
if(iterable.getIn(path)) {
return true;
}
var notSetValue = true;
return !(iterable.getIn(path, notSetValue) === notSetValue);
}
assert(pathExists(cursor, path) === false);
// notSetValue is anything but void 0
notSetValue = 'default';
cursor.update(path, notSetValue, id => id);
assert(pathExists(cursor, path) === false); |
By the way, immutable-js/immutable-js@8139d42 just landed. In the future, I'll PR to replace |
Sounds good. Would be good not having immutable patches in immstruct code-base. I'm renaming It seems however, the test you are talking about doesn't work in |
|
This PR corrects the following issues:
true
.Cursor.remove(key)
) doesn't actually delete the key path from the structure. Instead, value at key path is set toundefined
.void 0
,false
, etc).notSetValue
.The PR stems from my attempts to emulate
waitFor
in flux based on cursor key paths: