chore(refactor): easier to make sense of attr-to-prop map (even if a bit reduntant)
This commit is contained in:
parent
757eae8ad3
commit
cbe7b8c671
|
@ -91,26 +91,12 @@ function roleSetter(element, value) {
|
|||
}
|
||||
}
|
||||
|
||||
// special mapping for cases where attribute name doesn't match property name
|
||||
var _lazyAttrToProp;
|
||||
|
||||
function attrToProp() {
|
||||
if (!isPresent(_lazyAttrToProp)) {
|
||||
_lazyAttrToProp = StringMapWrapper.merge({
|
||||
"inner-html": "innerHTML",
|
||||
"readonly": "readOnly",
|
||||
"tabindex": "tabIndex",
|
||||
}, DOM.attrToPropMap);
|
||||
}
|
||||
return _lazyAttrToProp;
|
||||
}
|
||||
|
||||
// tells if an attribute is handled by the ElementBinderBuilder step
|
||||
export function isSpecialProperty(propName:string) {
|
||||
return StringWrapper.startsWith(propName, ARIA_PREFIX)
|
||||
|| StringWrapper.startsWith(propName, CLASS_PREFIX)
|
||||
|| StringWrapper.startsWith(propName, STYLE_PREFIX)
|
||||
|| StringMapWrapper.contains(attrToProp(), propName);
|
||||
|| StringMapWrapper.contains(DOM.attrToPropMap, propName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -257,7 +243,7 @@ export class ElementBinderBuilder extends CompileStep {
|
|||
}
|
||||
|
||||
_resolvePropertyName(attrName:string) {
|
||||
var mappedPropName = StringMapWrapper.get(attrToProp(), attrName);
|
||||
var mappedPropName = StringMapWrapper.get(DOM.attrToPropMap, attrName);
|
||||
return isPresent(mappedPropName) ? mappedPropName : attrName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,10 +18,11 @@ class BrowserDomAdapter extends DomAdapter {
|
|||
setRootDomAdapter(new BrowserDomAdapter());
|
||||
}
|
||||
|
||||
// override JS logic of attribute to property mapping
|
||||
@override
|
||||
final attrToPropMap = const {
|
||||
"inner-html": "innerHtml"
|
||||
'inner-html': 'innerHtml',
|
||||
'readonly': 'readOnly',
|
||||
'tabindex': 'tabIndex',
|
||||
};
|
||||
|
||||
query(String selector) => document.querySelector(selector);
|
||||
|
@ -108,13 +109,13 @@ class BrowserDomAdapter extends DomAdapter {
|
|||
createScriptTag(String attrName, String attrValue,
|
||||
[HtmlDocument doc = null]) {
|
||||
if (doc == null) doc = document;
|
||||
var el = doc.createElement("SCRIPT");
|
||||
var el = doc.createElement('SCRIPT');
|
||||
el.setAttribute(attrName, attrValue);
|
||||
return el;
|
||||
}
|
||||
StyleElement createStyleElement(String css, [HtmlDocument doc = null]) {
|
||||
if (doc == null) doc = document;
|
||||
var el = doc.createElement("STYLE");
|
||||
var el = doc.createElement('STYLE');
|
||||
el.text = css;
|
||||
return el;
|
||||
}
|
||||
|
|
|
@ -2,15 +2,19 @@ import {List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
|
|||
import {isPresent} from 'angular2/src/facade/lang';
|
||||
import {DomAdapter, setRootDomAdapter} from './dom_adapter';
|
||||
|
||||
var EMPTY_MAP = MapWrapper.create();
|
||||
var _attrToPropMap = {
|
||||
'inner-html': 'innerHTML',
|
||||
'readonly': 'readOnly',
|
||||
'tabindex': 'tabIndex',
|
||||
};
|
||||
|
||||
export class BrowserDomAdapter extends DomAdapter {
|
||||
static makeCurrent() {
|
||||
setRootDomAdapter(new BrowserDomAdapter());
|
||||
}
|
||||
|
||||
get attrToPropMap():Map {
|
||||
return EMPTY_MAP
|
||||
get attrToPropMap() {
|
||||
return _attrToPropMap;
|
||||
}
|
||||
|
||||
query(selector) {
|
||||
|
@ -75,7 +79,7 @@ export class BrowserDomAdapter extends DomAdapter {
|
|||
return res;
|
||||
}
|
||||
clearNodes(el) {
|
||||
el.innerHTML = "";
|
||||
el.innerHTML = '';
|
||||
}
|
||||
appendChild(el, node) {
|
||||
el.appendChild(node);
|
||||
|
@ -133,7 +137,7 @@ export class BrowserDomAdapter extends DomAdapter {
|
|||
return doc.createTextNode(text);
|
||||
}
|
||||
createScriptTag(attrName:string, attrValue:string, doc=document) {
|
||||
var el = doc.createElement("SCRIPT");
|
||||
var el = doc.createElement('SCRIPT');
|
||||
el.setAttribute(attrName, attrValue);
|
||||
return el;
|
||||
}
|
||||
|
|
|
@ -15,9 +15,15 @@ function _abstract() {
|
|||
*/
|
||||
@ABSTRACT()
|
||||
export class DomAdapter {
|
||||
get attrToPropMap():Map {
|
||||
|
||||
/**
|
||||
* Maps attribute names to their corresponding property names for cases
|
||||
* where attribute name doesn't match property name.
|
||||
*/
|
||||
get attrToPropMap() {
|
||||
throw _abstract();
|
||||
}
|
||||
|
||||
parse(templateHtml:string) {
|
||||
throw _abstract();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue