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

Change Addition #88

Closed
suni-masuno opened this issue Jan 10, 2017 · 2 comments
Closed

Change Addition #88

suni-masuno opened this issue Jan 10, 2017 · 2 comments

Comments

@suni-masuno
Copy link

Feature Request: It seems reasonable (and fits my case) to take an array of changes and sum them into one final change. With some moderate effort I could (and might) write this myself, but it seems like a natural fit for the project itself. My inclination is something like sumChanges([change1,change2,change3...changen])~~>totalChange so that I can look back and say what all has happened over a span of time.

Feature Request 2: It also seems desirable to extend apply change into applyChanges([...]) which takes an array of changes to apply to the origin (an ordered array that is).

Do these have downsides I'm missing? Beyond the fact that I'm a random person on the internet asking for things ^_^

Thanks for he great tool by the way, if you do or do not take the request.

@flitbit
Copy link
Collaborator

flitbit commented Apr 26, 2017

  1. The default is an array of changes or undefined if there are none. Doesn't that already provide the total changes?

  2. Code below: you're not alone on this one - I do it all the time:

function applyChanges(target, changes) {
  return changes.reduce(
    (acc, change) => {
      diff.applyChange(acc, true, change);
      return acc;
    },
    target
  );
}

flitbit pushed a commit that referenced this issue May 1, 2017
@flitbit
Copy link
Collaborator

flitbit commented May 1, 2017

Take a look at example/issue-88.js - let me know if you still really need it as part of the package.

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

No branches or pull requests

1 participant