Skip to content

Commit

Permalink
Merge pull request #768 from andrew703/new-function-fixed
Browse files Browse the repository at this point in the history
New function fixed
  • Loading branch information
errorrik committed Aug 1, 2023
2 parents 65cb897 + 55f78fc commit afa239f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/util/inherits.js
Expand Up @@ -18,7 +18,7 @@ var extend = require('./extend');
function inherits(subClass, superClass) {
/* jshint -W054 */
var subClassProto = subClass.prototype;
var F = new Function();
var F = function () {};
F.prototype = superClass.prototype;
subClass.prototype = new F();
subClass.prototype.constructor = subClass;
Expand Down
5 changes: 2 additions & 3 deletions src/view/component.js
Expand Up @@ -161,8 +161,7 @@ function Component(options) { // eslint-disable-line
var stumpText = stumpMatch[1];

// fill component data
options.data = (new Function('return '
+ stumpText
options.data = JSON.parse(stumpText
.replace(/^[\s\n]*/, '')
.replace(
/"(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.\d+Z"/g,
Expand All @@ -171,7 +170,7 @@ function Component(options) { // eslint-disable-line
+ ',' + (+h) + ',' + (+m) + ',' + (+s) + ')';
}
)
))();
);

if (firstCommentNode.previousSibling) {
removeEl(firstCommentNode.previousSibling);
Expand Down
5 changes: 3 additions & 2 deletions src/view/for-node.js
Expand Up @@ -23,6 +23,7 @@ var createNode = require('./create-node');
var createHydrateNode = require('./create-hydrate-node');
var nodeOwnSimpleDispose = require('./node-own-simple-dispose');
var nodeOwnCreateStump = require('./node-own-create-stump');
var bind = require('../util/bind');


/**
Expand Down Expand Up @@ -88,7 +89,7 @@ ForItemData.prototype.exprResolve = function (expr) {
)
};
break;

case this.indexName:
pathSeg = {
type: ExprType.NUMBER,
Expand Down Expand Up @@ -404,7 +405,7 @@ ForNode.prototype._updateArray = function (changes, newList) {
var childrenNeedUpdate = {};

var newLen = newList.length;
var getItemKey = this.aNode._gfk;
var getItemKey = bind(this.aNode._gfk, this.aNode);

/* eslint-disable no-redeclare */
for (var cIndex = 0; cIndex < changes.length; cIndex++) {
Expand Down
15 changes: 11 additions & 4 deletions src/view/preheat-a-node.js
Expand Up @@ -111,10 +111,17 @@ function preheatANode(aNode, componentInstance) {
&& trackBy.type === ExprType.ACCESSOR
&& trackBy.paths[0].value === directive.item
) {
aNode._gfk = new Function( // hotspot: getForKey
directive.item,
'return ' + directive.trackByRaw
);
aNode._gfk = function (data) { // hotspot: getForKey
var paths = this.directives.for.trackBy.paths || [];
var pathsLen = paths.length;
var value = data;
var key = '';
for (var i = 1; i < pathsLen; i++) {
key = paths[i].value;
value = value[key];
}
return value;
}
}
}
}
Expand Down

0 comments on commit afa239f

Please sign in to comment.