babel-plugin-extensible-destructuring icon indicating copy to clipboard operation
babel-plugin-extensible-destructuring copied to clipboard

Descructuring with spread operator (immutable.js)

Open savelichalex opened this issue 8 years ago • 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())

savelichalex avatar Mar 24 '16 13:03 savelichalex

Thank you, I'll see to it.

tomaskulich avatar Mar 31 '16 12:03 tomaskulich

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)

tomaskulich avatar Apr 09 '16 19:04 tomaskulich

I think that should be jsified only first level of Map

savelichalex avatar Apr 18 '16 12:04 savelichalex

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 avatar Feb 28 '17 07:02 jonathanj

@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.

palnes avatar Feb 21 '18 17:02 palnes

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

highfield avatar Mar 07 '19 06:03 highfield