Skip to content

help about: "copying value lets Flow guarantee the pointer isn't modified elsewhere" #443

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

Closed
ghost opened this issue Jun 15, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 15, 2017

I would be obliged if one explain AddUniqueOp.applyTo comment:
https://github.com/parse-community/Parse-SDK-JS/blob/master/src/ParseOp.js#L199

applyTo(value: mixed | Array<mixed>): Array<mixed> {
    if (value == null) {
            return this._value || [];
    }
    if (Array.isArray(value)) {
      // copying value lets Flow guarantee the pointer isn't modified elsewhere
      var valueCopy = value;
      var toAdd = [];
      this._value.forEach((v) => {
        if (v instanceof ParseObject) {
          if (!arrayContainsObject(valueCopy, v)) {
            toAdd.push(v);
          }
        } else {
          if (valueCopy.indexOf(v) < 0) {
            toAdd.push(v);
          }
        }
      })
      return value.concat(toAdd);
    }
    throw new Error('Cannot add elements to a non-array value');
}

why we need valueCopy reference?

var valueCopy = value;

and why we need copy technique?

thanks

@stale
Copy link

stale bot commented Feb 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Feb 6, 2019
@stale stale bot closed this as completed Feb 13, 2019
dplewis added a commit that referenced this issue Nov 10, 2020
Addresses: #443

Removing this to prevent confusion. Does anybody want to explain why this is needed?
davimacedo pushed a commit that referenced this issue Nov 10, 2020
Addresses: #443

Removing this to prevent confusion. Does anybody want to explain why this is needed?
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

No branches or pull requests

1 participant