-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
add $delete command to addons.update #2362
Conversation
@krawaller "it's generally preferable", if you're dealing with fixed keys then setting to undefined/null should be preferable (to avoid creating new hidden classes), but if you're dealing with dynamic indices then deleting probably makes most sense. It was just intended as a reminder for anyone stumbling upon it. |
Nod, understood. Another note, just realised that to continue parity with MongoDB, this should probably be renamed to |
Updated functionality for MongoDB
This means we now have the exact same functionality as MongoDB, except...
|
Nagging @petehunt because we wanna pull this in and deprecate |
I've said it here but want to bring the comment here as well: I'm not sure special behavior for arrays is justified, even if Mongo does it. IMO if |
On the other hand, most people probably want “normal” After all, if you really wanted to poke a hole in an array, you can |
it’s the other way round: dense arrays have bad performance characteristics when used to represent sparse ones. and nothing about setting elements to mongo’s behavior makes no sense:
that’s bullshit. if you also, why would someone specify an object without values just to give a set of keys. JS has no native syntax for sets (objects-without-values), and we only iterate the keys, so KISS and simply accept an array of keys or one key here like in other update([1,2,3], {$unset: 1}) === [1,,3]
update([1,2,3], {$unset: [0, 2]}) === [,2]
Object.keys(update([1,2,3], {$unset: 0})) === ['1', '2'] |
+1 for this. I'd love an $unset command! |
+1 |
Prefer using immutable.js. We don't want to turn this into a crazy DSL. |
Is this even used internally, can we split this out into a standalone library? addons.update is valuable to me outside of React projects. |
@dustingetz Would you want to maintain it? |
It is used internally (unfortunately). And yes, while it's available standalone(ish, it still depends on react), it should be split off in a real standalone project. Give me a good name and I'll do it sometime soon. I kinda want to call it |
I want to use it to implement |
I see it's split on npm: https://www.npmjs.com/package/react-addons-update, but where does the code live? Is there a seperate github repo? I can only find the code in the react repo? |
@peteruithoven It currently only lives here, where you found it. The npm module (all of the react-addons- modules in fact) just require deeply into react for the time being until they can become standalone / get removed. |
But pull requests like this one aren't merged? It feels like we shouldn't use this until it's split off and it can accept more contributors / contributions. |
From what I understand it stays here in 0.14 because |
As an experiment here is updateIn implemented against react-addons-update, along with other nice wrappers, it is a very nice programming model https://github.com/dustingetz/update-in import {updateIn, merge, push, unshift, splice} from 'update-in';
const val = {a: {b: 0, c: 2}, xs: [1, 2]};
merge({x: 1, y: 1}, {y: 2, z: 2}) // => {x: 1, y: 2, z: 2}
updateIn(val, ['a'], merge, {c:99, d: 99}) // => {a: {b: 0, c: 99, d: 99}, xs: [1, 2]} |
👍, being able to by the way, if anyone wants a |
You might be interested in https://github.com/kolodny/immutability-helper that lets you define custom operations by name. |
@krawaller updated the pull request. |
Using In case it helps anyone, I have created an almost-compatible module which implements https://www.npmjs.com/package/update-immutable My module also supports autovivification which can help you avoid maintaining initial state skeletons in components. |
This PR adds a
$delete
command toaddons.update
. It takes a key or an array of keys and deletes them from the target object.CLA completed (first-time contributor).