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

Refactor chained syntax to be transactional #8

Merged
merged 1 commit into from
Aug 2, 2016

Conversation

lawnsea
Copy link
Contributor

@lawnsea lawnsea commented Jul 29, 2016

Because cloning objects and arrays is generally O(N) in the size of the number
of keys or elements, immutable operations are relatively expensive. In cases
where multiple operations are performed without any opportunity for others to
observe intermediate values, the obvious optimization is to clone only once (for
the first operation) and mutate afterward.

So, refactor our "bound" or chained syntax as follows:

  • given a chain of operations on a source object, clone any descendants of that
    source object at most once
  • throw on any attempt to perform an operation after value is called on chain

Achieving this necessitated some refactoring of the internal API. All operations
now take a source (src) and a destination (dest). When called "unchained",
the mutation methods receive a null source.

Fix #5


I've deferred updating the README until this is ready to land. I can either push an update to the PR or amend the docs in a follow-on PR.

Because cloning objects and arrays is generally O(N) in the size of the number
of keys or elements, immutable operations are relatively expensive. In cases
where multiple operations are performed without any opportunity for others to
observe intermediate values, the obvious optimization is to clone only once (for
the first operation) and mutate afterward.

So, refactor our "bound" or chained syntax as follows:
- given a chain of operations on a source object, clone any descendants of that
  source object at most once
- throw on any attempt to perform an operation after `value` is called on chain

Achieving this necessitated some refactoring of the internal API. All operations
now take a source (`src`) and a destination (`dest`). When called "unchained",
the mutation methods receive a `null` source.

Fix mariocasciaro#5
@coveralls
Copy link

coveralls commented Jul 29, 2016

Coverage Status

Coverage increased (+0.4%) to 97.2% when pulling 9923877 on lawnsea:transaction into 57f1ef0 on mariocasciaro:master.

@mariocasciaro
Copy link
Owner

Hi Lon, thanks for the nice PR!
Merged!

@mariocasciaro mariocasciaro merged commit ed74d0b into mariocasciaro:master Aug 2, 2016
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.

None yet

3 participants