diff --git a/bower.json b/bower.json index f564e732..49a018f1 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-binding", - "version": "1.0.6", + "version": "1.0.7", "description": "A modern databinding library for JavaScript and HTML.", "license": "MIT", "keywords": [ diff --git a/dist/amd/aurelia-binding.js b/dist/amd/aurelia-binding.js index 7bb8220b..ded7a1d8 100644 --- a/dist/amd/aurelia-binding.js +++ b/dist/amd/aurelia-binding.js @@ -3692,7 +3692,7 @@ define(['exports', 'aurelia-logging', 'aurelia-pal', 'aurelia-task-queue', 'aure StyleObserver.prototype._setProperty = function _setProperty(style, value) { var priority = ''; - if (value.indexOf('!important') !== -1) { + if (value.indexOf && value.indexOf('!important') !== -1) { priority = 'important'; value = value.replace('!important', ''); } @@ -5312,12 +5312,17 @@ define(['exports', 'aurelia-logging', 'aurelia-pal', 'aurelia-task-queue', 'aure } var innerPropertyName = '_' + key; + var innerPropertyDescriptor = { + configurable: true, + enumerable: false, + writable: true + }; var callbackName = config && config.changeHandler || key + 'Changed'; if (descriptor) { if (typeof descriptor.initializer === 'function') { - target[innerPropertyName] = descriptor.initializer(); + innerPropertyDescriptor.value = descriptor.initializer(); } } else { descriptor = {}; @@ -5327,15 +5332,21 @@ define(['exports', 'aurelia-logging', 'aurelia-pal', 'aurelia-task-queue', 'aure descriptor.enumerable = true; } + delete descriptor.value; delete descriptor.writable; delete descriptor.initializer; + Reflect.defineProperty(target, innerPropertyName, innerPropertyDescriptor); + descriptor.get = function () { return this[innerPropertyName]; }; descriptor.set = function (newValue) { var oldValue = this[innerPropertyName]; + this[innerPropertyName] = newValue; + Reflect.defineProperty(this, innerPropertyName, { enumerable: false }); + if (this[callbackName]) { this[callbackName](newValue, oldValue, key); } diff --git a/dist/aurelia-binding.js b/dist/aurelia-binding.js index 994a717d..ffbc19b8 100644 --- a/dist/aurelia-binding.js +++ b/dist/aurelia-binding.js @@ -3511,7 +3511,7 @@ export class StyleObserver { _setProperty(style, value) { let priority = ''; - if (value.indexOf('!important') !== -1) { + if (value.indexOf && value.indexOf('!important') !== -1) { priority = 'important'; value = value.replace('!important', ''); } @@ -5040,6 +5040,11 @@ export function observable(targetOrConfig: any, key: string, descriptor?: Proper // use a convention to compute the inner property name let innerPropertyName = `_${key}`; + const innerPropertyDescriptor: PropertyDescriptor = { + configurable: true, + enumerable: false, + writable: true + }; // determine callback name based on config or convention. const callbackName = (config && config.changeHandler) || `${key}Changed`; @@ -5049,7 +5054,7 @@ export function observable(targetOrConfig: any, key: string, descriptor?: Proper // set the initial value of the property if it is defined. if (typeof descriptor.initializer === 'function') { - target[innerPropertyName] = descriptor.initializer(); + innerPropertyDescriptor.value = descriptor.initializer(); } } else { // there is no descriptor if the target was a field in TS (although Babel provides one), @@ -5063,14 +5068,22 @@ export function observable(targetOrConfig: any, key: string, descriptor?: Proper // we're adding a getter and setter which means the property descriptor // cannot have a "value" or "writable" attribute + delete descriptor.value; delete descriptor.writable; delete descriptor.initializer; + // Add the inner property on the prototype. + Reflect.defineProperty(target, innerPropertyName, innerPropertyDescriptor); + // add the getter and setter to the property descriptor. descriptor.get = function() { return this[innerPropertyName]; }; descriptor.set = function(newValue) { let oldValue = this[innerPropertyName]; + + // Add the inner property on the instance and make it nonenumerable. this[innerPropertyName] = newValue; + Reflect.defineProperty(this, innerPropertyName, { enumerable: false }); + if (this[callbackName]) { this[callbackName](newValue, oldValue, key); } diff --git a/dist/commonjs/aurelia-binding.js b/dist/commonjs/aurelia-binding.js index c000d7e3..0cd1eb51 100644 --- a/dist/commonjs/aurelia-binding.js +++ b/dist/commonjs/aurelia-binding.js @@ -3645,7 +3645,7 @@ var StyleObserver = exports.StyleObserver = function () { StyleObserver.prototype._setProperty = function _setProperty(style, value) { var priority = ''; - if (value.indexOf('!important') !== -1) { + if (value.indexOf && value.indexOf('!important') !== -1) { priority = 'important'; value = value.replace('!important', ''); } @@ -5265,12 +5265,17 @@ function observable(targetOrConfig, key, descriptor) { } var innerPropertyName = '_' + key; + var innerPropertyDescriptor = { + configurable: true, + enumerable: false, + writable: true + }; var callbackName = config && config.changeHandler || key + 'Changed'; if (descriptor) { if (typeof descriptor.initializer === 'function') { - target[innerPropertyName] = descriptor.initializer(); + innerPropertyDescriptor.value = descriptor.initializer(); } } else { descriptor = {}; @@ -5280,15 +5285,21 @@ function observable(targetOrConfig, key, descriptor) { descriptor.enumerable = true; } + delete descriptor.value; delete descriptor.writable; delete descriptor.initializer; + Reflect.defineProperty(target, innerPropertyName, innerPropertyDescriptor); + descriptor.get = function () { return this[innerPropertyName]; }; descriptor.set = function (newValue) { var oldValue = this[innerPropertyName]; + this[innerPropertyName] = newValue; + Reflect.defineProperty(this, innerPropertyName, { enumerable: false }); + if (this[callbackName]) { this[callbackName](newValue, oldValue, key); } diff --git a/dist/es2015/aurelia-binding.js b/dist/es2015/aurelia-binding.js index 8a827da3..e1fe273f 100644 --- a/dist/es2015/aurelia-binding.js +++ b/dist/es2015/aurelia-binding.js @@ -3346,7 +3346,7 @@ export let StyleObserver = class StyleObserver { _setProperty(style, value) { let priority = ''; - if (value.indexOf('!important') !== -1) { + if (value.indexOf && value.indexOf('!important') !== -1) { priority = 'important'; value = value.replace('!important', ''); } @@ -4806,12 +4806,17 @@ export function observable(targetOrConfig, key, descriptor) { } let innerPropertyName = `_${ key }`; + const innerPropertyDescriptor = { + configurable: true, + enumerable: false, + writable: true + }; const callbackName = config && config.changeHandler || `${ key }Changed`; if (descriptor) { if (typeof descriptor.initializer === 'function') { - target[innerPropertyName] = descriptor.initializer(); + innerPropertyDescriptor.value = descriptor.initializer(); } } else { descriptor = {}; @@ -4821,15 +4826,21 @@ export function observable(targetOrConfig, key, descriptor) { descriptor.enumerable = true; } + delete descriptor.value; delete descriptor.writable; delete descriptor.initializer; + Reflect.defineProperty(target, innerPropertyName, innerPropertyDescriptor); + descriptor.get = function () { return this[innerPropertyName]; }; descriptor.set = function (newValue) { let oldValue = this[innerPropertyName]; + this[innerPropertyName] = newValue; + Reflect.defineProperty(this, innerPropertyName, { enumerable: false }); + if (this[callbackName]) { this[callbackName](newValue, oldValue, key); } diff --git a/dist/native-modules/aurelia-binding.js b/dist/native-modules/aurelia-binding.js index f435e639..9643689a 100644 --- a/dist/native-modules/aurelia-binding.js +++ b/dist/native-modules/aurelia-binding.js @@ -3610,7 +3610,7 @@ export var StyleObserver = function () { StyleObserver.prototype._setProperty = function _setProperty(style, value) { var priority = ''; - if (value.indexOf('!important') !== -1) { + if (value.indexOf && value.indexOf('!important') !== -1) { priority = 'important'; value = value.replace('!important', ''); } @@ -5227,12 +5227,17 @@ export function observable(targetOrConfig, key, descriptor) { } var innerPropertyName = '_' + key; + var innerPropertyDescriptor = { + configurable: true, + enumerable: false, + writable: true + }; var callbackName = config && config.changeHandler || key + 'Changed'; if (descriptor) { if (typeof descriptor.initializer === 'function') { - target[innerPropertyName] = descriptor.initializer(); + innerPropertyDescriptor.value = descriptor.initializer(); } } else { descriptor = {}; @@ -5242,15 +5247,21 @@ export function observable(targetOrConfig, key, descriptor) { descriptor.enumerable = true; } + delete descriptor.value; delete descriptor.writable; delete descriptor.initializer; + Reflect.defineProperty(target, innerPropertyName, innerPropertyDescriptor); + descriptor.get = function () { return this[innerPropertyName]; }; descriptor.set = function (newValue) { var oldValue = this[innerPropertyName]; + this[innerPropertyName] = newValue; + Reflect.defineProperty(this, innerPropertyName, { enumerable: false }); + if (this[callbackName]) { this[callbackName](newValue, oldValue, key); } diff --git a/dist/system/aurelia-binding.js b/dist/system/aurelia-binding.js index 20060ebc..0026f415 100644 --- a/dist/system/aurelia-binding.js +++ b/dist/system/aurelia-binding.js @@ -815,12 +815,17 @@ System.register(['aurelia-logging', 'aurelia-pal', 'aurelia-task-queue', 'aureli } var innerPropertyName = '_' + key; + var innerPropertyDescriptor = { + configurable: true, + enumerable: false, + writable: true + }; var callbackName = config && config.changeHandler || key + 'Changed'; if (descriptor) { if (typeof descriptor.initializer === 'function') { - target[innerPropertyName] = descriptor.initializer(); + innerPropertyDescriptor.value = descriptor.initializer(); } } else { descriptor = {}; @@ -830,15 +835,21 @@ System.register(['aurelia-logging', 'aurelia-pal', 'aurelia-task-queue', 'aureli descriptor.enumerable = true; } + delete descriptor.value; delete descriptor.writable; delete descriptor.initializer; + Reflect.defineProperty(target, innerPropertyName, innerPropertyDescriptor); + descriptor.get = function () { return this[innerPropertyName]; }; descriptor.set = function (newValue) { var oldValue = this[innerPropertyName]; + this[innerPropertyName] = newValue; + Reflect.defineProperty(this, innerPropertyName, { enumerable: false }); + if (this[callbackName]) { this[callbackName](newValue, oldValue, key); } @@ -3900,7 +3911,7 @@ System.register(['aurelia-logging', 'aurelia-pal', 'aurelia-task-queue', 'aureli StyleObserver.prototype._setProperty = function _setProperty(style, value) { var priority = ''; - if (value.indexOf('!important') !== -1) { + if (value.indexOf && value.indexOf('!important') !== -1) { priority = 'important'; value = value.replace('!important', ''); } diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 3eb9b93e..87a4c2fe 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,15 @@ + +## [1.0.7](https://github.com/aurelia/binding/compare/1.0.6...v1.0.7) (2016-10-05) + + +### Bug Fixes + +* **observable:** backing property should not be enumerable ([521270b](https://github.com/aurelia/binding/commit/521270b)) +* **observable:** handle descriptor with set ([fa3dafb](https://github.com/aurelia/binding/commit/fa3dafb)), closes [#511](https://github.com/aurelia/binding/issues/511) +* **StyleObserver:** handle numbers ([ca4933d](https://github.com/aurelia/binding/commit/ca4933d)), closes [#518](https://github.com/aurelia/binding/issues/518) + + + ## [1.0.6](https://github.com/aurelia/binding/compare/1.0.5...v1.0.6) (2016-09-29) diff --git a/doc/example-dist/binding-checkboxes/objects-matcher/app.html b/doc/example-dist/binding-checkboxes/objects-matcher/app.html index 1ede1e95..3e5a1ae7 100644 --- a/doc/example-dist/binding-checkboxes/objects-matcher/app.html +++ b/doc/example-dist/binding-checkboxes/objects-matcher/app.html @@ -11,13 +11,13 @@

Products

- Motherboard + CPU Selected products: diff --git a/doc/example-dist/binding-radios/objects-matcher/app.html b/doc/example-dist/binding-radios/objects-matcher/app.html index 05d81faa..42d10370 100644 --- a/doc/example-dist/binding-radios/objects-matcher/app.html +++ b/doc/example-dist/binding-radios/objects-matcher/app.html @@ -13,14 +13,14 @@

Products

model.bind="{ id: 1, name: 'CPU' }" matcher.bind="productMatcher" checked.bind="selectedProduct"> - Motherboard + CPU Selected product: ${selectedProduct.id} - ${selectedProduct.name} diff --git a/package.json b/package.json index 65965aaa..f0972832 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-binding", - "version": "1.0.6", + "version": "1.0.7", "description": "A modern databinding library for JavaScript and HTML.", "keywords": [ "aurelia",