refactor(ivy): move all styling configurations into TNodeFlags (#33540)

This patch gets rid of the configuration settings present in the
`TStylingContext` array that is used within the styling algorithm
for `[style]`, `[style.prop]`, `[class]` and `[class.name]` bindings.
These configurations now all live inside of the `TNodeFlags`.

PR Close #33540
This commit is contained in:
Matias Niemelä
2019-11-01 15:53:50 -07:00
committed by atscott
parent e89c2dd8d0
commit 41560b47c4
11 changed files with 369 additions and 292 deletions

View File

@ -632,9 +632,6 @@
{
"name": "getComponentViewByInstance"
},
{
"name": "getConfig"
},
{
"name": "getConstant"
},
@ -932,6 +929,9 @@
{
"name": "isForwardRef"
},
{
"name": "isHostStyling"
},
{
"name": "isHostStylingActive"
},
@ -1067,6 +1067,9 @@
{
"name": "patchConfig"
},
{
"name": "patchHostStylingFlag"
},
{
"name": "readPatchedData"
},

View File

@ -5,11 +5,22 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {registerBinding} from '@angular/core/src/render3/styling/bindings';
import {TStylingContext, TStylingNode} from '@angular/core/src/render3/interfaces/styling';
import {registerBinding as _registerBinding} from '@angular/core/src/render3/styling/bindings';
import {attachStylingDebugObject} from '@angular/core/src/render3/styling/styling_debug';
import {DEFAULT_GUARD_MASK_VALUE, allocTStylingContext} from '../../../src/render3/util/styling_utils';
function registerBinding(
context: TStylingContext, countId: number, sourceIndex: number, prop: string | null,
value: any) {
let tNode: TStylingNode = (context as any).tNode;
if (!tNode) {
tNode = (context as any).tNode = {flags: 0};
}
_registerBinding(context, tNode, countId, sourceIndex, prop, value, false, false);
}
describe('styling context', () => {
it('should register a series of entries into the context', () => {
const debug = makeContextWithDebug(false);
@ -111,7 +122,9 @@ describe('styling context', () => {
function makeContextWithDebug(isClassBased: boolean) {
const ctx = allocTStylingContext(null, false);
return attachStylingDebugObject(ctx, isClassBased);
const tNode: TStylingNode = {flags: 0};
(ctx as any).tNode = ctx;
return attachStylingDebugObject(ctx, tNode, isClassBased);
}
function buildGuardMask(...bindingIndices: number[]) {

View File

@ -5,6 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {TStylingNode} from '@angular/core/src/render3/interfaces/styling';
import {registerBinding} from '@angular/core/src/render3/styling/bindings';
import {NodeStylingDebug, attachStylingDebugObject} from '@angular/core/src/render3/styling/styling_debug';
import {allocTStylingContext} from '@angular/core/src/render3/util/styling_utils';
@ -15,12 +16,14 @@ describe('styling debugging tools', () => {
() => {
if (isIE()) return;
const debug = makeContextWithDebug(false);
const context = debug.context;
const data: any[] = [];
const d = new NodeStylingDebug(context, data, false);
const values = makeContextWithDebug(false);
const context = values.context;
const tNode = values.tNode;
registerBinding(context, 0, 0, 'width', null);
const data: any[] = [];
const d = new NodeStylingDebug(context, tNode, data, false);
registerBinding(context, tNode, 0, 0, 'width', null, false, false);
expect(d.summary).toEqual({
width: {
prop: 'width',
@ -29,7 +32,7 @@ describe('styling debugging tools', () => {
},
});
registerBinding(context, 0, 0, 'width', '100px');
registerBinding(context, tNode, 0, 0, 'width', '100px', false, false);
expect(d.summary).toEqual({
width: {
prop: 'width',
@ -41,7 +44,7 @@ describe('styling debugging tools', () => {
const someBindingIndex1 = 1;
data[someBindingIndex1] = '200px';
registerBinding(context, 0, 0, 'width', someBindingIndex1);
registerBinding(context, tNode, 0, 0, 'width', someBindingIndex1, false, false);
expect(d.summary).toEqual({
width: {
prop: 'width',
@ -53,7 +56,7 @@ describe('styling debugging tools', () => {
const someBindingIndex2 = 2;
data[someBindingIndex2] = '500px';
registerBinding(context, 0, 1, 'width', someBindingIndex2);
registerBinding(context, tNode, 0, 1, 'width', someBindingIndex2, false, false);
expect(d.summary).toEqual({
width: {
prop: 'width',
@ -66,8 +69,14 @@ describe('styling debugging tools', () => {
});
function makeContextWithDebug(isClassBased: boolean) {
const ctx = allocTStylingContext(null, false);
return attachStylingDebugObject(ctx, isClassBased);
const context = allocTStylingContext(null, false);
const tNode = createTStylingNode();
attachStylingDebugObject(context, tNode, isClassBased);
return {context, tNode};
}
function createTStylingNode(): TStylingNode {
return {flags: 0};
}
function isIE() {