I’ve created a version of the library that uses copy-on-write semantics to avoid copying data unnecessarily or mutating input. It’s actually a pretty conservative change, but the diff is…unfortunately kind of enormous, for two reasons:
I ported the code to Typescript (it’s our primary language and it helped spot issues)—so that changed…well, a lot.
I didn’t really change any conceptual logic at all, but changing from foo.bar = 'baz' to foo = { ...foo, bar: 'baz' } every time something is mutated does result in a lot of changes.
The tests are entirely unchanged, except for the removal of one test that verified that objects weren’t being reused (since I specifically want to change that behaviour).
I’m not sure whether you’re interested in this, but it seems like the decent thing to offer, no? At any rate, if you do wish to accept this PR, I expect to do another round to clean up type definitions (the current version has a separate @types package jammed in somewhat awkwardly). Still,
I want to ask if there’s interest before I put more effort into a cleanup;
If so, please let me know if any of the lint settings are unsuitable;
If you do wish to accept this, it’s probably more convenient to review it in stages anyway. The TS port (+ a bunch of eslint stuff) make up one commit with 877 additions and 585 deletions, but no changes at all in behaviour. The other commits are rather more modest.
Coverage decreased (-1.4%) to 93.413% when pulling 668483f443055b9ac4c7e3ac1118cfb9f0906f6e on haggholm:immutable into 09bea1d99bedc3f702620ffada2abac92f37139e on mokkabonna:master.
I’ve created a version of the library that uses copy-on-write semantics to avoid copying data unnecessarily or mutating input. It’s actually a pretty conservative change, but the diff is…unfortunately kind of enormous, for two reasons:
foo.bar = 'baz'
tofoo = { ...foo, bar: 'baz' }
every time something is mutated does result in a lot of changes.The tests are entirely unchanged, except for the removal of one test that verified that objects weren’t being reused (since I specifically want to change that behaviour).
I’m not sure whether you’re interested in this, but it seems like the decent thing to offer, no? At any rate, if you do wish to accept this PR, I expect to do another round to clean up type definitions (the current version has a separate
@types
package jammed in somewhat awkwardly). Still,