Stateful objects
Closed this issue · 2 comments
I think you made this work for Date
... what about stateful objects in general? I have this use case where I wanted to use my own class which manages it's own state. However, it would error if I used it with updeep because it would get frozen and then it couldn't modify itself. I refactored the program so that the instance wasn't stored inside of the frozen structure, but I wonder if this should be a feature.
The simplest thing I have in mind is the ability to use updeep with freezing disabled. Something like result = u.mutable({foo: 'baz'}, {foo: 'bar', ack: myInstance})
... Thoughts?
I've thought about this, but it's somewhat tricky and ultimately it depends on what you're really trying to do. If you're just trying to mutate objects using updeep's semantics, then I'd probably suggest you just do it plainly, updeep doesn't provide too for already mutable objects.
If you're trying to store mutable objects within a frozen tree, I'd first ask/wonder why, but then I'd suggest you just create it with a constructor function other than Object and then we could modify u.freeze
to check against isPlainObject
. This is probably a good idea any way, but I didn't do it at first because I was curious how long I could get away with it 😄
If you're trying to store mutable objects within a frozen tree
Yep, this.
I'd first ask/wonder why
I'm still wondering it myself. Might just lead to problems even if updeep supported it.
Thanks for the reply 👍 I'll let you know if I find a use case that really begs support for this.