Skip to content

Commit

Permalink
remove createEl & splitStr2Obj
Browse files Browse the repository at this point in the history
  • Loading branch information
errorrik committed Sep 29, 2023
1 parent 9e992fd commit a1bb69b
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 94 deletions.
19 changes: 16 additions & 3 deletions src/browser/auto-close-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,26 @@
* @file 自闭合标签表
*/

var splitStr2Obj = require('../util/split-str-2-obj');

/**
* 自闭合标签列表
*
* @type {Object}
*/
var autoCloseTags = splitStr2Obj('area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr');
var autoCloseTags = {
area: 1,
base: 1,
br: 1,
col: 1,
embed: 1,
hr: 1,
img: 1,
input: 1,
link: 1,
meta: 1,
param: 1,
source: 1,
track: 1,
wbr: 1
};

exports = module.exports = autoCloseTags;
35 changes: 26 additions & 9 deletions src/browser/bool-attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,36 @@
* @file bool属性表
*/


var splitStr2Obj = require('../util/split-str-2-obj');

/**
* bool属性表
*
* @type {Object}
*/
var boolAttrs = splitStr2Obj(
'allowpaymentrequest,async,autofocus,autoplay,'
+ 'checked,controls,default,defer,disabled,formnovalidate,'
+ 'hidden,ismap,itemscope,loop,multiple,muted,nomodule,novalidate,'
+ 'open,readonly,required,reversed,selected,typemustmatch'
);
var boolAttrs = {
allowpaymentrequest: 1,
async: 1,
autofocus: 1,
autoplay: 1,
checked: 1,
controls: 1,
default: 1,
defer: 1,
disabled: 1,
formnovalidate: 1,
hidden: 1,
ismap: 1,
itemscope: 1,
loop: 1,
multiple: 1,
muted: 1,
nomodule: 1,
novalidate: 1,
open: 1,
readonly: 1,
required: 1,
reversed: 1,
selected: 1,
typemustmatch: 1
};

exports = module.exports = boolAttrs;
26 changes: 0 additions & 26 deletions src/browser/create-el.js

This file was deleted.

41 changes: 34 additions & 7 deletions src/browser/hot-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,44 @@
* @file 常用标签表,用于 element 创建优化
*/

var splitStr2Obj = require('../util/split-str-2-obj');

/**
* 常用标签表
*
* @type {Object}
*/
var hotTags = splitStr2Obj(
'div,span,img,ul,ol,li,dl,dt,dd,a,b,u,hr,'
+ 'form,input,textarea,button,label,select,option,'
+ 'table,tbody,th,tr,td,thead,main,aside,header,footer,nav'
);
var hotTags = {
div: 1,
span: 1,
img: 1,
ul: 1,
ol: 1,
li: 1,
dl: 1,
dt: 1,
dd: 1,
a: 1,
b: 1,
u: 1,
hr: 1,
form: 1,
input: 1,
textarea: 1,
button: 1,
label: 1,
select: 1,
option: 1,
table: 1,
tbody: 1,
th: 1,
tr: 1,
td: 1,
thead: 1,
main: 1,
aside: 1,
header: 1,
footer: 1,
nav: 1

};

exports = module.exports = hotTags;
51 changes: 39 additions & 12 deletions src/browser/svg-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,69 @@
* @file SVG标签表
*/

var splitStr2Obj = require('../util/split-str-2-obj');

/**
* svgTags
*
* @see https://www.w3.org/TR/SVG/svgdtd.html 只取常用
* @type {Object}
*/
var svgTags = splitStr2Obj(''
var svgTags = {
// Animation elements
+ 'animate,animateMotion,animateTransform,'
animate: 1,
animateMotion: 1,
animateTransform: 1,

// Basic shapes
+ 'circle,ellipse,line,polygon,polyline,rect,'
circle: 1,
ellipse: 1,
line: 1,
polygon: 1,
polyline: 1,
rect: 1,

// Container elements
+ 'defs,g,marker,mask,missing-glyph,pattern,svg,symbol,'
defs: 1,
g: 1,
marker: 1,
mask: 1,
'missing-glyph': 1,
pattern: 1,
svg: 1,
'symbol': 1,

// Descriptive elements
+ 'desc,metadata,'
desc: 1,
metadata: 1,

// Font elements
+ 'font,font-face,'
font: 1,
'font-face': 1,

// Gradient elements
+ 'linearGradient,radialGradient,stop,'
linearGradient: 1,
radialGradient: 1,
stop: 1,

// Graphics elements
+ 'image,path,use,'
image: 1,
path: 1,
use: 1,

// Text elements
+ 'glyph,textPath,text,tref,tspan,'
glyph: 1,
textPath: 1,
text: 1,
tref: 1,
tspan: 1,

// Others
+ 'clipPath,cursor,filter,foreignObject,view'
);
clipPath: 1,
cursor: 1,
filter: 1,
foreignObject: 1,
view: 1
};


