ds300/derivablejs

`struct` will not `deepUnpack` constructor objects

ggoodman opened this issue · 2 comments

var havelock = require('havelock');

function Constructor (a, b) {
  this.a = havelock.atom(a);
  this.b = havelock.atom(b);
}

var obj = new Constructor(1, 2);

havelock.struct(obj).react(function (obj) {
  console.log(obj); // obj is not unpacked because of `.constructor === Object` check
}

This is a fantastic lib. Thanks for sharing, really found your router example fascinating.

Hi, thanks for the kind words :)

I wrote struct with object literals in mind, but you're right there's no need to restrict it to plain objects.

I'm on holiday right now so I'll probably get around to fixing this and #6 on Monday. Thanks again, have a great weekend.

Hmmm, thinking about this without wine in my belly has revealed a good reason to restrict struct to plain objects: how do you call an arbitrary constructor?

I think, for the sake of simplicity, it should just throw an error if the top-level arg is not a plain JS collection (Object, Array, maybe Map and Set if they are defined), and the docs should be very clear that no other types will be deeply unpacked.