json-schema-merge-allof
json-schema-merge-allof copied to clipboard
Immutable (copy-on-write) semantics
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'
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,
- 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.