vacuumlabs/babel-plugin-extensible-destructuring

Descructuring with spread operator (immutable.js)

savelichalex opened this issue · 6 comments

For example:

function foo() {
  return new Map({foo: 1, bar: 2});
}

function baz({foo, bar}) { ... }

baz(...foo())

not work. Need to do baz(...foo().toJS())

Thank you, I'll see to it.

well, I thought about this a little, and it seems to me, it's far from clear, what semantics should 'extensible spreading' have. Given that Map map is deeply immutable structure, what should

{...map, key: val} 

be? It should probably be js object, but what about the values in map? Should they be also recursively jsified?

Another problem I see is, that such proposal would require more patching (defining just __extensible_get__ is obviously not enough)

I think that should be jsified only first level of Map

What about spreading an Immutable Record? I was sort of expecting it to work because Record({a: 1}).a is defined, whereas for a Map it isn't; but it doesn't work. I think spreading an Immutable Record is probably pretty clearly defined though.

@jonathanj i'm not so sure. an Immutable.Record does not expose its keys in any meaningful way, except if you turn it into an Immutable.Map.

I can confirm that it's not working. However, the "toJS"-way seems a (temporary) patch.