From f9ea70c0b66318878371841c11e8431f72cac979 Mon Sep 17 00:00:00 2001 From: Rob Eisenberg Date: Tue, 13 Oct 2015 04:43:44 -0400 Subject: [PATCH] chore(all): prepare release 0.16.0 --- bower.json | 8 +- config.js | 90 +-- dist/amd/aurelia-templating-binding.d.ts | 13 +- dist/amd/aurelia-templating-binding.js | 224 ++----- dist/aurelia-templating-binding.d.ts | 13 +- dist/aurelia-templating-binding.js | 282 ++++----- dist/commonjs/aurelia-templating-binding.d.ts | 13 +- dist/commonjs/aurelia-templating-binding.js | 224 ++----- dist/es6/aurelia-templating-binding.d.ts | 13 +- dist/es6/aurelia-templating-binding.js | 282 ++++----- dist/system/aurelia-templating-binding.d.ts | 13 +- dist/system/aurelia-templating-binding.js | 227 +++---- doc/api.json | 562 ++++++++++++------ package.json | 38 +- src/binding-language.js | 34 +- 15 files changed, 892 insertions(+), 1144 deletions(-) diff --git a/bower.json b/bower.json index ac1fdfa..7244fdc 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-templating-binding", - "version": "0.15.0", + "version": "0.16.0", "description": "An implementation of the templating engine's Binding Language abstraction which uses a pluggable command syntax.", "keywords": [ "aurelia", @@ -18,8 +18,8 @@ "url": "http://github.com/aurelia/templating-binding" }, "dependencies": { - "aurelia-binding": "^0.9.0", - "aurelia-logging": "^0.7.0", - "aurelia-templating": "^0.15.0" + "aurelia-binding": "^0.10.0", + "aurelia-logging": "^0.8.0", + "aurelia-templating": "^0.16.0" } } diff --git a/config.js b/config.js index 9cda03b..a8812f6 100644 --- a/config.js +++ b/config.js @@ -14,59 +14,81 @@ System.config({ }, map: { - "aurelia-binding": "github:aurelia/binding@0.9.0", - "aurelia-logging": "github:aurelia/logging@0.7.0", - "aurelia-pal": "github:aurelia/pal@0.1.9", - "aurelia-pal-browser": "github:aurelia/pal-browser@0.1.12", - "aurelia-task-queue": "github:aurelia/task-queue@0.7.0", - "aurelia-templating": "github:aurelia/templating@0.15.0", + "aurelia-binding": "github:aurelia/binding@0.10.0", + "aurelia-logging": "github:aurelia/logging@0.8.0", + "aurelia-pal": "github:aurelia/pal@0.2.0", + "aurelia-pal-browser": "github:aurelia/pal-browser@0.2.0", + "aurelia-task-queue": "github:aurelia/task-queue@0.8.0", + "aurelia-templating": "github:aurelia/templating@0.16.0", "babel": "npm:babel-core@5.8.23", "babel-runtime": "npm:babel-runtime@5.8.20", "core-js": "npm:core-js@0.9.18", - "github:aurelia/binding@0.9.0": { - "aurelia-dependency-injection": "github:aurelia/dependency-injection@0.10.0", - "aurelia-metadata": "github:aurelia/metadata@0.8.0", - "aurelia-task-queue": "github:aurelia/task-queue@0.7.0", + "github:aurelia/binding@0.10.0": { + "aurelia-metadata": "github:aurelia/metadata@0.9.0", + "aurelia-pal": "github:aurelia/pal@0.2.0", + "aurelia-task-queue": "github:aurelia/task-queue@0.8.0", "core-js": "npm:core-js@0.9.18" }, - "github:aurelia/dependency-injection@0.10.0": { - "aurelia-logging": "github:aurelia/logging@0.7.0", - "aurelia-metadata": "github:aurelia/metadata@0.8.0", + "github:aurelia/dependency-injection@0.11.0": { + "aurelia-logging": "github:aurelia/logging@0.8.0", + "aurelia-metadata": "github:aurelia/metadata@0.9.0", + "aurelia-pal": "github:aurelia/pal@0.2.0", "core-js": "npm:core-js@0.9.18" }, - "github:aurelia/loader@0.9.0": { - "aurelia-html-template-element": "github:aurelia/html-template-element@0.3.0", - "aurelia-metadata": "github:aurelia/metadata@0.8.0", - "aurelia-path": "github:aurelia/path@0.9.0", - "core-js": "github:zloirock/core-js@0.8.4" + "github:aurelia/loader@0.10.0": { + "aurelia-metadata": "github:aurelia/metadata@0.9.0", + "aurelia-path": "github:aurelia/path@0.10.0" }, - "github:aurelia/metadata@0.8.0": { + "github:aurelia/metadata@0.9.0": { + "aurelia-pal": "github:aurelia/pal@0.2.0", "core-js": "npm:core-js@0.9.18" }, - "github:aurelia/pal-browser@0.1.12": { - "aurelia-pal": "github:aurelia/pal@0.1.9" + "github:aurelia/pal-browser@0.2.0": { + "aurelia-pal": "github:aurelia/pal@0.2.0" }, - "github:aurelia/templating@0.15.0": { - "aurelia-binding": "github:aurelia/binding@0.9.0", - "aurelia-dependency-injection": "github:aurelia/dependency-injection@0.10.0", - "aurelia-html-template-element": "github:aurelia/html-template-element@0.3.0", - "aurelia-loader": "github:aurelia/loader@0.9.0", - "aurelia-logging": "github:aurelia/logging@0.7.0", - "aurelia-metadata": "github:aurelia/metadata@0.8.0", - "aurelia-path": "github:aurelia/path@0.9.0", - "aurelia-task-queue": "github:aurelia/task-queue@0.7.0", + "github:aurelia/task-queue@0.8.0": { + "aurelia-pal": "github:aurelia/pal@0.2.0" + }, + "github:aurelia/templating@0.16.0": { + "aurelia-binding": "github:aurelia/binding@0.10.0", + "aurelia-dependency-injection": "github:aurelia/dependency-injection@0.11.0", + "aurelia-loader": "github:aurelia/loader@0.10.0", + "aurelia-logging": "github:aurelia/logging@0.8.0", + "aurelia-metadata": "github:aurelia/metadata@0.9.0", + "aurelia-pal": "github:aurelia/pal@0.2.0", + "aurelia-path": "github:aurelia/path@0.10.0", + "aurelia-task-queue": "github:aurelia/task-queue@0.8.0", "core-js": "npm:core-js@0.9.18" }, - "github:jspm/nodelibs-process@0.1.1": { - "process": "npm:process@0.10.1" + "github:jspm/nodelibs-assert@0.1.0": { + "assert": "npm:assert@1.3.0" + }, + "github:jspm/nodelibs-process@0.1.2": { + "process": "npm:process@0.11.2" + }, + "github:jspm/nodelibs-util@0.1.0": { + "util": "npm:util@0.10.3" + }, + "npm:assert@1.3.0": { + "util": "npm:util@0.10.3" }, "npm:babel-runtime@5.8.20": { - "process": "github:jspm/nodelibs-process@0.1.1" + "process": "github:jspm/nodelibs-process@0.1.2" }, "npm:core-js@0.9.18": { "fs": "github:jspm/nodelibs-fs@0.1.2", - "process": "github:jspm/nodelibs-process@0.1.1", + "process": "github:jspm/nodelibs-process@0.1.2", "systemjs-json": "github:systemjs/plugin-json@0.1.0" + }, + "npm:inherits@2.0.1": { + "util": "github:jspm/nodelibs-util@0.1.0" + }, + "npm:process@0.11.2": { + "assert": "github:jspm/nodelibs-assert@0.1.0" + }, + "npm:util@0.10.3": { + "inherits": "npm:inherits@2.0.1", + "process": "github:jspm/nodelibs-process@0.1.2" } } }); diff --git a/dist/amd/aurelia-templating-binding.d.ts b/dist/amd/aurelia-templating-binding.d.ts index 14b1f16..6bf2813 100644 --- a/dist/amd/aurelia-templating-binding.d.ts +++ b/dist/amd/aurelia-templating-binding.d.ts @@ -1,6 +1,6 @@ declare module 'aurelia-templating-binding' { import * as LogManager from 'aurelia-logging'; - import { Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, CallExpression, bindingMode, NameExpression } from 'aurelia-binding'; + import { Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, CallExpression, bindingMode, NameExpression, connectable } from 'aurelia-binding'; import { BehaviorInstruction, BindingLanguage } from 'aurelia-templating'; /*eslint dot-notation:0*/ @@ -15,6 +15,10 @@ declare module 'aurelia-templating-binding' { delegate(resources: any, element: any, info: any): any; call(resources: any, element: any, info: any, existingInstruction: any): any; options(resources: any, element: any, info: any, existingInstruction: any): any; + 'for'(resources: any, element: any, info: any, existingInstruction: any): any; + 'two-way'(resources: any, element: any, info: any, existingInstruction: any): any; + 'one-way'(resources: any, element: any, info: any, existingInstruction: any): any; + 'one-time'(resources: any, element: any, info: any, existingInstruction: any): any; } export class TemplatingBindingLanguage extends BindingLanguage { static inject(): any; @@ -30,12 +34,9 @@ declare module 'aurelia-templating-binding' { } class InterpolationBinding { constructor(observerLocator: any, parts: any, target: any, targetProperty: any, mode: any, valueConverterLookupFunction: any); - getObserver(obj: any, propertyName: any): any; bind(source: any): any; - setValue(): any; - partChanged(newValue: any, oldValue: any, connecting: any): any; - connect(): any; - interpolate(): any; + call(): any; + interpolate(connect: any, initial: any): any; unbind(): any; } export function configure(config: any): any; diff --git a/dist/amd/aurelia-templating-binding.js b/dist/amd/aurelia-templating-binding.js index 36e51d4..374d99c 100644 --- a/dist/amd/aurelia-templating-binding.js +++ b/dist/amd/aurelia-templating-binding.js @@ -125,64 +125,64 @@ define(['exports', 'aurelia-logging', 'aurelia-binding', 'aurelia-templating'], return instruction; }; - return SyntaxInterpreter; - })(); + SyntaxInterpreter.prototype['for'] = function _for(resources, element, info, existingInstruction) { + var parts = undefined; + var keyValue = undefined; + var instruction = undefined; + var attrValue = undefined; + var isDestructuring = undefined; - exports.SyntaxInterpreter = SyntaxInterpreter; + attrValue = info.attrValue; + isDestructuring = attrValue.match(/^ *[[].+[\]]/); + parts = isDestructuring ? attrValue.split('of ') : attrValue.split(' of '); - SyntaxInterpreter.prototype['for'] = function (resources, element, info, existingInstruction) { - var parts = undefined; - var keyValue = undefined; - var instruction = undefined; - var attrValue = undefined; - var isDestructuring = undefined; + if (parts.length !== 2) { + throw new Error('Incorrect syntax for "for". The form is: "$local of $items" or "[$key, $value] of $items".'); + } - attrValue = info.attrValue; - isDestructuring = attrValue.match(/[[].+[\]]/); - parts = isDestructuring ? attrValue.split('of ') : attrValue.split(' of '); + instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); - if (parts.length !== 2) { - throw new Error('Incorrect syntax for "for". The form is: "$local of $items" or "[$key, $value] of $items".'); - } + if (isDestructuring) { + keyValue = parts[0].replace(/[[\]]/g, '').replace(/,/g, ' ').replace(/\s+/g, ' ').trim().split(' '); + instruction.attributes.key = keyValue[0]; + instruction.attributes.value = keyValue[1]; + } else { + instruction.attributes.local = parts[0]; + } - instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); + instruction.attributes.items = new _aureliaBinding.BindingExpression(this.observerLocator, 'items', this.parser.parse(parts[1]), _aureliaBinding.bindingMode.oneWay, resources.valueConverterLookupFunction); - if (isDestructuring) { - keyValue = parts[0].replace(/[[\]]/g, '').replace(/,/g, ' ').replace(/\s+/g, ' ').trim().split(' '); - instruction.attributes.key = keyValue[0]; - instruction.attributes.value = keyValue[1]; - } else { - instruction.attributes.local = parts[0]; - } + return instruction; + }; - instruction.attributes.items = new _aureliaBinding.BindingExpression(this.observerLocator, 'items', this.parser.parse(parts[1]), _aureliaBinding.bindingMode.oneWay, resources.valueConverterLookupFunction); + SyntaxInterpreter.prototype['two-way'] = function twoWay(resources, element, info, existingInstruction) { + var instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); - return instruction; - }; + instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.bindingMode.twoWay, resources.valueConverterLookupFunction); - SyntaxInterpreter.prototype['two-way'] = function (resources, element, info, existingInstruction) { - var instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); + return instruction; + }; - instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.bindingMode.twoWay, resources.valueConverterLookupFunction); + SyntaxInterpreter.prototype['one-way'] = function oneWay(resources, element, info, existingInstruction) { + var instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); - return instruction; - }; + instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.bindingMode.oneWay, resources.valueConverterLookupFunction); - SyntaxInterpreter.prototype['one-way'] = function (resources, element, info, existingInstruction) { - var instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); + return instruction; + }; - instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.bindingMode.oneWay, resources.valueConverterLookupFunction); + SyntaxInterpreter.prototype['one-time'] = function oneTime(resources, element, info, existingInstruction) { + var instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); - return instruction; - }; + instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.bindingMode.oneTime, resources.valueConverterLookupFunction); - SyntaxInterpreter.prototype['one-time'] = function (resources, element, info, existingInstruction) { - var instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); + return instruction; + }; - instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.bindingMode.oneTime, resources.valueConverterLookupFunction); + return SyntaxInterpreter; + })(); - return instruction; - }; + exports.SyntaxInterpreter = SyntaxInterpreter; var info = {}; var logger = _aureliaLogging.getLogger('templating-binding'); @@ -381,7 +381,7 @@ define(['exports', 'aurelia-logging', 'aurelia-binding', 'aurelia-templating'], var InterpolationBinding = (function () { function InterpolationBinding(observerLocator, parts, target, targetProperty, mode, valueConverterLookupFunction) { - _classCallCheck(this, InterpolationBinding); + _classCallCheck(this, _InterpolationBinding); if (targetProperty === 'style') { logger.info('Internet Explorer does not support interpolation in "style" attributes. Use the style attribute\'s alias, "css" instead.'); @@ -394,146 +394,54 @@ define(['exports', 'aurelia-logging', 'aurelia-binding', 'aurelia-templating'], this.targetProperty = observerLocator.getObserver(target, targetProperty); this.mode = mode; this.valueConverterLookupFunction = valueConverterLookupFunction; - this.toDispose = []; } - InterpolationBinding.prototype.getObserver = function getObserver(obj, propertyName) { - return this.observerLocator.getObserver(obj, propertyName); - }; - InterpolationBinding.prototype.bind = function bind(source) { - this.source = source; - - if (this.mode === _aureliaBinding.bindingMode.oneWay) { + if (this.source !== undefined) { this.unbind(); - this.connect(); - this.setValue(); - } else { - this.setValue(); - } - }; - - InterpolationBinding.prototype.setValue = function setValue() { - var value = this.interpolate(); - this.targetProperty.setValue(value); - }; - - InterpolationBinding.prototype.partChanged = function partChanged(newValue, oldValue, connecting) { - var _this = this; - - var map = undefined; - var data = undefined; - - if (!connecting) { - this.setValue(); - } - - if (oldValue instanceof Array) { - map = this.arrayPartMap; - data = map ? map.get(oldValue) : null; - if (data) { - data.refs--; - if (data.refs === 0) { - data.dispose(); - map['delete'](oldValue); - } - } - } - - if (newValue instanceof Array) { - map = this.arrayPartMap || (this.arrayPartMap = new Map()); - data = map.get(newValue); - if (!data) { - data = { - refs: 0, - dispose: this.observerLocator.getArrayObserver(newValue).subscribe(function () { - return _this.setValue(); - }) - }; - - map.set(newValue, data); - } - data.refs++; } + this.source = source; + this.interpolate(this.mode === _aureliaBinding.bindingMode.oneWay, true); }; - InterpolationBinding.prototype.connect = function connect() { - var result = undefined; - var parts = this.parts; - var source = this.source; - var toDispose = this.toDispose = []; - var partChanged = this.partChanged.bind(this); - var i = undefined; - var ii = undefined; - - for (i = 0, ii = parts.length; i < ii; ++i) { - if (i % 2 !== 0) { - result = parts[i].connect(this, source); - if (result.observer) { - toDispose.push(result.observer.subscribe(partChanged)); - } - if (result.value instanceof Array) { - partChanged(result.value, undefined, true); - } - } - } + InterpolationBinding.prototype.call = function call() { + this._version++; + this.interpolate(this.mode === _aureliaBinding.bindingMode.oneWay, false); }; - InterpolationBinding.prototype.interpolate = function interpolate() { + InterpolationBinding.prototype.interpolate = function interpolate(connect, initial) { var value = ''; var parts = this.parts; var source = this.source; var valueConverterLookupFunction = this.valueConverterLookupFunction; - var i = undefined; - var ii = undefined; - var temp = undefined; - for (i = 0, ii = parts.length; i < ii; ++i) { + for (var i = 0, ii = parts.length; i < ii; ++i) { if (i % 2 === 0) { value += parts[i]; } else { - temp = parts[i].evaluate(source, valueConverterLookupFunction); - value += typeof temp !== 'undefined' && temp !== null ? temp.toString() : ''; + var part = parts[i].evaluate(source, valueConverterLookupFunction); + value += part === undefined || part === null ? '' : part.toString(); + if (connect) { + parts[i].connect(this, source); + if (part instanceof Array) { + this.observeArray(part); + } + } } } - - return value; + this.targetProperty.setValue(value); + if (!initial) { + this.unobserve(false); + } }; InterpolationBinding.prototype.unbind = function unbind() { - var i = undefined; - var ii = undefined; - var toDispose = this.toDispose; - var map = this.arrayPartMap; - - if (toDispose) { - for (i = 0, ii = toDispose.length; i < ii; ++i) { - toDispose[i](); - } - } - - this.toDispose = null; - - if (map) { - for (var _iterator = map.values(), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - if (_isArray) { - if (_i >= _iterator.length) break; - toDispose = _iterator[_i++]; - } else { - _i = _iterator.next(); - if (_i.done) break; - toDispose = _i.value; - } - - toDispose.dispose(); - } - - map.clear(); - } - - this.arrayPartMap = null; + this.source = undefined; + this.unobserve(true); }; + var _InterpolationBinding = InterpolationBinding; + InterpolationBinding = _aureliaBinding.connectable()(InterpolationBinding) || InterpolationBinding; return InterpolationBinding; })(); diff --git a/dist/aurelia-templating-binding.d.ts b/dist/aurelia-templating-binding.d.ts index 14b1f16..6bf2813 100644 --- a/dist/aurelia-templating-binding.d.ts +++ b/dist/aurelia-templating-binding.d.ts @@ -1,6 +1,6 @@ declare module 'aurelia-templating-binding' { import * as LogManager from 'aurelia-logging'; - import { Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, CallExpression, bindingMode, NameExpression } from 'aurelia-binding'; + import { Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, CallExpression, bindingMode, NameExpression, connectable } from 'aurelia-binding'; import { BehaviorInstruction, BindingLanguage } from 'aurelia-templating'; /*eslint dot-notation:0*/ @@ -15,6 +15,10 @@ declare module 'aurelia-templating-binding' { delegate(resources: any, element: any, info: any): any; call(resources: any, element: any, info: any, existingInstruction: any): any; options(resources: any, element: any, info: any, existingInstruction: any): any; + 'for'(resources: any, element: any, info: any, existingInstruction: any): any; + 'two-way'(resources: any, element: any, info: any, existingInstruction: any): any; + 'one-way'(resources: any, element: any, info: any, existingInstruction: any): any; + 'one-time'(resources: any, element: any, info: any, existingInstruction: any): any; } export class TemplatingBindingLanguage extends BindingLanguage { static inject(): any; @@ -30,12 +34,9 @@ declare module 'aurelia-templating-binding' { } class InterpolationBinding { constructor(observerLocator: any, parts: any, target: any, targetProperty: any, mode: any, valueConverterLookupFunction: any); - getObserver(obj: any, propertyName: any): any; bind(source: any): any; - setValue(): any; - partChanged(newValue: any, oldValue: any, connecting: any): any; - connect(): any; - interpolate(): any; + call(): any; + interpolate(connect: any, initial: any): any; unbind(): any; } export function configure(config: any): any; diff --git a/dist/aurelia-templating-binding.js b/dist/aurelia-templating-binding.js index 98f14b6..acfad3e 100644 --- a/dist/aurelia-templating-binding.js +++ b/dist/aurelia-templating-binding.js @@ -1,5 +1,5 @@ import * as LogManager from 'aurelia-logging'; -import {Parser,ObserverLocator,EventManager,ListenerExpression,BindingExpression,CallExpression,bindingMode,NameExpression} from 'aurelia-binding'; +import {Parser,ObserverLocator,EventManager,ListenerExpression,BindingExpression,CallExpression,bindingMode,NameExpression,connectable} from 'aurelia-binding'; import {BehaviorInstruction,BindingLanguage} from 'aurelia-templating'; /*eslint dot-notation:0*/ @@ -137,92 +137,92 @@ export class SyntaxInterpreter { return instruction; } -} -SyntaxInterpreter.prototype['for'] = function(resources, element, info, existingInstruction) { - let parts; - let keyValue; - let instruction; - let attrValue; - let isDestructuring; + 'for'(resources, element, info, existingInstruction) { + let parts; + let keyValue; + let instruction; + let attrValue; + let isDestructuring; - attrValue = info.attrValue; - isDestructuring = attrValue.match(/[[].+[\]]/); - parts = isDestructuring ? attrValue.split('of ') : attrValue.split(' of '); + attrValue = info.attrValue; + isDestructuring = attrValue.match(/^ *[[].+[\]]/); + parts = isDestructuring ? attrValue.split('of ') : attrValue.split(' of '); - if (parts.length !== 2) { - throw new Error('Incorrect syntax for "for". The form is: "$local of $items" or "[$key, $value] of $items".'); - } + if (parts.length !== 2) { + throw new Error('Incorrect syntax for "for". The form is: "$local of $items" or "[$key, $value] of $items".'); + } - instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); + instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); - if (isDestructuring) { - keyValue = parts[0].replace(/[[\]]/g, '').replace(/,/g, ' ').replace(/\s+/g, ' ').trim().split(' '); - instruction.attributes.key = keyValue[0]; - instruction.attributes.value = keyValue[1]; - } else { - instruction.attributes.local = parts[0]; + if (isDestructuring) { + keyValue = parts[0].replace(/[[\]]/g, '').replace(/,/g, ' ').replace(/\s+/g, ' ').trim().split(' '); + instruction.attributes.key = keyValue[0]; + instruction.attributes.value = keyValue[1]; + } else { + instruction.attributes.local = parts[0]; + } + + instruction.attributes.items = new BindingExpression( + this.observerLocator, + 'items', + this.parser.parse(parts[1]), + bindingMode.oneWay, + resources.valueConverterLookupFunction + ); + + return instruction; } - instruction.attributes.items = new BindingExpression( - this.observerLocator, - 'items', - this.parser.parse(parts[1]), - bindingMode.oneWay, - resources.valueConverterLookupFunction - ); + 'two-way'(resources, element, info, existingInstruction) { + let instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); - return instruction; -}; + instruction.attributes[info.attrName] = new BindingExpression( + this.observerLocator, + this.attributeMap[info.attrName] || info.attrName, + this.parser.parse(info.attrValue), + bindingMode.twoWay, + resources.valueConverterLookupFunction + ); -SyntaxInterpreter.prototype['two-way'] = function(resources, element, info, existingInstruction) { - let instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); + return instruction; + } + + 'one-way'(resources, element, info, existingInstruction) { + let instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); - instruction.attributes[info.attrName] = new BindingExpression( + instruction.attributes[info.attrName] = new BindingExpression( this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), - bindingMode.twoWay, + bindingMode.oneWay, resources.valueConverterLookupFunction ); - return instruction; -}; - -SyntaxInterpreter.prototype['one-way'] = function(resources, element, info, existingInstruction) { - 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), - bindingMode.oneWay, - resources.valueConverterLookupFunction - ); - - return instruction; -}; + return instruction; + } -SyntaxInterpreter.prototype['one-time'] = function(resources, element, info, existingInstruction) { - let instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); + 'one-time'(resources, element, info, existingInstruction) { + 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), - bindingMode.oneTime, - resources.valueConverterLookupFunction - ); + instruction.attributes[info.attrName] = new BindingExpression( + this.observerLocator, + this.attributeMap[info.attrName] || info.attrName, + this.parser.parse(info.attrValue), + bindingMode.oneTime, + resources.valueConverterLookupFunction + ); - return instruction; -}; + return instruction; + } +} let info = {}; let logger = LogManager.getLogger('templating-binding'); export class TemplatingBindingLanguage extends BindingLanguage { static inject() { return [Parser, ObserverLocator, SyntaxInterpreter]; } - constructor(parser, observerLocator, syntaxInterpreter) { + constructor(parser, observerLocator, syntaxInterpreter) { super(); this.parser = parser; this.observerLocator = observerLocator; @@ -284,27 +284,27 @@ export class TemplatingBindingLanguage extends BindingLanguage { } createAttributeInstruction(resources, element, theInfo, existingInstruction) { - let instruction; - - if (theInfo.expression) { - if (theInfo.attrName === 'ref') { - return theInfo.expression; - } + let instruction; - instruction = existingInstruction || BehaviorInstruction.attribute(theInfo.attrName); - instruction.attributes[theInfo.attrName] = theInfo.expression; - } else if (theInfo.command) { - instruction = this.syntaxInterpreter.interpret( - resources, - element, - theInfo, - existingInstruction - ); + if (theInfo.expression) { + if (theInfo.attrName === 'ref') { + return theInfo.expression; } - return instruction; + instruction = existingInstruction || BehaviorInstruction.attribute(theInfo.attrName); + instruction.attributes[theInfo.attrName] = theInfo.expression; + } else if (theInfo.command) { + instruction = this.syntaxInterpreter.interpret( + resources, + element, + theInfo, + existingInstruction + ); } + return instruction; +} + parseText(resources, value) { return this.parseContent(resources, 'textContent', value); } @@ -420,6 +420,7 @@ export class InterpolationBindingExpression { } } +@connectable() class InterpolationBinding { constructor(observerLocator, parts, target, targetProperty, mode, valueConverterLookupFunction) { if (targetProperty === 'style') { @@ -433,131 +434,50 @@ class InterpolationBinding { this.targetProperty = observerLocator.getObserver(target, targetProperty); this.mode = mode; this.valueConverterLookupFunction = valueConverterLookupFunction; - this.toDispose = []; - } - - getObserver(obj, propertyName) { - return this.observerLocator.getObserver(obj, propertyName); } bind(source) { - this.source = source; - - if (this.mode === bindingMode.oneWay) { + if (this.source !== undefined) { this.unbind(); - this.connect(); - this.setValue(); - } else { - this.setValue(); } + this.source = source; + this.interpolate(this.mode === bindingMode.oneWay, true); } - setValue() { - let value = this.interpolate(); - this.targetProperty.setValue(value); - } - - partChanged(newValue, oldValue, connecting) { - let map; - let data; - - if (!connecting) { - this.setValue(); - } - - if (oldValue instanceof Array) { - map = this.arrayPartMap; - data = map ? map.get(oldValue) : null; - if (data) { - data.refs--; - if (data.refs === 0) { - data.dispose(); - map.delete(oldValue); - } - } - } - - if (newValue instanceof Array) { - map = this.arrayPartMap || (this.arrayPartMap = new Map()); - data = map.get(newValue); - if (!data) { - data = { - refs: 0, - dispose: this.observerLocator.getArrayObserver(newValue).subscribe(() => this.setValue()) - }; - - map.set(newValue, data); - } - data.refs++; - } + call() { + this._version++; + this.interpolate(this.mode === bindingMode.oneWay, false); } - connect() { - let result; - let parts = this.parts; - let source = this.source; - let toDispose = this.toDispose = []; - let partChanged = this.partChanged.bind(this); - let i; - let ii; - - for (i = 0, ii = parts.length; i < ii; ++i) { - if (i % 2 !== 0) { - result = parts[i].connect(this, source); - if (result.observer) { - toDispose.push(result.observer.subscribe(partChanged)); - } - if (result.value instanceof Array) { - partChanged(result.value, undefined, true); - } - } - } - } - - interpolate() { + interpolate(connect, initial) { let value = ''; let parts = this.parts; let source = this.source; let valueConverterLookupFunction = this.valueConverterLookupFunction; - let i; - let ii; - let temp; - for (i = 0, ii = parts.length; i < ii; ++i) { + for (let i = 0, ii = parts.length; i < ii; ++i) { if (i % 2 === 0) { value += parts[i]; } else { - temp = parts[i].evaluate(source, valueConverterLookupFunction); - value += (typeof temp !== 'undefined' && temp !== null ? temp.toString() : ''); + let part = parts[i].evaluate(source, valueConverterLookupFunction); + value += part === undefined || part === null ? '' : part.toString(); + if (connect) { + parts[i].connect(this, source); + if (part instanceof Array) { + this.observeArray(part); + } + } } } - - return value; + this.targetProperty.setValue(value); + if (!initial) { + this.unobserve(false); + } } unbind() { - let i; - let ii; - let toDispose = this.toDispose; - let map = this.arrayPartMap; - - if (toDispose) { - for (i = 0, ii = toDispose.length; i < ii; ++i) { - toDispose[i](); - } - } - - this.toDispose = null; - - if (map) { - for (toDispose of map.values()) { - toDispose.dispose(); - } - - map.clear(); - } - - this.arrayPartMap = null; + this.source = undefined; + this.unobserve(true); } } diff --git a/dist/commonjs/aurelia-templating-binding.d.ts b/dist/commonjs/aurelia-templating-binding.d.ts index 14b1f16..6bf2813 100644 --- a/dist/commonjs/aurelia-templating-binding.d.ts +++ b/dist/commonjs/aurelia-templating-binding.d.ts @@ -1,6 +1,6 @@ declare module 'aurelia-templating-binding' { import * as LogManager from 'aurelia-logging'; - import { Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, CallExpression, bindingMode, NameExpression } from 'aurelia-binding'; + import { Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, CallExpression, bindingMode, NameExpression, connectable } from 'aurelia-binding'; import { BehaviorInstruction, BindingLanguage } from 'aurelia-templating'; /*eslint dot-notation:0*/ @@ -15,6 +15,10 @@ declare module 'aurelia-templating-binding' { delegate(resources: any, element: any, info: any): any; call(resources: any, element: any, info: any, existingInstruction: any): any; options(resources: any, element: any, info: any, existingInstruction: any): any; + 'for'(resources: any, element: any, info: any, existingInstruction: any): any; + 'two-way'(resources: any, element: any, info: any, existingInstruction: any): any; + 'one-way'(resources: any, element: any, info: any, existingInstruction: any): any; + 'one-time'(resources: any, element: any, info: any, existingInstruction: any): any; } export class TemplatingBindingLanguage extends BindingLanguage { static inject(): any; @@ -30,12 +34,9 @@ declare module 'aurelia-templating-binding' { } class InterpolationBinding { constructor(observerLocator: any, parts: any, target: any, targetProperty: any, mode: any, valueConverterLookupFunction: any); - getObserver(obj: any, propertyName: any): any; bind(source: any): any; - setValue(): any; - partChanged(newValue: any, oldValue: any, connecting: any): any; - connect(): any; - interpolate(): any; + call(): any; + interpolate(connect: any, initial: any): any; unbind(): any; } export function configure(config: any): any; diff --git a/dist/commonjs/aurelia-templating-binding.js b/dist/commonjs/aurelia-templating-binding.js index 6df23e2..1a40a38 100644 --- a/dist/commonjs/aurelia-templating-binding.js +++ b/dist/commonjs/aurelia-templating-binding.js @@ -134,64 +134,64 @@ var SyntaxInterpreter = (function () { return instruction; }; - return SyntaxInterpreter; -})(); + SyntaxInterpreter.prototype['for'] = function _for(resources, element, info, existingInstruction) { + var parts = undefined; + var keyValue = undefined; + var instruction = undefined; + var attrValue = undefined; + var isDestructuring = undefined; -exports.SyntaxInterpreter = SyntaxInterpreter; + attrValue = info.attrValue; + isDestructuring = attrValue.match(/^ *[[].+[\]]/); + parts = isDestructuring ? attrValue.split('of ') : attrValue.split(' of '); -SyntaxInterpreter.prototype['for'] = function (resources, element, info, existingInstruction) { - var parts = undefined; - var keyValue = undefined; - var instruction = undefined; - var attrValue = undefined; - var isDestructuring = undefined; + if (parts.length !== 2) { + throw new Error('Incorrect syntax for "for". The form is: "$local of $items" or "[$key, $value] of $items".'); + } - attrValue = info.attrValue; - isDestructuring = attrValue.match(/[[].+[\]]/); - parts = isDestructuring ? attrValue.split('of ') : attrValue.split(' of '); + instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); - if (parts.length !== 2) { - throw new Error('Incorrect syntax for "for". The form is: "$local of $items" or "[$key, $value] of $items".'); - } + if (isDestructuring) { + keyValue = parts[0].replace(/[[\]]/g, '').replace(/,/g, ' ').replace(/\s+/g, ' ').trim().split(' '); + instruction.attributes.key = keyValue[0]; + instruction.attributes.value = keyValue[1]; + } else { + instruction.attributes.local = parts[0]; + } - instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); + instruction.attributes.items = new _aureliaBinding.BindingExpression(this.observerLocator, 'items', this.parser.parse(parts[1]), _aureliaBinding.bindingMode.oneWay, resources.valueConverterLookupFunction); - if (isDestructuring) { - keyValue = parts[0].replace(/[[\]]/g, '').replace(/,/g, ' ').replace(/\s+/g, ' ').trim().split(' '); - instruction.attributes.key = keyValue[0]; - instruction.attributes.value = keyValue[1]; - } else { - instruction.attributes.local = parts[0]; - } + return instruction; + }; - instruction.attributes.items = new _aureliaBinding.BindingExpression(this.observerLocator, 'items', this.parser.parse(parts[1]), _aureliaBinding.bindingMode.oneWay, resources.valueConverterLookupFunction); + SyntaxInterpreter.prototype['two-way'] = function twoWay(resources, element, info, existingInstruction) { + var instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); - return instruction; -}; + instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.bindingMode.twoWay, resources.valueConverterLookupFunction); -SyntaxInterpreter.prototype['two-way'] = function (resources, element, info, existingInstruction) { - var instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); + return instruction; + }; - instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.bindingMode.twoWay, resources.valueConverterLookupFunction); + SyntaxInterpreter.prototype['one-way'] = function oneWay(resources, element, info, existingInstruction) { + var instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); - return instruction; -}; + instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.bindingMode.oneWay, resources.valueConverterLookupFunction); -SyntaxInterpreter.prototype['one-way'] = function (resources, element, info, existingInstruction) { - var instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); + return instruction; + }; - instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.bindingMode.oneWay, resources.valueConverterLookupFunction); + SyntaxInterpreter.prototype['one-time'] = function oneTime(resources, element, info, existingInstruction) { + var instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); - return instruction; -}; + instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.bindingMode.oneTime, resources.valueConverterLookupFunction); -SyntaxInterpreter.prototype['one-time'] = function (resources, element, info, existingInstruction) { - var instruction = existingInstruction || _aureliaTemplating.BehaviorInstruction.attribute(info.attrName); + return instruction; + }; - instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.bindingMode.oneTime, resources.valueConverterLookupFunction); + return SyntaxInterpreter; +})(); - return instruction; -}; +exports.SyntaxInterpreter = SyntaxInterpreter; var info = {}; var logger = LogManager.getLogger('templating-binding'); @@ -390,7 +390,7 @@ exports.InterpolationBindingExpression = InterpolationBindingExpression; var InterpolationBinding = (function () { function InterpolationBinding(observerLocator, parts, target, targetProperty, mode, valueConverterLookupFunction) { - _classCallCheck(this, InterpolationBinding); + _classCallCheck(this, _InterpolationBinding); if (targetProperty === 'style') { logger.info('Internet Explorer does not support interpolation in "style" attributes. Use the style attribute\'s alias, "css" instead.'); @@ -403,146 +403,54 @@ var InterpolationBinding = (function () { this.targetProperty = observerLocator.getObserver(target, targetProperty); this.mode = mode; this.valueConverterLookupFunction = valueConverterLookupFunction; - this.toDispose = []; } - InterpolationBinding.prototype.getObserver = function getObserver(obj, propertyName) { - return this.observerLocator.getObserver(obj, propertyName); - }; - InterpolationBinding.prototype.bind = function bind(source) { - this.source = source; - - if (this.mode === _aureliaBinding.bindingMode.oneWay) { + if (this.source !== undefined) { this.unbind(); - this.connect(); - this.setValue(); - } else { - this.setValue(); - } - }; - - InterpolationBinding.prototype.setValue = function setValue() { - var value = this.interpolate(); - this.targetProperty.setValue(value); - }; - - InterpolationBinding.prototype.partChanged = function partChanged(newValue, oldValue, connecting) { - var _this = this; - - var map = undefined; - var data = undefined; - - if (!connecting) { - this.setValue(); - } - - if (oldValue instanceof Array) { - map = this.arrayPartMap; - data = map ? map.get(oldValue) : null; - if (data) { - data.refs--; - if (data.refs === 0) { - data.dispose(); - map['delete'](oldValue); - } - } - } - - if (newValue instanceof Array) { - map = this.arrayPartMap || (this.arrayPartMap = new Map()); - data = map.get(newValue); - if (!data) { - data = { - refs: 0, - dispose: this.observerLocator.getArrayObserver(newValue).subscribe(function () { - return _this.setValue(); - }) - }; - - map.set(newValue, data); - } - data.refs++; } + this.source = source; + this.interpolate(this.mode === _aureliaBinding.bindingMode.oneWay, true); }; - InterpolationBinding.prototype.connect = function connect() { - var result = undefined; - var parts = this.parts; - var source = this.source; - var toDispose = this.toDispose = []; - var partChanged = this.partChanged.bind(this); - var i = undefined; - var ii = undefined; - - for (i = 0, ii = parts.length; i < ii; ++i) { - if (i % 2 !== 0) { - result = parts[i].connect(this, source); - if (result.observer) { - toDispose.push(result.observer.subscribe(partChanged)); - } - if (result.value instanceof Array) { - partChanged(result.value, undefined, true); - } - } - } + InterpolationBinding.prototype.call = function call() { + this._version++; + this.interpolate(this.mode === _aureliaBinding.bindingMode.oneWay, false); }; - InterpolationBinding.prototype.interpolate = function interpolate() { + InterpolationBinding.prototype.interpolate = function interpolate(connect, initial) { var value = ''; var parts = this.parts; var source = this.source; var valueConverterLookupFunction = this.valueConverterLookupFunction; - var i = undefined; - var ii = undefined; - var temp = undefined; - for (i = 0, ii = parts.length; i < ii; ++i) { + for (var i = 0, ii = parts.length; i < ii; ++i) { if (i % 2 === 0) { value += parts[i]; } else { - temp = parts[i].evaluate(source, valueConverterLookupFunction); - value += typeof temp !== 'undefined' && temp !== null ? temp.toString() : ''; + var part = parts[i].evaluate(source, valueConverterLookupFunction); + value += part === undefined || part === null ? '' : part.toString(); + if (connect) { + parts[i].connect(this, source); + if (part instanceof Array) { + this.observeArray(part); + } + } } } - - return value; + this.targetProperty.setValue(value); + if (!initial) { + this.unobserve(false); + } }; InterpolationBinding.prototype.unbind = function unbind() { - var i = undefined; - var ii = undefined; - var toDispose = this.toDispose; - var map = this.arrayPartMap; - - if (toDispose) { - for (i = 0, ii = toDispose.length; i < ii; ++i) { - toDispose[i](); - } - } - - this.toDispose = null; - - if (map) { - for (var _iterator = map.values(), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - if (_isArray) { - if (_i >= _iterator.length) break; - toDispose = _iterator[_i++]; - } else { - _i = _iterator.next(); - if (_i.done) break; - toDispose = _i.value; - } - - toDispose.dispose(); - } - - map.clear(); - } - - this.arrayPartMap = null; + this.source = undefined; + this.unobserve(true); }; + var _InterpolationBinding = InterpolationBinding; + InterpolationBinding = _aureliaBinding.connectable()(InterpolationBinding) || InterpolationBinding; return InterpolationBinding; })(); diff --git a/dist/es6/aurelia-templating-binding.d.ts b/dist/es6/aurelia-templating-binding.d.ts index 14b1f16..6bf2813 100644 --- a/dist/es6/aurelia-templating-binding.d.ts +++ b/dist/es6/aurelia-templating-binding.d.ts @@ -1,6 +1,6 @@ declare module 'aurelia-templating-binding' { import * as LogManager from 'aurelia-logging'; - import { Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, CallExpression, bindingMode, NameExpression } from 'aurelia-binding'; + import { Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, CallExpression, bindingMode, NameExpression, connectable } from 'aurelia-binding'; import { BehaviorInstruction, BindingLanguage } from 'aurelia-templating'; /*eslint dot-notation:0*/ @@ -15,6 +15,10 @@ declare module 'aurelia-templating-binding' { delegate(resources: any, element: any, info: any): any; call(resources: any, element: any, info: any, existingInstruction: any): any; options(resources: any, element: any, info: any, existingInstruction: any): any; + 'for'(resources: any, element: any, info: any, existingInstruction: any): any; + 'two-way'(resources: any, element: any, info: any, existingInstruction: any): any; + 'one-way'(resources: any, element: any, info: any, existingInstruction: any): any; + 'one-time'(resources: any, element: any, info: any, existingInstruction: any): any; } export class TemplatingBindingLanguage extends BindingLanguage { static inject(): any; @@ -30,12 +34,9 @@ declare module 'aurelia-templating-binding' { } class InterpolationBinding { constructor(observerLocator: any, parts: any, target: any, targetProperty: any, mode: any, valueConverterLookupFunction: any); - getObserver(obj: any, propertyName: any): any; bind(source: any): any; - setValue(): any; - partChanged(newValue: any, oldValue: any, connecting: any): any; - connect(): any; - interpolate(): any; + call(): any; + interpolate(connect: any, initial: any): any; unbind(): any; } export function configure(config: any): any; diff --git a/dist/es6/aurelia-templating-binding.js b/dist/es6/aurelia-templating-binding.js index 98f14b6..acfad3e 100644 --- a/dist/es6/aurelia-templating-binding.js +++ b/dist/es6/aurelia-templating-binding.js @@ -1,5 +1,5 @@ import * as LogManager from 'aurelia-logging'; -import {Parser,ObserverLocator,EventManager,ListenerExpression,BindingExpression,CallExpression,bindingMode,NameExpression} from 'aurelia-binding'; +import {Parser,ObserverLocator,EventManager,ListenerExpression,BindingExpression,CallExpression,bindingMode,NameExpression,connectable} from 'aurelia-binding'; import {BehaviorInstruction,BindingLanguage} from 'aurelia-templating'; /*eslint dot-notation:0*/ @@ -137,92 +137,92 @@ export class SyntaxInterpreter { return instruction; } -} -SyntaxInterpreter.prototype['for'] = function(resources, element, info, existingInstruction) { - let parts; - let keyValue; - let instruction; - let attrValue; - let isDestructuring; + 'for'(resources, element, info, existingInstruction) { + let parts; + let keyValue; + let instruction; + let attrValue; + let isDestructuring; - attrValue = info.attrValue; - isDestructuring = attrValue.match(/[[].+[\]]/); - parts = isDestructuring ? attrValue.split('of ') : attrValue.split(' of '); + attrValue = info.attrValue; + isDestructuring = attrValue.match(/^ *[[].+[\]]/); + parts = isDestructuring ? attrValue.split('of ') : attrValue.split(' of '); - if (parts.length !== 2) { - throw new Error('Incorrect syntax for "for". The form is: "$local of $items" or "[$key, $value] of $items".'); - } + if (parts.length !== 2) { + throw new Error('Incorrect syntax for "for". The form is: "$local of $items" or "[$key, $value] of $items".'); + } - instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); + instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); - if (isDestructuring) { - keyValue = parts[0].replace(/[[\]]/g, '').replace(/,/g, ' ').replace(/\s+/g, ' ').trim().split(' '); - instruction.attributes.key = keyValue[0]; - instruction.attributes.value = keyValue[1]; - } else { - instruction.attributes.local = parts[0]; + if (isDestructuring) { + keyValue = parts[0].replace(/[[\]]/g, '').replace(/,/g, ' ').replace(/\s+/g, ' ').trim().split(' '); + instruction.attributes.key = keyValue[0]; + instruction.attributes.value = keyValue[1]; + } else { + instruction.attributes.local = parts[0]; + } + + instruction.attributes.items = new BindingExpression( + this.observerLocator, + 'items', + this.parser.parse(parts[1]), + bindingMode.oneWay, + resources.valueConverterLookupFunction + ); + + return instruction; } - instruction.attributes.items = new BindingExpression( - this.observerLocator, - 'items', - this.parser.parse(parts[1]), - bindingMode.oneWay, - resources.valueConverterLookupFunction - ); + 'two-way'(resources, element, info, existingInstruction) { + let instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); - return instruction; -}; + instruction.attributes[info.attrName] = new BindingExpression( + this.observerLocator, + this.attributeMap[info.attrName] || info.attrName, + this.parser.parse(info.attrValue), + bindingMode.twoWay, + resources.valueConverterLookupFunction + ); -SyntaxInterpreter.prototype['two-way'] = function(resources, element, info, existingInstruction) { - let instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); + return instruction; + } + + 'one-way'(resources, element, info, existingInstruction) { + let instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); - instruction.attributes[info.attrName] = new BindingExpression( + instruction.attributes[info.attrName] = new BindingExpression( this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), - bindingMode.twoWay, + bindingMode.oneWay, resources.valueConverterLookupFunction ); - return instruction; -}; - -SyntaxInterpreter.prototype['one-way'] = function(resources, element, info, existingInstruction) { - 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), - bindingMode.oneWay, - resources.valueConverterLookupFunction - ); - - return instruction; -}; + return instruction; + } -SyntaxInterpreter.prototype['one-time'] = function(resources, element, info, existingInstruction) { - let instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); + 'one-time'(resources, element, info, existingInstruction) { + 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), - bindingMode.oneTime, - resources.valueConverterLookupFunction - ); + instruction.attributes[info.attrName] = new BindingExpression( + this.observerLocator, + this.attributeMap[info.attrName] || info.attrName, + this.parser.parse(info.attrValue), + bindingMode.oneTime, + resources.valueConverterLookupFunction + ); - return instruction; -}; + return instruction; + } +} let info = {}; let logger = LogManager.getLogger('templating-binding'); export class TemplatingBindingLanguage extends BindingLanguage { static inject() { return [Parser, ObserverLocator, SyntaxInterpreter]; } - constructor(parser, observerLocator, syntaxInterpreter) { + constructor(parser, observerLocator, syntaxInterpreter) { super(); this.parser = parser; this.observerLocator = observerLocator; @@ -284,27 +284,27 @@ export class TemplatingBindingLanguage extends BindingLanguage { } createAttributeInstruction(resources, element, theInfo, existingInstruction) { - let instruction; - - if (theInfo.expression) { - if (theInfo.attrName === 'ref') { - return theInfo.expression; - } + let instruction; - instruction = existingInstruction || BehaviorInstruction.attribute(theInfo.attrName); - instruction.attributes[theInfo.attrName] = theInfo.expression; - } else if (theInfo.command) { - instruction = this.syntaxInterpreter.interpret( - resources, - element, - theInfo, - existingInstruction - ); + if (theInfo.expression) { + if (theInfo.attrName === 'ref') { + return theInfo.expression; } - return instruction; + instruction = existingInstruction || BehaviorInstruction.attribute(theInfo.attrName); + instruction.attributes[theInfo.attrName] = theInfo.expression; + } else if (theInfo.command) { + instruction = this.syntaxInterpreter.interpret( + resources, + element, + theInfo, + existingInstruction + ); } + return instruction; +} + parseText(resources, value) { return this.parseContent(resources, 'textContent', value); } @@ -420,6 +420,7 @@ export class InterpolationBindingExpression { } } +@connectable() class InterpolationBinding { constructor(observerLocator, parts, target, targetProperty, mode, valueConverterLookupFunction) { if (targetProperty === 'style') { @@ -433,131 +434,50 @@ class InterpolationBinding { this.targetProperty = observerLocator.getObserver(target, targetProperty); this.mode = mode; this.valueConverterLookupFunction = valueConverterLookupFunction; - this.toDispose = []; - } - - getObserver(obj, propertyName) { - return this.observerLocator.getObserver(obj, propertyName); } bind(source) { - this.source = source; - - if (this.mode === bindingMode.oneWay) { + if (this.source !== undefined) { this.unbind(); - this.connect(); - this.setValue(); - } else { - this.setValue(); } + this.source = source; + this.interpolate(this.mode === bindingMode.oneWay, true); } - setValue() { - let value = this.interpolate(); - this.targetProperty.setValue(value); - } - - partChanged(newValue, oldValue, connecting) { - let map; - let data; - - if (!connecting) { - this.setValue(); - } - - if (oldValue instanceof Array) { - map = this.arrayPartMap; - data = map ? map.get(oldValue) : null; - if (data) { - data.refs--; - if (data.refs === 0) { - data.dispose(); - map.delete(oldValue); - } - } - } - - if (newValue instanceof Array) { - map = this.arrayPartMap || (this.arrayPartMap = new Map()); - data = map.get(newValue); - if (!data) { - data = { - refs: 0, - dispose: this.observerLocator.getArrayObserver(newValue).subscribe(() => this.setValue()) - }; - - map.set(newValue, data); - } - data.refs++; - } + call() { + this._version++; + this.interpolate(this.mode === bindingMode.oneWay, false); } - connect() { - let result; - let parts = this.parts; - let source = this.source; - let toDispose = this.toDispose = []; - let partChanged = this.partChanged.bind(this); - let i; - let ii; - - for (i = 0, ii = parts.length; i < ii; ++i) { - if (i % 2 !== 0) { - result = parts[i].connect(this, source); - if (result.observer) { - toDispose.push(result.observer.subscribe(partChanged)); - } - if (result.value instanceof Array) { - partChanged(result.value, undefined, true); - } - } - } - } - - interpolate() { + interpolate(connect, initial) { let value = ''; let parts = this.parts; let source = this.source; let valueConverterLookupFunction = this.valueConverterLookupFunction; - let i; - let ii; - let temp; - for (i = 0, ii = parts.length; i < ii; ++i) { + for (let i = 0, ii = parts.length; i < ii; ++i) { if (i % 2 === 0) { value += parts[i]; } else { - temp = parts[i].evaluate(source, valueConverterLookupFunction); - value += (typeof temp !== 'undefined' && temp !== null ? temp.toString() : ''); + let part = parts[i].evaluate(source, valueConverterLookupFunction); + value += part === undefined || part === null ? '' : part.toString(); + if (connect) { + parts[i].connect(this, source); + if (part instanceof Array) { + this.observeArray(part); + } + } } } - - return value; + this.targetProperty.setValue(value); + if (!initial) { + this.unobserve(false); + } } unbind() { - let i; - let ii; - let toDispose = this.toDispose; - let map = this.arrayPartMap; - - if (toDispose) { - for (i = 0, ii = toDispose.length; i < ii; ++i) { - toDispose[i](); - } - } - - this.toDispose = null; - - if (map) { - for (toDispose of map.values()) { - toDispose.dispose(); - } - - map.clear(); - } - - this.arrayPartMap = null; + this.source = undefined; + this.unobserve(true); } } diff --git a/dist/system/aurelia-templating-binding.d.ts b/dist/system/aurelia-templating-binding.d.ts index 14b1f16..6bf2813 100644 --- a/dist/system/aurelia-templating-binding.d.ts +++ b/dist/system/aurelia-templating-binding.d.ts @@ -1,6 +1,6 @@ declare module 'aurelia-templating-binding' { import * as LogManager from 'aurelia-logging'; - import { Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, CallExpression, bindingMode, NameExpression } from 'aurelia-binding'; + import { Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, CallExpression, bindingMode, NameExpression, connectable } from 'aurelia-binding'; import { BehaviorInstruction, BindingLanguage } from 'aurelia-templating'; /*eslint dot-notation:0*/ @@ -15,6 +15,10 @@ declare module 'aurelia-templating-binding' { delegate(resources: any, element: any, info: any): any; call(resources: any, element: any, info: any, existingInstruction: any): any; options(resources: any, element: any, info: any, existingInstruction: any): any; + 'for'(resources: any, element: any, info: any, existingInstruction: any): any; + 'two-way'(resources: any, element: any, info: any, existingInstruction: any): any; + 'one-way'(resources: any, element: any, info: any, existingInstruction: any): any; + 'one-time'(resources: any, element: any, info: any, existingInstruction: any): any; } export class TemplatingBindingLanguage extends BindingLanguage { static inject(): any; @@ -30,12 +34,9 @@ declare module 'aurelia-templating-binding' { } class InterpolationBinding { constructor(observerLocator: any, parts: any, target: any, targetProperty: any, mode: any, valueConverterLookupFunction: any); - getObserver(obj: any, propertyName: any): any; bind(source: any): any; - setValue(): any; - partChanged(newValue: any, oldValue: any, connecting: any): any; - connect(): any; - interpolate(): any; + call(): any; + interpolate(connect: any, initial: any): any; unbind(): any; } export function configure(config: any): any; diff --git a/dist/system/aurelia-templating-binding.js b/dist/system/aurelia-templating-binding.js index 9148908..75472d5 100644 --- a/dist/system/aurelia-templating-binding.js +++ b/dist/system/aurelia-templating-binding.js @@ -1,7 +1,7 @@ System.register(['aurelia-logging', 'aurelia-binding', 'aurelia-templating'], function (_export) { 'use strict'; - var LogManager, Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, CallExpression, bindingMode, NameExpression, BehaviorInstruction, BindingLanguage, SyntaxInterpreter, info, logger, TemplatingBindingLanguage, InterpolationBindingExpression, InterpolationBinding; + var LogManager, Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, CallExpression, bindingMode, NameExpression, connectable, BehaviorInstruction, BindingLanguage, SyntaxInterpreter, info, logger, TemplatingBindingLanguage, InterpolationBindingExpression, InterpolationBinding; _export('configure', configure); @@ -36,6 +36,7 @@ System.register(['aurelia-logging', 'aurelia-binding', 'aurelia-templating'], fu CallExpression = _aureliaBinding.CallExpression; bindingMode = _aureliaBinding.bindingMode; NameExpression = _aureliaBinding.NameExpression; + connectable = _aureliaBinding.connectable; }, function (_aureliaTemplating) { BehaviorInstruction = _aureliaTemplating.BehaviorInstruction; BindingLanguage = _aureliaTemplating.BindingLanguage; @@ -158,64 +159,64 @@ System.register(['aurelia-logging', 'aurelia-binding', 'aurelia-templating'], fu return instruction; }; - return SyntaxInterpreter; - })(); + SyntaxInterpreter.prototype['for'] = function _for(resources, element, info, existingInstruction) { + var parts = undefined; + var keyValue = undefined; + var instruction = undefined; + var attrValue = undefined; + var isDestructuring = undefined; - _export('SyntaxInterpreter', SyntaxInterpreter); + attrValue = info.attrValue; + isDestructuring = attrValue.match(/^ *[[].+[\]]/); + parts = isDestructuring ? attrValue.split('of ') : attrValue.split(' of '); - SyntaxInterpreter.prototype['for'] = function (resources, element, info, existingInstruction) { - var parts = undefined; - var keyValue = undefined; - var instruction = undefined; - var attrValue = undefined; - var isDestructuring = undefined; + if (parts.length !== 2) { + throw new Error('Incorrect syntax for "for". The form is: "$local of $items" or "[$key, $value] of $items".'); + } - attrValue = info.attrValue; - isDestructuring = attrValue.match(/[[].+[\]]/); - parts = isDestructuring ? attrValue.split('of ') : attrValue.split(' of '); + instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); - if (parts.length !== 2) { - throw new Error('Incorrect syntax for "for". The form is: "$local of $items" or "[$key, $value] of $items".'); - } + if (isDestructuring) { + keyValue = parts[0].replace(/[[\]]/g, '').replace(/,/g, ' ').replace(/\s+/g, ' ').trim().split(' '); + instruction.attributes.key = keyValue[0]; + instruction.attributes.value = keyValue[1]; + } else { + instruction.attributes.local = parts[0]; + } - instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); + instruction.attributes.items = new BindingExpression(this.observerLocator, 'items', this.parser.parse(parts[1]), bindingMode.oneWay, resources.valueConverterLookupFunction); - if (isDestructuring) { - keyValue = parts[0].replace(/[[\]]/g, '').replace(/,/g, ' ').replace(/\s+/g, ' ').trim().split(' '); - instruction.attributes.key = keyValue[0]; - instruction.attributes.value = keyValue[1]; - } else { - instruction.attributes.local = parts[0]; - } + return instruction; + }; - instruction.attributes.items = new BindingExpression(this.observerLocator, 'items', this.parser.parse(parts[1]), bindingMode.oneWay, resources.valueConverterLookupFunction); + SyntaxInterpreter.prototype['two-way'] = function twoWay(resources, element, info, existingInstruction) { + var instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); - return instruction; - }; + instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), bindingMode.twoWay, resources.valueConverterLookupFunction); - SyntaxInterpreter.prototype['two-way'] = function (resources, element, info, existingInstruction) { - var instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); + return instruction; + }; - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), bindingMode.twoWay, resources.valueConverterLookupFunction); + SyntaxInterpreter.prototype['one-way'] = function oneWay(resources, element, info, existingInstruction) { + var instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); - return instruction; - }; + instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), bindingMode.oneWay, resources.valueConverterLookupFunction); - SyntaxInterpreter.prototype['one-way'] = function (resources, element, info, existingInstruction) { - var instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); + return instruction; + }; - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), bindingMode.oneWay, resources.valueConverterLookupFunction); + SyntaxInterpreter.prototype['one-time'] = function oneTime(resources, element, info, existingInstruction) { + var instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); - return instruction; - }; + instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), bindingMode.oneTime, resources.valueConverterLookupFunction); - SyntaxInterpreter.prototype['one-time'] = function (resources, element, info, existingInstruction) { - var instruction = existingInstruction || BehaviorInstruction.attribute(info.attrName); + return instruction; + }; - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), bindingMode.oneTime, resources.valueConverterLookupFunction); + return SyntaxInterpreter; + })(); - return instruction; - }; + _export('SyntaxInterpreter', SyntaxInterpreter); info = {}; logger = LogManager.getLogger('templating-binding'); @@ -414,7 +415,7 @@ System.register(['aurelia-logging', 'aurelia-binding', 'aurelia-templating'], fu InterpolationBinding = (function () { function InterpolationBinding(observerLocator, parts, target, targetProperty, mode, valueConverterLookupFunction) { - _classCallCheck(this, InterpolationBinding); + _classCallCheck(this, _InterpolationBinding); if (targetProperty === 'style') { logger.info('Internet Explorer does not support interpolation in "style" attributes. Use the style attribute\'s alias, "css" instead.'); @@ -427,146 +428,54 @@ System.register(['aurelia-logging', 'aurelia-binding', 'aurelia-templating'], fu this.targetProperty = observerLocator.getObserver(target, targetProperty); this.mode = mode; this.valueConverterLookupFunction = valueConverterLookupFunction; - this.toDispose = []; } - InterpolationBinding.prototype.getObserver = function getObserver(obj, propertyName) { - return this.observerLocator.getObserver(obj, propertyName); - }; - InterpolationBinding.prototype.bind = function bind(source) { - this.source = source; - - if (this.mode === bindingMode.oneWay) { + if (this.source !== undefined) { this.unbind(); - this.connect(); - this.setValue(); - } else { - this.setValue(); - } - }; - - InterpolationBinding.prototype.setValue = function setValue() { - var value = this.interpolate(); - this.targetProperty.setValue(value); - }; - - InterpolationBinding.prototype.partChanged = function partChanged(newValue, oldValue, connecting) { - var _this = this; - - var map = undefined; - var data = undefined; - - if (!connecting) { - this.setValue(); - } - - if (oldValue instanceof Array) { - map = this.arrayPartMap; - data = map ? map.get(oldValue) : null; - if (data) { - data.refs--; - if (data.refs === 0) { - data.dispose(); - map['delete'](oldValue); - } - } - } - - if (newValue instanceof Array) { - map = this.arrayPartMap || (this.arrayPartMap = new Map()); - data = map.get(newValue); - if (!data) { - data = { - refs: 0, - dispose: this.observerLocator.getArrayObserver(newValue).subscribe(function () { - return _this.setValue(); - }) - }; - - map.set(newValue, data); - } - data.refs++; } + this.source = source; + this.interpolate(this.mode === bindingMode.oneWay, true); }; - InterpolationBinding.prototype.connect = function connect() { - var result = undefined; - var parts = this.parts; - var source = this.source; - var toDispose = this.toDispose = []; - var partChanged = this.partChanged.bind(this); - var i = undefined; - var ii = undefined; - - for (i = 0, ii = parts.length; i < ii; ++i) { - if (i % 2 !== 0) { - result = parts[i].connect(this, source); - if (result.observer) { - toDispose.push(result.observer.subscribe(partChanged)); - } - if (result.value instanceof Array) { - partChanged(result.value, undefined, true); - } - } - } + InterpolationBinding.prototype.call = function call() { + this._version++; + this.interpolate(this.mode === bindingMode.oneWay, false); }; - InterpolationBinding.prototype.interpolate = function interpolate() { + InterpolationBinding.prototype.interpolate = function interpolate(connect, initial) { var value = ''; var parts = this.parts; var source = this.source; var valueConverterLookupFunction = this.valueConverterLookupFunction; - var i = undefined; - var ii = undefined; - var temp = undefined; - for (i = 0, ii = parts.length; i < ii; ++i) { + for (var i = 0, ii = parts.length; i < ii; ++i) { if (i % 2 === 0) { value += parts[i]; } else { - temp = parts[i].evaluate(source, valueConverterLookupFunction); - value += typeof temp !== 'undefined' && temp !== null ? temp.toString() : ''; + var part = parts[i].evaluate(source, valueConverterLookupFunction); + value += part === undefined || part === null ? '' : part.toString(); + if (connect) { + parts[i].connect(this, source); + if (part instanceof Array) { + this.observeArray(part); + } + } } } - - return value; + this.targetProperty.setValue(value); + if (!initial) { + this.unobserve(false); + } }; InterpolationBinding.prototype.unbind = function unbind() { - var i = undefined; - var ii = undefined; - var toDispose = this.toDispose; - var map = this.arrayPartMap; - - if (toDispose) { - for (i = 0, ii = toDispose.length; i < ii; ++i) { - toDispose[i](); - } - } - - this.toDispose = null; - - if (map) { - for (var _iterator = map.values(), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - if (_isArray) { - if (_i >= _iterator.length) break; - toDispose = _iterator[_i++]; - } else { - _i = _iterator.next(); - if (_i.done) break; - toDispose = _i.value; - } - - toDispose.dispose(); - } - - map.clear(); - } - - this.arrayPartMap = null; + this.source = undefined; + this.unobserve(true); }; + var _InterpolationBinding = InterpolationBinding; + InterpolationBinding = connectable()(InterpolationBinding) || InterpolationBinding; return InterpolationBinding; })(); } diff --git a/doc/api.json b/doc/api.json index 494ccda..a6fb232 100644 --- a/doc/api.json +++ b/doc/api.json @@ -6,28 +6,28 @@ "flags": {}, "children": [ { - "id": 95, + "id": 119, "name": "InterpolationBinding", "kind": 128, "kindString": "Class", "flags": {}, "children": [ { - "id": 96, + "id": 120, "name": "constructor", "kind": 512, "kindString": "Constructor", "flags": {}, "signatures": [ { - "id": 97, + "id": 121, "name": "new InterpolationBinding", "kind": 16384, "kindString": "Constructor signature", "flags": {}, "parameters": [ { - "id": 98, + "id": 122, "name": "observerLocator", "kind": 32768, "kindString": "Parameter", @@ -38,7 +38,7 @@ } }, { - "id": 99, + "id": 123, "name": "parts", "kind": 32768, "kindString": "Parameter", @@ -49,7 +49,7 @@ } }, { - "id": 100, + "id": 124, "name": "target", "kind": 32768, "kindString": "Parameter", @@ -60,7 +60,7 @@ } }, { - "id": 101, + "id": 125, "name": "targetProperty", "kind": 32768, "kindString": "Parameter", @@ -71,7 +71,7 @@ } }, { - "id": 102, + "id": 126, "name": "mode", "kind": 32768, "kindString": "Parameter", @@ -82,7 +82,7 @@ } }, { - "id": 103, + "id": 127, "name": "valueConverterLookupFunction", "kind": 32768, "kindString": "Parameter", @@ -96,28 +96,28 @@ "type": { "type": "reference", "name": "InterpolationBinding", - "id": 95, + "id": 119, "moduleName": "\"aurelia-templating-binding\"" } } ] }, { - "id": 108, + "id": 128, "name": "bind", "kind": 2048, "kindString": "Method", "flags": {}, "signatures": [ { - "id": 109, + "id": 129, "name": "bind", "kind": 4096, "kindString": "Call signature", "flags": {}, "parameters": [ { - "id": 110, + "id": 130, "name": "source", "kind": 32768, "kindString": "Parameter", @@ -136,62 +136,18 @@ ] }, { - "id": 118, - "name": "connect", - "kind": 2048, - "kindString": "Method", - "flags": {}, - "signatures": [ - { - "id": 119, - "name": "connect", - "kind": 4096, - "kindString": "Call signature", - "flags": {}, - "type": { - "type": "instrinct", - "name": "any" - } - } - ] - }, - { - "id": 104, - "name": "getObserver", + "id": 131, + "name": "call", "kind": 2048, "kindString": "Method", "flags": {}, "signatures": [ { - "id": 105, - "name": "getObserver", + "id": 132, + "name": "call", "kind": 4096, "kindString": "Call signature", "flags": {}, - "parameters": [ - { - "id": 106, - "name": "obj", - "kind": 32768, - "kindString": "Parameter", - "flags": {}, - "type": { - "type": "instrinct", - "name": "any" - } - }, - { - "id": 107, - "name": "propertyName", - "kind": 32768, - "kindString": "Parameter", - "flags": {}, - "type": { - "type": "instrinct", - "name": "any" - } - } - ], "type": { "type": "instrinct", "name": "any" @@ -200,53 +156,22 @@ ] }, { - "id": 120, + "id": 133, "name": "interpolate", "kind": 2048, "kindString": "Method", "flags": {}, "signatures": [ { - "id": 121, + "id": 134, "name": "interpolate", "kind": 4096, "kindString": "Call signature", "flags": {}, - "type": { - "type": "instrinct", - "name": "any" - } - } - ] - }, - { - "id": 113, - "name": "partChanged", - "kind": 2048, - "kindString": "Method", - "flags": {}, - "signatures": [ - { - "id": 114, - "name": "partChanged", - "kind": 4096, - "kindString": "Call signature", - "flags": {}, "parameters": [ { - "id": 115, - "name": "newValue", - "kind": 32768, - "kindString": "Parameter", - "flags": {}, - "type": { - "type": "instrinct", - "name": "any" - } - }, - { - "id": 116, - "name": "oldValue", + "id": 135, + "name": "connect", "kind": 32768, "kindString": "Parameter", "flags": {}, @@ -256,8 +181,8 @@ } }, { - "id": 117, - "name": "connecting", + "id": 136, + "name": "initial", "kind": 32768, "kindString": "Parameter", "flags": {}, @@ -275,34 +200,14 @@ ] }, { - "id": 111, - "name": "setValue", - "kind": 2048, - "kindString": "Method", - "flags": {}, - "signatures": [ - { - "id": 112, - "name": "setValue", - "kind": 4096, - "kindString": "Call signature", - "flags": {}, - "type": { - "type": "instrinct", - "name": "any" - } - } - ] - }, - { - "id": 122, + "id": 137, "name": "unbind", "kind": 2048, "kindString": "Method", "flags": {}, "signatures": [ { - "id": 123, + "id": 138, "name": "unbind", "kind": 4096, "kindString": "Call signature", @@ -320,26 +225,23 @@ "title": "Constructors", "kind": 512, "children": [ - 96 + 120 ] }, { "title": "Methods", "kind": 2048, "children": [ - 108, - 118, - 104, - 120, - 113, - 111, - 122 + 128, + 131, + 133, + 137 ] } ] }, { - "id": 83, + "id": 107, "name": "InterpolationBindingExpression", "kind": 128, "kindString": "Class", @@ -348,7 +250,7 @@ }, "children": [ { - "id": 84, + "id": 108, "name": "constructor", "kind": 512, "kindString": "Constructor", @@ -357,14 +259,14 @@ }, "signatures": [ { - "id": 85, + "id": 109, "name": "new InterpolationBindingExpression", "kind": 16384, "kindString": "Constructor signature", "flags": {}, "parameters": [ { - "id": 86, + "id": 110, "name": "observerLocator", "kind": 32768, "kindString": "Parameter", @@ -375,7 +277,7 @@ } }, { - "id": 87, + "id": 111, "name": "targetProperty", "kind": 32768, "kindString": "Parameter", @@ -386,7 +288,7 @@ } }, { - "id": 88, + "id": 112, "name": "parts", "kind": 32768, "kindString": "Parameter", @@ -397,7 +299,7 @@ } }, { - "id": 89, + "id": 113, "name": "mode", "kind": 32768, "kindString": "Parameter", @@ -408,7 +310,7 @@ } }, { - "id": 90, + "id": 114, "name": "valueConverterLookupFunction", "kind": 32768, "kindString": "Parameter", @@ -419,7 +321,7 @@ } }, { - "id": 91, + "id": 115, "name": "attribute", "kind": 32768, "kindString": "Parameter", @@ -433,14 +335,14 @@ "type": { "type": "reference", "name": "InterpolationBindingExpression", - "id": 83, + "id": 107, "moduleName": "\"aurelia-templating-binding\"" } } ] }, { - "id": 92, + "id": 116, "name": "createBinding", "kind": 2048, "kindString": "Method", @@ -449,14 +351,14 @@ }, "signatures": [ { - "id": 93, + "id": 117, "name": "createBinding", "kind": 4096, "kindString": "Call signature", "flags": {}, "parameters": [ { - "id": 94, + "id": 118, "name": "target", "kind": 32768, "kindString": "Parameter", @@ -480,14 +382,14 @@ "title": "Constructors", "kind": 512, "children": [ - 84 + 108 ] }, { "title": "Methods", "kind": 2048, "children": [ - 92 + 116 ] } ] @@ -799,6 +701,74 @@ } ] }, + { + "id": 55, + "name": "for", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 56, + "name": "for", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "parameters": [ + { + "id": 57, + "name": "resources", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 58, + "name": "element", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 59, + "name": "info", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 60, + "name": "existingInstruction", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, { "id": 17, "name": "handleUnknownCommand", @@ -935,6 +905,142 @@ } ] }, + { + "id": 73, + "name": "one-time", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 74, + "name": "one-time", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "parameters": [ + { + "id": 75, + "name": "resources", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 76, + "name": "element", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 77, + "name": "info", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 78, + "name": "existingInstruction", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 67, + "name": "one-way", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 68, + "name": "one-way", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "parameters": [ + { + "id": 69, + "name": "resources", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 70, + "name": "element", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 71, + "name": "info", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 72, + "name": "existingInstruction", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, { "id": 49, "name": "options", @@ -1060,6 +1166,74 @@ } ] }, + { + "id": 61, + "name": "two-way", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 62, + "name": "two-way", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "parameters": [ + { + "id": 63, + "name": "resources", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 64, + "name": "element", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 65, + "name": "info", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 66, + "name": "existingInstruction", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, { "id": 4, "name": "inject", @@ -1100,17 +1274,21 @@ 43, 38, 23, + 55, 17, 11, + 73, + 67, 49, 33, + 61, 4 ] } ] }, { - "id": 55, + "id": 79, "name": "TemplatingBindingLanguage", "kind": 128, "kindString": "Class", @@ -1119,7 +1297,7 @@ }, "children": [ { - "id": 58, + "id": 82, "name": "constructor", "kind": 512, "kindString": "Constructor", @@ -1128,14 +1306,14 @@ }, "signatures": [ { - "id": 59, + "id": 83, "name": "new TemplatingBindingLanguage", "kind": 16384, "kindString": "Constructor signature", "flags": {}, "parameters": [ { - "id": 60, + "id": 84, "name": "parser", "kind": 32768, "kindString": "Parameter", @@ -1146,7 +1324,7 @@ } }, { - "id": 61, + "id": 85, "name": "observerLocator", "kind": 32768, "kindString": "Parameter", @@ -1157,7 +1335,7 @@ } }, { - "id": 62, + "id": 86, "name": "syntaxInterpreter", "kind": 32768, "kindString": "Parameter", @@ -1171,14 +1349,14 @@ "type": { "type": "reference", "name": "TemplatingBindingLanguage", - "id": 55, + "id": 79, "moduleName": "\"aurelia-templating-binding\"" } } ] }, { - "id": 68, + "id": 92, "name": "createAttributeInstruction", "kind": 2048, "kindString": "Method", @@ -1187,14 +1365,14 @@ }, "signatures": [ { - "id": 69, + "id": 93, "name": "createAttributeInstruction", "kind": 4096, "kindString": "Call signature", "flags": {}, "parameters": [ { - "id": 70, + "id": 94, "name": "resources", "kind": 32768, "kindString": "Parameter", @@ -1205,7 +1383,7 @@ } }, { - "id": 71, + "id": 95, "name": "element", "kind": 32768, "kindString": "Parameter", @@ -1216,7 +1394,7 @@ } }, { - "id": 72, + "id": 96, "name": "theInfo", "kind": 32768, "kindString": "Parameter", @@ -1227,7 +1405,7 @@ } }, { - "id": 73, + "id": 97, "name": "existingInstruction", "kind": 32768, "kindString": "Parameter", @@ -1245,18 +1423,18 @@ "overwrites": { "type": "reference", "name": "BindingLanguage.createAttributeInstruction", - "id": 1945 + "id": 2127 } } ], "overwrites": { "type": "reference", "name": "BindingLanguage.createAttributeInstruction", - "id": 1945 + "id": 2127 } }, { - "id": 63, + "id": 87, "name": "inspectAttribute", "kind": 2048, "kindString": "Method", @@ -1265,14 +1443,14 @@ }, "signatures": [ { - "id": 64, + "id": 88, "name": "inspectAttribute", "kind": 4096, "kindString": "Call signature", "flags": {}, "parameters": [ { - "id": 65, + "id": 89, "name": "resources", "kind": 32768, "kindString": "Parameter", @@ -1283,7 +1461,7 @@ } }, { - "id": 66, + "id": 90, "name": "attrName", "kind": 32768, "kindString": "Parameter", @@ -1294,7 +1472,7 @@ } }, { - "id": 67, + "id": 91, "name": "attrValue", "kind": 32768, "kindString": "Parameter", @@ -1312,18 +1490,18 @@ "overwrites": { "type": "reference", "name": "BindingLanguage.inspectAttribute", - "id": 1940 + "id": 2122 } } ], "overwrites": { "type": "reference", "name": "BindingLanguage.inspectAttribute", - "id": 1940 + "id": 2122 } }, { - "id": 78, + "id": 102, "name": "parseContent", "kind": 2048, "kindString": "Method", @@ -1332,14 +1510,14 @@ }, "signatures": [ { - "id": 79, + "id": 103, "name": "parseContent", "kind": 4096, "kindString": "Call signature", "flags": {}, "parameters": [ { - "id": 80, + "id": 104, "name": "resources", "kind": 32768, "kindString": "Parameter", @@ -1350,7 +1528,7 @@ } }, { - "id": 81, + "id": 105, "name": "attrName", "kind": 32768, "kindString": "Parameter", @@ -1361,7 +1539,7 @@ } }, { - "id": 82, + "id": 106, "name": "attrValue", "kind": 32768, "kindString": "Parameter", @@ -1380,7 +1558,7 @@ ] }, { - "id": 74, + "id": 98, "name": "parseText", "kind": 2048, "kindString": "Method", @@ -1389,14 +1567,14 @@ }, "signatures": [ { - "id": 75, + "id": 99, "name": "parseText", "kind": 4096, "kindString": "Call signature", "flags": {}, "parameters": [ { - "id": 76, + "id": 100, "name": "resources", "kind": 32768, "kindString": "Parameter", @@ -1407,7 +1585,7 @@ } }, { - "id": 77, + "id": 101, "name": "value", "kind": 32768, "kindString": "Parameter", @@ -1425,18 +1603,18 @@ "overwrites": { "type": "reference", "name": "BindingLanguage.parseText", - "id": 1951 + "id": 2133 } } ], "overwrites": { "type": "reference", "name": "BindingLanguage.parseText", - "id": 1951 + "id": 2133 } }, { - "id": 56, + "id": 80, "name": "inject", "kind": 2048, "kindString": "Method", @@ -1446,7 +1624,7 @@ }, "signatures": [ { - "id": 57, + "id": 81, "name": "inject", "kind": 4096, "kindString": "Call signature", @@ -1464,18 +1642,18 @@ "title": "Constructors", "kind": 512, "children": [ - 58 + 82 ] }, { "title": "Methods", "kind": 2048, "children": [ - 68, - 63, - 78, - 74, - 56 + 92, + 87, + 102, + 98, + 80 ] } ], @@ -1483,12 +1661,12 @@ { "type": "reference", "name": "BindingLanguage", - "id": 1939 + "id": 2121 } ] }, { - "id": 124, + "id": 139, "name": "configure", "kind": 64, "kindString": "Function", @@ -1497,14 +1675,14 @@ }, "signatures": [ { - "id": 125, + "id": 140, "name": "configure", "kind": 4096, "kindString": "Call signature", "flags": {}, "parameters": [ { - "id": 126, + "id": 141, "name": "config", "kind": 32768, "kindString": "Parameter", @@ -1528,17 +1706,17 @@ "title": "Classes", "kind": 128, "children": [ - 95, - 83, + 119, + 107, 3, - 55 + 79 ] }, { "title": "Functions", "kind": 64, "children": [ - 124 + 139 ] } ] diff --git a/package.json b/package.json index 2b9b43c..afcf73f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-templating-binding", - "version": "0.15.0", + "version": "0.16.0", "description": "An implementation of the templating engine's Binding Language abstraction which uses a pluggable command syntax.", "keywords": [ "aurelia", @@ -26,14 +26,14 @@ "lib": "dist/amd" }, "dependencies": { - "aurelia-binding": "github:aurelia/binding@^0.9.0", - "aurelia-logging": "github:aurelia/logging@^0.7.0", - "aurelia-templating": "github:aurelia/templating@^0.15.0" + "aurelia-binding": "github:aurelia/binding@^0.10.0", + "aurelia-logging": "github:aurelia/logging@^0.8.0", + "aurelia-templating": "github:aurelia/templating@^0.16.0" }, "devDependencies": { - "aurelia-pal": "github:aurelia/pal@^0.1.9", - "aurelia-pal-browser": "github:aurelia/pal-browser@^0.1.12", - "aurelia-task-queue": "github:aurelia/task-queue@^0.7.0", + "aurelia-pal": "github:aurelia/pal@^0.2.0", + "aurelia-pal-browser": "github:aurelia/pal-browser@^0.2.0", + "aurelia-task-queue": "github:aurelia/task-queue@^0.8.0", "babel": "npm:babel-core@^5.1.13", "babel-runtime": "npm:babel-runtime@^5.1.13", "core-js": "npm:core-js@^0.9.4" @@ -71,30 +71,8 @@ "yargs": "^2.1.1" }, "aurelia": { - "usedBy": [ - "aurelia-bootstrapper" - ], "documentation": { - "links": [ - { - "rel": "license", - "mediaType": "text/plain", - "title": "The MIT License (MIT)", - "href": "LICENSE" - }, - { - "rel": "describedby", - "mediaType": "application/aurelia-doc+json", - "title": "API", - "href": "doc/api.json" - }, - { - "rel": "version-history", - "mediaType": "text/markdown", - "title": "Change Log", - "href": "doc/CHANGELOG.md" - } - ] + "links": [] } } } diff --git a/src/binding-language.js b/src/binding-language.js index 234b1d7..7657daa 100644 --- a/src/binding-language.js +++ b/src/binding-language.js @@ -8,7 +8,7 @@ let logger = LogManager.getLogger('templating-binding'); export class TemplatingBindingLanguage extends BindingLanguage { static inject() { return [Parser, ObserverLocator, SyntaxInterpreter]; } - constructor(parser, observerLocator, syntaxInterpreter) { + constructor(parser, observerLocator, syntaxInterpreter) { super(); this.parser = parser; this.observerLocator = observerLocator; @@ -70,27 +70,27 @@ export class TemplatingBindingLanguage extends BindingLanguage { } createAttributeInstruction(resources, element, theInfo, existingInstruction) { - let instruction; + let instruction; - if (theInfo.expression) { - if (theInfo.attrName === 'ref') { - return theInfo.expression; - } - - instruction = existingInstruction || BehaviorInstruction.attribute(theInfo.attrName); - instruction.attributes[theInfo.attrName] = theInfo.expression; - } else if (theInfo.command) { - instruction = this.syntaxInterpreter.interpret( - resources, - element, - theInfo, - existingInstruction - ); + if (theInfo.expression) { + if (theInfo.attrName === 'ref') { + return theInfo.expression; } - return instruction; + instruction = existingInstruction || BehaviorInstruction.attribute(theInfo.attrName); + instruction.attributes[theInfo.attrName] = theInfo.expression; + } else if (theInfo.command) { + instruction = this.syntaxInterpreter.interpret( + resources, + element, + theInfo, + existingInstruction + ); } + return instruction; +} + parseText(resources, value) { return this.parseContent(resources, 'textContent', value); }