Skip to content

fix(ivy): ngOnChanges to receive SimpleChanges with private non minif…#22352

Closed
marclaval wants to merge 2 commits intoangular:masterfrom
marclaval:fixLifecycle3
Closed

fix(ivy): ngOnChanges to receive SimpleChanges with private non minif…#22352
marclaval wants to merge 2 commits intoangular:masterfrom
marclaval:fixLifecycle3

Conversation

@marclaval
Copy link
Copy Markdown
Contributor

…ied property names as keys

If my understanding is correct, with this code:

@Component({selector: 'lifecycle-comp', template: ``})
    class LifecycleComp {
      @Input('publicName') privateName: string;
      ngOnChanges(changes: SimpleChanges) {
         console.log(Object.keys(changes).join(',');
     }
   ...
}

Then, upon changes, 'privateName' will be logged in the console, not 'publicName' and not the minified version of 'privateName'.
If this behaviour is to be kept, we'd need to generate some data structure to keep this information. This PR is implementing a quite naive solution for that.

On top of that, it adds tests for the OnChange hook.

@marclaval marclaval added action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release comp: ivy labels Feb 21, 2018
@marclaval marclaval requested a review from kara February 21, 2018 17:34
@kara kara requested review from alxhub and mhevery February 21, 2018 18:11
Copy link
Copy Markdown
Contributor

@vicb vicb Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a "list" (may be fix the other API docs)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should drop "private" everywhere, it sounds misleading.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this terminology:

  • alias = the name given in the decorator,
  • property name = source code,
  • minified name

Copy link
Copy Markdown
Contributor

@kara kara Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that private is confusing. Interesting that I came to a similar conclusion but with alias flipped. e.g. public name is external facing, alias is internal-facing (if different).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning is that there is the thing (the property in our case) and you can give it any alias with @Input(alias) whatever the alias we always refer to the thing.

Copy link
Copy Markdown
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me aside from the name, but @alxhub or @mhevery should take a look too (in case they had a different plan for this)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like copy-pasted comment? Update to read onChanges?

Comment thread packages/core/src/render3/definition.ts Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could improve upon this name, esp since the property names of this will also be minified, which could be confusing. How about inputAliases?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test might be clearer if you show which parts would be minified. e.g.

inputs: {a: 'val1', b: 'publicName'},
inputsNonMinified: {b: 'val2'}

Same on line 1755

Copy link
Copy Markdown
Contributor

@kara kara Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention that these are private names or aliases to differentiate from inputs (same comment on line 40)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, update to read onChanges?

Comment thread packages/core/src/render3/definition.ts Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be rename inputToAlias, inputToProperty, outputToAlias if you think the terminology proposed below makes sense ?

Copy link
Copy Markdown
Contributor

@kara kara Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's backwards for inputs and outputs, no? The public names end up as the keys after inverting, so wouldn't it be aliasToInput and aliasToOutput?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const * 3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about being more explicit by changing
${name}${this.val1}${this.val2} - ${Object.keys(simpleChanges).join(',')}
for
comp=${name} val1=${this.val1} val2=${this.val2} - changed=[${Object.getOwnPropertyNames(simpleChanges).join(',')] }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"(and not in update mode)" ?

Copy link
Copy Markdown
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments.

Can't wait to have the JIT compiler so that we can write smaller integration tests without having to compile (and review) by hand !

@marclaval
Copy link
Copy Markdown
Contributor Author

Thanks for your reviews, I've integrated your comments.

About the naming discussion, I've changed inputsNonMinified to inputsPropertyName as this dictionary is in fact not inverted as others. Still to be discussed ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove public

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A dict is from something to something

Copy link
Copy Markdown
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for me after my comments have been addressed.

Could you please open an issue for the alias naming ? Thanks.

Copy link
Copy Markdown
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, apart from the naming. @marclaval created an issue to discuss naming with @mhevery returns here: #22383

@vicb vicb added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 22, 2018
@ngbot
Copy link
Copy Markdown

ngbot bot commented Feb 22, 2018

I see that you just added the PR action: merge label, but the following checks are still failing:
    failure status "ci/circleci: lint" is failing
    failure status "ci/circleci: build" is failing
    failure missing required status "code-review/pullapprove"
    pending status "google3" is pending
    pending status "continuous-integration/travis-ci/pr" is pending
    pending 2 pending code reviews

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@vicb vicb closed this in 7effb00 Feb 23, 2018
@trotyl
Copy link
Copy Markdown
Contributor

trotyl commented Nov 14, 2018

@IgorMinar FYI, current NgOnChangesFeature implementation would not work with the Stage 3 Class fields proposal due to the semantic change, which defines the property on the instance and will not trigger prototype setter, I guess you may also want to argue for it in the framework authors meeting.

But it's still possible to make it work by wrapping the factory method instead and hook on instances.

@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants