Skip to content

Commit

Permalink
fix(binding-language): apply default modes to options props
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Dec 3, 2015
1 parent 8be5005 commit d025af9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/binding-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class TemplatingBindingLanguage extends BindingLanguage {
return info;
}

createAttributeInstruction(resources, element, theInfo, existingInstruction) {
createAttributeInstruction(resources, element, theInfo, existingInstruction, context) {
let instruction;

if (theInfo.expression) {
Expand All @@ -83,7 +83,8 @@ export class TemplatingBindingLanguage extends BindingLanguage {
resources,
element,
theInfo,
existingInstruction
existingInstruction,
context
);
}

Expand Down
24 changes: 14 additions & 10 deletions src/syntax-interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ export class SyntaxInterpreter {
this.eventManager = eventManager;
}

interpret(resources, element, info, existingInstruction) {
interpret(resources, element, info, existingInstruction, context) {
if (info.command in this) {
return this[info.command](resources, element, info, existingInstruction);
return this[info.command](resources, element, info, existingInstruction, context);
}

return this.handleUnknownCommand(resources, element, info, existingInstruction);
return this.handleUnknownCommand(resources, element, info, existingInstruction, context);
}

handleUnknownCommand(resources, element, info, existingInstruction) {
handleUnknownCommand(resources, element, info, existingInstruction, context) {
LogManager.getLogger('templating-binding').warn('Unknown binding command.', info);
return existingInstruction;
}

determineDefaultBindingMode(element, attrName) {
determineDefaultBindingMode(element, attrName, context) {
let tagName = element.tagName.toLowerCase();

if (tagName === 'input') {
Expand All @@ -46,17 +46,21 @@ export class SyntaxInterpreter {
return bindingMode.twoWay;
}

if (context && attrName in context.attributes) {
return context.attributes[attrName].defaultBindingMode || bindingMode.oneWay;
}

return bindingMode.oneWay;
}

bind(resources, element, info, existingInstruction) {
bind(resources, element, info, existingInstruction, context) {
let instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName);

instruction.attributes[info.attrName] = new BindingExpression(
this.observerLocator,
this.attributeMap[info.attrName] || info.attrName,
this.parser.parse(info.attrValue),
info.defaultBindingMode || this.determineDefaultBindingMode(element, info.attrName),
info.defaultBindingMode || this.determineDefaultBindingMode(element, info.attrName, context),
resources.lookupFunctions
);

Expand Down Expand Up @@ -98,7 +102,7 @@ export class SyntaxInterpreter {
return instruction;
}

options(resources, element, info, existingInstruction) {
options(resources, element, info, existingInstruction, context) {
let instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName);
let attrValue = info.attrValue;
let language = this.language;
Expand All @@ -113,7 +117,7 @@ export class SyntaxInterpreter {

if (current === ';') {
info = language.inspectAttribute(resources, name, target.trim());
language.createAttributeInstruction(resources, element, info, instruction);
language.createAttributeInstruction(resources, element, info, instruction, context);

if (!instruction.attributes[info.attrName]) {
instruction.attributes[info.attrName] = info.attrValue;
Expand All @@ -131,7 +135,7 @@ export class SyntaxInterpreter {

if (name !== null) {
info = language.inspectAttribute(resources, name, target.trim());
language.createAttributeInstruction(resources, element, info, instruction);
language.createAttributeInstruction(resources, element, info, instruction, context);

if (!instruction.attributes[info.attrName]) {
instruction.attributes[info.attrName] = info.attrValue;
Expand Down

0 comments on commit d025af9

Please sign in to comment.