Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immutable (copy-on-write) semantics #25

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

haggholm
Copy link

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.

@coveralls
Copy link

Coverage Status

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants