barneycarroll / patchinko

A terse API for performing deep patching on JavaScript structures
MIT License
73 stars 5 forks source link

Error for object nested with DOM elements #22

Open robinchew opened 5 years ago

robinchew commented 5 years ago

Following code causes Illegal Constructor error:

import O from 'patchinko/immutable.mjs'

console.log(O({selected: {dom: document.body}}, {
  selected: O({
    dom: O(oldDom => document.body),
  }),
}))

console.log(O({selected: {dom: null}}, {
  selected: O({
    dom: O(oldDom => document.body),
  }),
}))

Run above code in flems

barneycarroll commented 5 years ago

There are two issues here:

  1. Can and should immutable be expected to procedurally copy complex objects?
  2. Should immutable be trying to copy objects at all in the case where they're being handed to a scope?

1 is tough. Currently we have thing => new thing.constructor as the copy mechanism. I don't think it's in Patchinko's remit to special case DOM objects, where there's no unopinionated way to copy a node (should cloneNode be passed true?).

2 is a design mistake in Patchinko, I think. That merits its own issue - #23.