Skip to content

Conversation

matsko
Copy link
Contributor

@matsko matsko commented May 30, 2019

This commit is the final patch of the ivy styling algorithm refactor.
This patch swaps functionality from the old styling mechanism to the
new refactored code by changing the instruction code the compiler
generates and by pointing the runtime instruction code to the new
styling algorithm.

@matsko matsko force-pushed the styling_refactor_cleanup branch 3 times, most recently from edccdbf to e5b9bca Compare May 30, 2019 18:52
@matsko matsko requested a review from mhevery May 30, 2019 19:01
@matsko matsko force-pushed the styling_refactor_cleanup branch 3 times, most recently from 6d3f4b2 to c102bd8 Compare May 30, 2019 21:07
@ngbot ngbot bot added this to the needsTriage milestone May 30, 2019
@matsko matsko force-pushed the styling_refactor_cleanup branch from c102bd8 to 1c4b94a Compare June 2, 2019 22:03
@matsko matsko added the target: major This PR is targeted for the next major release label Jun 2, 2019
@matsko matsko force-pushed the styling_refactor_cleanup branch 12 times, most recently from 92813f8 to 91bdf16 Compare June 20, 2019 06:51
@matsko
Copy link
Contributor Author

matsko commented Jun 20, 2019

@@ -1172,7 +1158,7 @@ describe('compiler compliance: styling', () => {
expectEmit(result.source, template, 'Incorrect template');
});

it('should generate override instructions for only single-level styling bindings when !important is present',
it('should generate overridVjwjwe instructions for only single-level styling bindings when !important is present',
Copy link
Contributor

Choose a reason for hiding this comment

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

oops

}
if (rf & 2) {
$r3$.ɵɵproperty("id", ctx.id, null, true);
$r3$.ɵɵproperty("title", ctx.title, null, true);
$r3$.ɵɵstyleSanitizer($r3$.ɵɵdefaultStyleSanitizer);
Copy link
Contributor

Choose a reason for hiding this comment

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

If a sanitizer is not given explicitly, shouldn't it just use the default one?

Choose a reason for hiding this comment

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

This sounds reasonable to me, @matsko WDYT?

@@ -586,12 +586,7 @@ function createHostBindingsFunction(
name?: string): o.Expression|null {
// Initialize hostVarsCount to number of bound host properties (interpolations illegal),
// except 'style' and 'class' properties, since they should *not* allocate host var slots
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this comment is outdated now

@@ -324,62 +327,41 @@ class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugEleme
}

get classes(): {[key: string]: boolean;} {
const classes: {[key: string]: boolean;} = {};
let classes !: {[key: string]: boolean};
Copy link
Contributor

@alfaproject alfaproject Jun 20, 2019

Choose a reason for hiding this comment

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

Type should be: let classes: {[key: string]: boolean} | undefined;

But why not just return where it's set and avoid branching?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for this is because the if statement below assigns a new map and if it overwrites the value then you end up having an empty map be used for no reason.

Copy link
Contributor

@alfaproject alfaproject Jun 20, 2019

Choose a reason for hiding this comment

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

I mean this:

  get classes(): {[key: string]: boolean} {
    const element = this.nativeElement;
    if (element) {
      const context = loadLContextFromNode(element);
      const lView = context.lView;
      const tData = lView[TVIEW].data;
      const tNode = tData[context.nodeIndex] as TNode;
      if (tNode.classes) {
        if (isStylingContext(tNode.classes)) {
          return new NodeStylingDebug(tNode.classes as TStylingContext, lView, true).values;
        } else {
          return stylingMapToStringMap(tNode.classes);
        }
      }
    }
    return {};
  }

(removes 1 branch from the function)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see. Yes. Excellent contribution.

}

get styles(): {[key: string]: string | null;} {
const styles: {[key: string]: string | null;} = {};
let styles !: {[key: string]: string | null};
Copy link
Contributor

@alfaproject alfaproject Jun 20, 2019

Choose a reason for hiding this comment

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

Type should be: let styles: {[key: string]: string | null} | undefined;

But why not just return where it's set and avoid branching?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same thing here

@matsko matsko force-pushed the styling_refactor_cleanup branch from 73bef1b to 70eaea1 Compare June 28, 2019 18:08
// it's a container element or it's apart of a test
// environment that doesn't have styling. In either
// case it's safe not to apply styling to the element.
const nativeStyle = native.style;
if (value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@matsko it looks like we may need to adjust this check to take into account cases like the one described in #31345, where the value here would be 0 (with the type of number). My guess is that we may also have empty strings here, so may be we should check for null here, like:

  if (value !== null) {

It's not directly related to this PR, we can do it in a separate one once this PR lands.
Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good find. I will fix. Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

!= needs to be used in the event that the value is undefined.

@matsko matsko force-pushed the styling_refactor_cleanup branch 4 times, most recently from eceecbe to 675a2aa Compare July 11, 2019 23:38
@matsko matsko force-pushed the styling_refactor_cleanup branch 7 times, most recently from eaa6092 to db9fd9b Compare July 19, 2019 17:41
@matsko
Copy link
Contributor Author

matsko commented Jul 19, 2019

Copy link
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.

LGTM

@kara
Copy link
Contributor

kara commented Jul 19, 2019

@matsko Seeing a cyclic dependency issue in G3

packages/core/src/render3/util/view_utils.ts -> packages/core/public_api.ts -> 
packages/core/src/core.ts -> packages/core/src/metadata.ts -> 
packages/core/src/metadata/directives.ts -> packages/core/src/render3/jit/directive.ts -> 
packages/core/src/render3/jit/environment.ts -> packages/core/src/sanitization/sanitization.ts -> 
packages/core/src/render3/state.ts -> packages/core/src/render3/assert.ts -> 
packages/core/src/render3/util/view_utils.ts

Update: this failure is from master, not this PR. Seems like we'll need to get that patched/fixed before we can run a useful presubmit.

This commit is the final patch of the ivy styling algorithm refactor.
This patch swaps functionality from the old styling mechanism to the
new refactored code by changing the instruction code the compiler
generates and by pointing the runtime instruction code to the new
styling algorithm.
@matsko matsko force-pushed the styling_refactor_cleanup branch from 76810b0 to 05a41b3 Compare July 19, 2019 22:24
@matsko
Copy link
Contributor Author

matsko commented Jul 19, 2019

@kara kara unassigned matsko Jul 19, 2019
@kara kara added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Jul 19, 2019
@kara kara closed this in 9c954eb Jul 19, 2019
sabeersulaiman pushed a commit to sabeersulaiman/angular that referenced this pull request Sep 6, 2019
angular#30742)

This commit is the final patch of the ivy styling algorithm refactor.
This patch swaps functionality from the old styling mechanism to the
new refactored code by changing the instruction code the compiler
generates and by pointing the runtime instruction code to the new
styling algorithm.

PR Close angular#30742
@angular-automatic-lock-bot
Copy link

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 15, 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 merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants