Skip to content

Commit

Permalink
faster way of computing dependencies for 'm-model'
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed May 26, 2017
1 parent fa90210 commit 1002f79
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
32 changes: 22 additions & 10 deletions dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2276,9 +2276,6 @@
// Get attributes
var attrs = vnode.props.attrs;

// Compile a literal value for the getter
compileTemplateExpression(value, dependencies);

// Setup default event types and dom property to change
var eventType = "input";
var valueProp = "value";
Expand All @@ -2292,23 +2289,38 @@
// Generate event listener code
var keypath = value;

// Compute getter if dynamic
// Compute getter base if dynamic
var bracketIndex = value.indexOf("[");
var dotIndex = value.indexOf(".");
var base = null;
if (bracketIndex !== -1 && (dotIndex === -1 || bracketIndex < dotIndex)) {
base = value.slice(0, bracketIndex);
} else if (dotIndex !== -1 && (bracketIndex === -1 || dotIndex < bracketIndex)) {
base = value.slice(0, dotIndex);
}
if (base !== null) {
var dynamicPath = null;
var dynamicIndex = -1;

if (bracketIndex !== -1 && dotIndex !== -1) {
// Dynamic getter found,
// Extract base and dynamic path
if (bracketIndex < dotIndex) {
dynamicIndex = bracketIndex;
} else {
dynamicIndex = dotIndex;
}
base = value.substring(0, dynamicIndex);
dynamicPath = value.slice(-dynamicIndex);

// Add dependencies for the dynamic getter
compileTemplateExpression(value, dependencies);

// Replace string references with actual references
keypath = keypath.replace(expressionRE, function (match, reference) {
if (reference !== undefined && reference !== base) {
return '" + ' + reference + ' + "';
} else {
return match;
}
});
} else {
// Add dependencies for the simple getter
compileTemplateExpression(value.slice(-dynamicIndex), dependencies);
}

// Generate the listener
Expand Down
Loading

0 comments on commit 1002f79

Please sign in to comment.