refactor(ivy): Use AttributeMarker instead of NS (#23899)

- Removes NS enum
- Uses existing AttributeMarker
- Adds enum value NAMESPACE_URI

PR Close #23899
This commit is contained in:
Ben Lesh
2018-05-30 15:57:09 -07:00
committed by Victor Berchet
parent b415010222
commit 1208a35373
5 changed files with 17 additions and 27 deletions

View File

@ -262,7 +262,7 @@ export function injectAttribute(attrNameToInject: string): string|undefined {
for (let i = 0; i < attrs.length; i = i + 2) {
let attrName = attrs[i];
if (attrName === AttributeMarker.SELECT_ONLY) break;
if (attrName === 0) { // NS.FULL
if (attrName === AttributeMarker.NAMESPACE_URI) {
attrName = attrs[i += 2];
}
if (attrName == attrNameToInject) {

View File

@ -843,8 +843,7 @@ function setUpAttributes(native: RElement, attrs: TAttributes): void {
const isProc = isProceduralRenderer(renderer);
for (let i = 0; i < attrs.length; i += 2) {
let attrName = attrs[i];
if (attrName === 0) { // NS.FULL
// Namespaced attribute
if (attrName === AttributeMarker.NAMESPACE_URI) {
const attrNS = attrs[i + 1] as string;
attrName = attrs[i + 2] as string;
const attrVal = attrs[i + 3] as string;
@ -1516,7 +1515,7 @@ function generateInitialInputs(
const attrs = tNode.attrs !;
for (let i = 0; i < attrs.length; i += 2) {
const first = attrs[i];
const attrName = first === 0 ? attrs[i += 2] : first; // 0 = NS.FULL
const attrName = first === AttributeMarker.NAMESPACE_URI ? attrs[i += 2] : first;
const minifiedInputName = inputs[attrName];
const attrValue = attrs[i + 1];

View File

@ -12,18 +12,6 @@ import {LQueries} from './query';
import {RElement, RNode, RText} from './renderer';
import {LView, TData, TView} from './view';
/**
* Namespace attribute flags.
*/
export const enum NS {
/**
* Use the next value as the full namespaces URI, the values after that
* are then the name and the value, respectively.
*/
FULL = 0,
}
/**
* TNodeType corresponds to the TNode.type property. It contains information
* on how to map a particular set of bits in LNode.flags to the node type.
@ -172,7 +160,11 @@ export interface LProjectionNode extends LNode {
* items are not regular attributes and the processing should be adapted accordingly.
*/
export const enum AttributeMarker {
NS = 0, // namespace. Has to be repeated.
/**
* Use the next value as the full namespaces URI, the values after that
* are then the name and the value, respectively.
*/
NAMESPACE_URI = 0, // namespace. Has to be repeated.
/**
* This marker indicates that the following attribute names were extracted from bindings (ex.:
@ -188,7 +180,7 @@ export const enum AttributeMarker {
* - attribute names and values
* - special markers acting as flags to alter attributes processing.
*/
export type TAttributes = (string | AttributeMarker | NS)[];
export type TAttributes = (string | AttributeMarker)[];
/**
* LNode binding data (flyweight) for a particular node that is shared between all templates

View File

@ -107,8 +107,7 @@ function findAttrIndexInNode(name: string, attrs: TAttributes | null): number {
if (attrs === null) return -1;
for (let i = 0; i < attrs.length; i += step) {
const attrName = attrs[i];
if (attrName === 0) {
// NS.FULL
if (attrName === AttributeMarker.NAMESPACE_URI) {
step = 2;
} else if (attrName === name) {
return i;