exports = module.exports = svgTags;
1 change: 0 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
// require('./browser/on');
// require('./browser/un');
// require('./browser/svg-tags');
// require('./browser/create-el');
// require('./browser/remove-el');
// require('./util/next-tick');
// require('./browser/ie');
Expand Down
29 changes: 0 additions & 29 deletions src/util/split-str-2-obj.js

This file was deleted.

5 changes: 4 additions & 1 deletion src/view/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var Data = require('../runtime/data');
var evalExpr = require('../runtime/eval-expr');
var changeExprCompare = require('../runtime/change-expr-compare');
var DataChangeType = require('../runtime/data-change-type');
var svgTags = require('../browser/svg-tags');
var insertBefore = require('../browser/insert-before');
var un = require('../browser/un');
var preprocessComponents = require('./preprocess-components');
Expand Down Expand Up @@ -1033,7 +1034,9 @@ Component.prototype.attach = function (parentEl, beforeEl) {
}
else {
props = aNode.props;
this.el = createEl(this.tagName);
this.el = svgTags[this.tagName] && document.createElementNS
? document.createElementNS('http://www.w3.org/2000/svg', this.tagName)
: document.createElement(this.tagName);
}

if (this._sbindData) {
Expand Down
5 changes: 4 additions & 1 deletion src/view/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
var changeExprCompare = require('../runtime/change-expr-compare');
var changesIsInDataRef = require('../runtime/changes-is-in-data-ref');
var evalExpr = require('../runtime/eval-expr');
var svgTags = require('../browser/svg-tags');
var insertBefore = require('../browser/insert-before');
var LifeCycle = require('./life-cycle');
var NodeType = require('./node-type');
Expand Down Expand Up @@ -125,7 +126,9 @@ Element.prototype.attach = function (parentEl, beforeEl) {
}
else {
props = aNode.props;
this.el = createEl(this.tagName);
this.el = svgTags[this.tagName] && document.createElementNS
? document.createElementNS('http://www.w3.org/2000/svg', this.tagName)
: document.createElement(this.tagName);
}

if (this._sbindData) {
Expand Down
6 changes: 5 additions & 1 deletion src/view/preheat-el.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
* @file ANode预热
*/

var svgTags = require('../browser/svg-tags');

/**
* ANode预热HTML元素,用于循环创建时clone
*
* @param {Object} aNode 要预热的ANode
* @return {HTMLElement}
*/
function preheatEl(aNode) {
var el = createEl(aNode.tagName);
var el = svgTags[aNode.tagName] && document.createElementNS
? document.createElementNS('http://www.w3.org/2000/svg', aNode.tagName)
: document.createElement(aNode.tagName);
aNode._el = el;

for (var i = 0, l = aNode.props.length; i < l; i++) {
Expand Down
7 changes: 4 additions & 3 deletions src/view/style-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
* @file 样式的基本属性
*/

var splitStr2Obj = require('../util/split-str-2-obj');

/**
* 元素的基本属性
*
* @type {Object}
*/
var styleProps = splitStr2Obj('class,style');
var styleProps = {
'class': 1,
style: 1
};

exports = module.exports = styleProps;
5 changes: 4 additions & 1 deletion src/view/template-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var Data = require('../runtime/data');
var evalExpr = require('../runtime/eval-expr');
var changeExprCompare = require('../runtime/change-expr-compare');
var DataChangeType = require('../runtime/data-change-type');
var svgTags = require('../browser/svg-tags');
var insertBefore = require('../browser/insert-before');
var createNode = require('./create-node');
var preheatEl = require('./preheat-el');
Expand Down Expand Up @@ -252,7 +253,9 @@ TemplateComponent.prototype.attach = function (parentEl, beforeEl) {
}
else {
props = aNode.props;
this.el = createEl(this.tagName);
this.el = svgTags[this.tagName] && document.createElementNS
? document.createElementNS('http://www.w3.org/2000/svg', this.tagName)
: document.createElement(this.tagName);
}

if (this._sbindData) {
Expand Down

0 comments on commit a1bb69b

Please sign in to comment.