json-schema-merge-allof icon indicating copy to clipboard operation
json-schema-merge-allof copied to clipboard

Immutable (copy-on-write) semantics

Open haggholm opened this issue 4 years ago • 1 comments

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:

  1. I ported the code to Typescript (it’s our primary language and it helped spot issues)—so that changed…well, a lot.
  2. 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,

  1. I want to ask if there’s interest before I put more effort into a cleanup;
  2. If so, please let me know if any of the lint settings are unsuitable;
  3. 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.

haggholm avatar Nov 13 '20 03:11 haggholm

Coverage Status

Coverage decreased (-1.4%) to 93.413% when pulling 668483f443055b9ac4c7e3ac1118cfb9f0906f6e on haggholm:immutable into 09bea1d99bedc3f702620ffada2abac92f37139e on mokkabonna:master.

coveralls avatar Nov 13 '20 03:11 coveralls