diff --git a/bower.json b/bower.json index b6f4894..2400a6c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-templating-resources", - "version": "0.8.6", + "version": "0.8.7", "description": "A standard set of behaviors, converters and other resources for use with the Aurelia templating library.", "keywords": [ "aurelia", diff --git a/dist/amd/repeat.js b/dist/amd/repeat.js index 7c5ff19..eaf195e 100644 --- a/dist/amd/repeat.js +++ b/dist/amd/repeat.js @@ -39,6 +39,14 @@ define(["exports", "aurelia-binding", "aurelia-templating"], function (exports, this.executionContext = executionContext; + if (!items) { + if (this.oldItems) { + this.viewSlot.removeAll(); + } + + return; + } + if (this.oldItems === items) { var splices = calcSplices(items, 0, items.length, this.lastBoundItems, 0, this.lastBoundItems.length); var observer = this.observerLocator.getArrayObserver(items); @@ -59,7 +67,10 @@ define(["exports", "aurelia-binding", "aurelia-templating"], function (exports, unbind: { value: function unbind() { this.oldItems = this.items; - this.lastBoundItems = this.items.slice(0); + + if (this.items) { + this.lastBoundItems = this.items.slice(0); + } if (this.disposeArraySubscription) { this.disposeArraySubscription(); @@ -80,19 +91,25 @@ define(["exports", "aurelia-binding", "aurelia-templating"], function (exports, value: function processItems() { var _this = this; var items = this.items, - observer = this.observerLocator.getArrayObserver(items), viewSlot = this.viewSlot, viewFactory = this.viewFactory, i, ii, row, - view; + view, + observer; if (this.disposeArraySubscription) { this.disposeArraySubscription(); viewSlot.removeAll(); } + if (!items) { + return; + } + + observer = this.observerLocator.getArrayObserver(items); + for (i = 0, ii = items.length; i < ii; ++i) { row = this.createFullExecutionContext(items[i], i, ii); view = viewFactory.create(row); diff --git a/dist/commonjs/repeat.js b/dist/commonjs/repeat.js index 5f737df..af64987 100644 --- a/dist/commonjs/repeat.js +++ b/dist/commonjs/repeat.js @@ -42,6 +42,14 @@ var Repeat = exports.Repeat = (function () { this.executionContext = executionContext; + if (!items) { + if (this.oldItems) { + this.viewSlot.removeAll(); + } + + return; + } + if (this.oldItems === items) { var splices = calcSplices(items, 0, items.length, this.lastBoundItems, 0, this.lastBoundItems.length); var observer = this.observerLocator.getArrayObserver(items); @@ -62,7 +70,10 @@ var Repeat = exports.Repeat = (function () { unbind: { value: function unbind() { this.oldItems = this.items; - this.lastBoundItems = this.items.slice(0); + + if (this.items) { + this.lastBoundItems = this.items.slice(0); + } if (this.disposeArraySubscription) { this.disposeArraySubscription(); @@ -83,19 +94,25 @@ var Repeat = exports.Repeat = (function () { value: function processItems() { var _this = this; var items = this.items, - observer = this.observerLocator.getArrayObserver(items), viewSlot = this.viewSlot, viewFactory = this.viewFactory, i, ii, row, - view; + view, + observer; if (this.disposeArraySubscription) { this.disposeArraySubscription(); viewSlot.removeAll(); } + if (!items) { + return; + } + + observer = this.observerLocator.getArrayObserver(items); + for (i = 0, ii = items.length; i < ii; ++i) { row = this.createFullExecutionContext(items[i], i, ii); view = viewFactory.create(row); diff --git a/dist/es6/repeat.js b/dist/es6/repeat.js index 03b8570..cc4795c 100644 --- a/dist/es6/repeat.js +++ b/dist/es6/repeat.js @@ -22,13 +22,21 @@ export class Repeat { this.executionContext = executionContext; + if(!items){ + if(this.oldItems){ + this.viewSlot.removeAll(); + } + + return; + } + if(this.oldItems === items){ var splices = calcSplices(items, 0, items.length, this.lastBoundItems, 0, this.lastBoundItems.length); var observer = this.observerLocator.getArrayObserver(items); this.handleSplices(items, splices); this.lastBoundItems = this.oldItems = null; - + this.disposeArraySubscription = observer.subscribe(splices => { this.handleSplices(items, splices); }); @@ -39,7 +47,10 @@ export class Repeat { unbind(){ this.oldItems = this.items; - this.lastBoundItems = this.items.slice(0); + + if(this.items){ + this.lastBoundItems = this.items.slice(0); + } if(this.disposeArraySubscription){ this.disposeArraySubscription(); @@ -53,16 +64,21 @@ export class Repeat { processItems(){ var items = this.items, - observer = this.observerLocator.getArrayObserver(items), viewSlot = this.viewSlot, viewFactory = this.viewFactory, - i, ii, row, view; + i, ii, row, view, observer; - if(this.disposeArraySubscription){ + if (this.disposeArraySubscription) { this.disposeArraySubscription(); viewSlot.removeAll(); } + if(!items){ + return; + } + + observer = this.observerLocator.getArrayObserver(items); + for(i = 0, ii = items.length; i < ii; ++i){ row = this.createFullExecutionContext(items[i], i, ii); view = viewFactory.create(row); @@ -89,7 +105,7 @@ export class Repeat { var first = (index === 0), last = (index === length - 1), even = index % 2 === 0; - + context.$parent = this.executionContext; context.$index = index; context.$first = first; @@ -119,7 +135,7 @@ export class Repeat { for (j = 0, jj = removed.length; j < jj; ++j) { model = removed[j]; view = viewSlot.removeAt(splice.index + removeDelta); - + if (view) { viewLookup.set(model, view); } @@ -157,4 +173,4 @@ export class Repeat { viewLookup.forEach(x => x.unbind()); } -} \ No newline at end of file +} diff --git a/dist/system/repeat.js b/dist/system/repeat.js index c8b9010..e2c1d2c 100644 --- a/dist/system/repeat.js +++ b/dist/system/repeat.js @@ -45,6 +45,14 @@ System.register(["aurelia-binding", "aurelia-templating"], function (_export) { this.executionContext = executionContext; + if (!items) { + if (this.oldItems) { + this.viewSlot.removeAll(); + } + + return; + } + if (this.oldItems === items) { var splices = calcSplices(items, 0, items.length, this.lastBoundItems, 0, this.lastBoundItems.length); var observer = this.observerLocator.getArrayObserver(items); @@ -65,7 +73,10 @@ System.register(["aurelia-binding", "aurelia-templating"], function (_export) { unbind: { value: function unbind() { this.oldItems = this.items; - this.lastBoundItems = this.items.slice(0); + + if (this.items) { + this.lastBoundItems = this.items.slice(0); + } if (this.disposeArraySubscription) { this.disposeArraySubscription(); @@ -86,19 +97,25 @@ System.register(["aurelia-binding", "aurelia-templating"], function (_export) { value: function processItems() { var _this = this; var items = this.items, - observer = this.observerLocator.getArrayObserver(items), viewSlot = this.viewSlot, viewFactory = this.viewFactory, i, ii, row, - view; + view, + observer; if (this.disposeArraySubscription) { this.disposeArraySubscription(); viewSlot.removeAll(); } + if (!items) { + return; + } + + observer = this.observerLocator.getArrayObserver(items); + for (i = 0, ii = items.length; i < ii; ++i) { row = this.createFullExecutionContext(items[i], i, ii); view = viewFactory.create(row); diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index d3cac33..4610de2 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,11 @@ +### 0.8.7 (2015-02-06) + + +#### Bug Fixes + +* **repeat:** error when items are undefined ([11809714](http://github.com/aurelia/templating-resources/commit/118097145e3d7a936280f9110c44b6724ed51ba2)) + + ### 0.8.6 (2015-02-06) diff --git a/package.json b/package.json index 4f9be57..bfcbdc4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-templating-resources", - "version": "0.8.6", + "version": "0.8.7", "description": "A standard set of behaviors, converters and other resources for use with the Aurelia templating library.", "keywords": [ "aurelia",