From 87507ecd21989e06f46652baca198efd44683fd5 Mon Sep 17 00:00:00 2001 From: Rob Eisenberg Date: Tue, 14 Jul 2015 11:21:10 -0400 Subject: [PATCH] chore(all): prepare release 0.13.4 --- bower.json | 2 +- build/tasks/test.js | 12 +--- dist/amd/aurelia-templating.d.ts | 22 +++--- dist/amd/index.js | 95 +++++++++++++++++--------- dist/commonjs/aurelia-templating.d.ts | 22 +++--- dist/commonjs/index.js | 95 +++++++++++++++++--------- dist/es6/aurelia-templating.d.ts | 22 +++--- dist/es6/index.js | 61 +++++++++++------ dist/index.d.ts | 22 +++--- dist/index.js | 61 +++++++++++------ dist/system/aurelia-templating.d.ts | 22 +++--- dist/system/index.js | 97 +++++++++++++++++---------- doc/CHANGELOG.md | 8 +++ package.json | 2 +- test/html-behavior.spec.js | 2 +- 15 files changed, 348 insertions(+), 197 deletions(-) diff --git a/bower.json b/bower.json index 874f0760..27268fc7 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-templating", - "version": "0.13.3", + "version": "0.13.4", "description": "An extensible HTML templating engine supporting databinding, custom elements, attached behaviors and more.", "keywords": [ "aurelia", diff --git a/build/tasks/test.js b/build/tasks/test.js index 71884759..2fcefea8 100644 --- a/build/tasks/test.js +++ b/build/tasks/test.js @@ -8,9 +8,7 @@ gulp.task('test', function (done) { karma.start({ configFile: __dirname + '/../../karma.conf.js', singleRun: true - }, function(e) { - done(); - }); + }, done); }); /** @@ -19,9 +17,7 @@ gulp.task('test', function (done) { gulp.task('tdd', function (done) { karma.start({ configFile: __dirname + '/../../karma.conf.js' - }, function(e) { - done(); - }); + }, done); }); /** @@ -40,7 +36,5 @@ gulp.task('cover', function (done) { type: 'html', dir: 'build/reports/coverage' } - }, function (e) { - done(); - }); + }, done); }); diff --git a/dist/amd/aurelia-templating.d.ts b/dist/amd/aurelia-templating.d.ts index d13d77bd..83a558a7 100644 --- a/dist/amd/aurelia-templating.d.ts +++ b/dist/amd/aurelia-templating.d.ts @@ -99,12 +99,12 @@ declare module 'aurelia-templating' { } export class UseViewStrategy extends ViewStrategy { constructor(path: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; makeRelativeTo(file: any): any; } export class ConventionalViewStrategy extends ViewStrategy { constructor(moduleId: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; static convertModuleIdToViewUrl(moduleId: any): any; } export class NoViewStrategy extends ViewStrategy { @@ -112,7 +112,7 @@ declare module 'aurelia-templating' { } export class TemplateRegistryViewStrategy extends ViewStrategy { constructor(moduleId: any, registryEntry: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; } export class BindingLanguage { inspectAttribute(resources: any, attrName: any, attrValue: any): any; @@ -196,13 +196,17 @@ declare module 'aurelia-templating' { compileSurrogate(node: any, resources: any): any; compileElement(node: any, resources: any, instructions: any, parentNode: any, parentInjectorId: any, targetLightDOM: any): any; } + class ProxyViewFactory { + constructor(promise: any); + absorb(factory: any): any; + } export class ViewEngine { static inject(): any; constructor(loader: any, container: any, viewCompiler: any, moduleAnalyzer: any, appResources: any); - loadViewFactory(urlOrRegistryEntry: any, compileOptions: any, associatedModuleId: any): any; - loadTemplateResources(viewRegistryEntry: any, associatedModuleId: any): any; + loadViewFactory(urlOrRegistryEntry: any, compileOptions: any, associatedModuleId: any, loadContext: any): any; + loadTemplateResources(viewRegistryEntry: any, associatedModuleId: any, loadContext: any): any; importViewModelResource(moduleImport: any, moduleMember: any): any; - importViewResources(moduleIds: any, names: any, resources: any, associatedModuleId: any): any; + importViewResources(moduleIds: any, names: any, resources: any, associatedModuleId: any, loadContext: any): any; } export class BehaviorInstance { constructor(behavior: any, executionContext: any, instruction: any); @@ -234,7 +238,7 @@ declare module 'aurelia-templating' { static convention(name: any, existing: any): any; addChildBinding(behavior: any): any; analyze(container: any, target: any): any; - load(container: any, target: any, viewStrategy: any, transientView: any): any; + load(container: any, target: any, viewStrategy: any, transientView: any, loadContext: any): any; register(registry: any, name: any): any; compile(compiler: any, resources: any, node: any, instruction: any, parentNode: any): any; create(container: any, instruction?: any, element?: any, bindings?: any): any; @@ -244,13 +248,13 @@ declare module 'aurelia-templating' { constructor(moduleId: any); analyze(container: any): any; register(registry: any, name: any): any; - load(container: any): any; + load(container: any, loadContext: any): any; } export class ResourceDescription { constructor(key: any, exportedValue: any, resourceTypeMeta: any); analyze(container: any): any; register(registry: any, name: any): any; - load(container: any): any; + load(container: any, loadContext: any): any; static get(resource: any, key?: any): any; } export class ModuleAnalyzer { diff --git a/dist/amd/index.js b/dist/amd/index.js index 8edb587c..072aab72 100644 --- a/dist/amd/index.js +++ b/dist/amd/index.js @@ -191,12 +191,12 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen _inherits(UseViewStrategy, _ViewStrategy); - UseViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options) { + UseViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options, loadContext) { if (!this.absolutePath && this.moduleId) { this.absolutePath = _aureliaPath.relativeToFile(this.path, this.moduleId); } - return viewEngine.loadViewFactory(this.absolutePath || this.path, options, this.moduleId); + return viewEngine.loadViewFactory(this.absolutePath || this.path, options, this.moduleId, loadContext); }; UseViewStrategy.prototype.makeRelativeTo = function makeRelativeTo(file) { @@ -219,8 +219,8 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen _inherits(ConventionalViewStrategy, _ViewStrategy2); - ConventionalViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options) { - return viewEngine.loadViewFactory(this.viewUrl, options, this.moduleId); + ConventionalViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options, loadContext) { + return viewEngine.loadViewFactory(this.viewUrl, options, this.moduleId, loadContext); }; ConventionalViewStrategy.convertModuleIdToViewUrl = function convertModuleIdToViewUrl(moduleId) { @@ -262,12 +262,12 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen _inherits(TemplateRegistryViewStrategy, _ViewStrategy4); - TemplateRegistryViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options) { + TemplateRegistryViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options, loadContext) { if (this.registryEntry.isReady) { return Promise.resolve(this.registryEntry.factory); } - return viewEngine.loadViewFactory(this.registryEntry, options, this.moduleId); + return viewEngine.loadViewFactory(this.registryEntry, options, this.moduleId, loadContext); }; return TemplateRegistryViewStrategy; @@ -1710,6 +1710,24 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen return loader.loadTemplate(urlOrRegistryEntry); } + var ProxyViewFactory = (function () { + function ProxyViewFactory(promise) { + var _this4 = this; + + _classCallCheck(this, ProxyViewFactory); + + promise.then(function (x) { + return _this4.absorb(x); + }); + } + + ProxyViewFactory.prototype.absorb = function absorb(factory) { + this.create = factory.create.bind(factory); + }; + + return ProxyViewFactory; + })(); + var ViewEngine = (function () { function ViewEngine(loader, container, viewCompiler, moduleAnalyzer, appResources) { _classCallCheck(this, ViewEngine); @@ -1725,24 +1743,33 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen return [_aureliaLoader.Loader, _aureliaDependencyInjection.Container, ViewCompiler, ModuleAnalyzer, ResourceRegistry]; }; - ViewEngine.prototype.loadViewFactory = function loadViewFactory(urlOrRegistryEntry, compileOptions, associatedModuleId) { - var _this4 = this; + ViewEngine.prototype.loadViewFactory = function loadViewFactory(urlOrRegistryEntry, compileOptions, associatedModuleId, loadContext) { + var _this5 = this; + + loadContext = loadContext || []; return ensureRegistryEntry(this.loader, urlOrRegistryEntry).then(function (viewRegistryEntry) { if (viewRegistryEntry.onReady) { - return viewRegistryEntry.onReady; + if (loadContext.indexOf(urlOrRegistryEntry) === -1) { + loadContext.push(urlOrRegistryEntry); + return viewRegistryEntry.onReady; + } + + return Promise.resolve(new ProxyViewFactory(viewRegistryEntry.onReady)); } - return viewRegistryEntry.onReady = _this4.loadTemplateResources(viewRegistryEntry, associatedModuleId).then(function (resources) { + loadContext.push(urlOrRegistryEntry); + + return viewRegistryEntry.onReady = _this5.loadTemplateResources(viewRegistryEntry, associatedModuleId, loadContext).then(function (resources) { viewRegistryEntry.setResources(resources); - var viewFactory = _this4.viewCompiler.compile(viewRegistryEntry.template, resources, compileOptions); + var viewFactory = _this5.viewCompiler.compile(viewRegistryEntry.template, resources, compileOptions); viewRegistryEntry.setFactory(viewFactory); return viewFactory; }); }); }; - ViewEngine.prototype.loadTemplateResources = function loadTemplateResources(viewRegistryEntry, associatedModuleId) { + ViewEngine.prototype.loadTemplateResources = function loadTemplateResources(viewRegistryEntry, associatedModuleId, loadContext) { var resources = new ViewResources(this.appResources, viewRegistryEntry.id), dependencies = viewRegistryEntry.dependencies, importIds, @@ -1760,28 +1787,30 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen }); logger.debug('importing resources for ' + viewRegistryEntry.id, importIds); - return this.importViewResources(importIds, names, resources, associatedModuleId); + return this.importViewResources(importIds, names, resources, associatedModuleId, loadContext); }; ViewEngine.prototype.importViewModelResource = function importViewModelResource(moduleImport, moduleMember) { - var _this5 = this; + var _this6 = this; return this.loader.loadModule(moduleImport).then(function (viewModelModule) { var normalizedId = _aureliaMetadata.Origin.get(viewModelModule).moduleId, - resourceModule = _this5.moduleAnalyzer.analyze(normalizedId, viewModelModule, moduleMember); + resourceModule = _this6.moduleAnalyzer.analyze(normalizedId, viewModelModule, moduleMember); if (!resourceModule.mainResource) { throw new Error('No view model found in module "' + moduleImport + '".'); } - resourceModule.analyze(_this5.container); + resourceModule.analyze(_this6.container); return resourceModule.mainResource; }); }; - ViewEngine.prototype.importViewResources = function importViewResources(moduleIds, names, resources, associatedModuleId) { - var _this6 = this; + ViewEngine.prototype.importViewResources = function importViewResources(moduleIds, names, resources, associatedModuleId, loadContext) { + var _this7 = this; + + loadContext = loadContext || []; return this.loader.loadAllModules(moduleIds).then(function (imports) { var i, @@ -1790,8 +1819,8 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen normalizedId, current, associatedModule, - container = _this6.container, - moduleAnalyzer = _this6.moduleAnalyzer, + container = _this7.container, + moduleAnalyzer = _this7.moduleAnalyzer, allAnalysis = new Array(imports.length); for (i = 0, ii = imports.length; i < ii; ++i) { @@ -1814,7 +1843,7 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen } for (i = 0, ii = allAnalysis.length; i < ii; ++i) { - allAnalysis[i] = allAnalysis[i].load(container); + allAnalysis[i] = allAnalysis[i].load(container, loadContext); } return Promise.all(allAnalysis).then(function () { @@ -2342,8 +2371,8 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen } }; - HtmlBehaviorResource.prototype.load = function load(container, target, viewStrategy, transientView) { - var _this7 = this; + HtmlBehaviorResource.prototype.load = function load(container, target, viewStrategy, transientView, loadContext) { + var _this8 = this; var options; @@ -2358,9 +2387,9 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen viewStrategy.moduleId = _aureliaMetadata.Origin.get(target).moduleId; } - return viewStrategy.loadViewFactory(container.get(ViewEngine), options).then(function (viewFactory) { - if (!transientView || !_this7.viewFactory) { - _this7.viewFactory = viewFactory; + return viewStrategy.loadViewFactory(container.get(ViewEngine), options, loadContext).then(function (viewFactory) { + if (!transientView || !_this8.viewFactory) { + _this8.viewFactory = viewFactory; } return viewFactory; @@ -2619,7 +2648,7 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen } }; - ResourceModule.prototype.load = function load(container) { + ResourceModule.prototype.load = function load(container, loadContext) { if (this.onLoaded) { return this.onLoaded; } @@ -2631,11 +2660,11 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen loads = []; if (current) { - loads.push(current.load(container)); + loads.push(current.load(container, loadContext)); } for (i = 0, ii = resources.length; i < ii; ++i) { - loads.push(resources[i].load(container)); + loads.push(resources[i].load(container, loadContext)); } this.onLoaded = Promise.all(loads); @@ -2690,12 +2719,12 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen this.metadata.register(registry, name); }; - ResourceDescription.prototype.load = function load(container) { + ResourceDescription.prototype.load = function load(container, loadContext) { var metadata = this.metadata, value = this.value; if ('load' in metadata) { - return metadata.load(container, value); + return metadata.load(container, value, null, null, loadContext); } }; @@ -3053,7 +3082,7 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen }; CompositionEngine.prototype.compose = function compose(instruction) { - var _this8 = this; + var _this9 = this; instruction.childContainer = instruction.childContainer || instruction.container.createChild(); instruction.view = ViewStrategy.normalize(instruction.view); @@ -3061,7 +3090,7 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depen if (instruction.viewModel) { if (typeof instruction.viewModel === 'string') { return this.createViewModel(instruction).then(function (instruction) { - return _this8.createBehaviorAndSwap(instruction); + return _this9.createBehaviorAndSwap(instruction); }); } else { return this.createBehaviorAndSwap(instruction); diff --git a/dist/commonjs/aurelia-templating.d.ts b/dist/commonjs/aurelia-templating.d.ts index d13d77bd..83a558a7 100644 --- a/dist/commonjs/aurelia-templating.d.ts +++ b/dist/commonjs/aurelia-templating.d.ts @@ -99,12 +99,12 @@ declare module 'aurelia-templating' { } export class UseViewStrategy extends ViewStrategy { constructor(path: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; makeRelativeTo(file: any): any; } export class ConventionalViewStrategy extends ViewStrategy { constructor(moduleId: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; static convertModuleIdToViewUrl(moduleId: any): any; } export class NoViewStrategy extends ViewStrategy { @@ -112,7 +112,7 @@ declare module 'aurelia-templating' { } export class TemplateRegistryViewStrategy extends ViewStrategy { constructor(moduleId: any, registryEntry: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; } export class BindingLanguage { inspectAttribute(resources: any, attrName: any, attrValue: any): any; @@ -196,13 +196,17 @@ declare module 'aurelia-templating' { compileSurrogate(node: any, resources: any): any; compileElement(node: any, resources: any, instructions: any, parentNode: any, parentInjectorId: any, targetLightDOM: any): any; } + class ProxyViewFactory { + constructor(promise: any); + absorb(factory: any): any; + } export class ViewEngine { static inject(): any; constructor(loader: any, container: any, viewCompiler: any, moduleAnalyzer: any, appResources: any); - loadViewFactory(urlOrRegistryEntry: any, compileOptions: any, associatedModuleId: any): any; - loadTemplateResources(viewRegistryEntry: any, associatedModuleId: any): any; + loadViewFactory(urlOrRegistryEntry: any, compileOptions: any, associatedModuleId: any, loadContext: any): any; + loadTemplateResources(viewRegistryEntry: any, associatedModuleId: any, loadContext: any): any; importViewModelResource(moduleImport: any, moduleMember: any): any; - importViewResources(moduleIds: any, names: any, resources: any, associatedModuleId: any): any; + importViewResources(moduleIds: any, names: any, resources: any, associatedModuleId: any, loadContext: any): any; } export class BehaviorInstance { constructor(behavior: any, executionContext: any, instruction: any); @@ -234,7 +238,7 @@ declare module 'aurelia-templating' { static convention(name: any, existing: any): any; addChildBinding(behavior: any): any; analyze(container: any, target: any): any; - load(container: any, target: any, viewStrategy: any, transientView: any): any; + load(container: any, target: any, viewStrategy: any, transientView: any, loadContext: any): any; register(registry: any, name: any): any; compile(compiler: any, resources: any, node: any, instruction: any, parentNode: any): any; create(container: any, instruction?: any, element?: any, bindings?: any): any; @@ -244,13 +248,13 @@ declare module 'aurelia-templating' { constructor(moduleId: any); analyze(container: any): any; register(registry: any, name: any): any; - load(container: any): any; + load(container: any, loadContext: any): any; } export class ResourceDescription { constructor(key: any, exportedValue: any, resourceTypeMeta: any); analyze(container: any): any; register(registry: any, name: any): any; - load(container: any): any; + load(container: any, loadContext: any): any; static get(resource: any, key?: any): any; } export class ModuleAnalyzer { diff --git a/dist/commonjs/index.js b/dist/commonjs/index.js index 70259153..599c4d45 100644 --- a/dist/commonjs/index.js +++ b/dist/commonjs/index.js @@ -210,12 +210,12 @@ var UseViewStrategy = (function (_ViewStrategy) { _inherits(UseViewStrategy, _ViewStrategy); - UseViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options) { + UseViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options, loadContext) { if (!this.absolutePath && this.moduleId) { this.absolutePath = _aureliaPath.relativeToFile(this.path, this.moduleId); } - return viewEngine.loadViewFactory(this.absolutePath || this.path, options, this.moduleId); + return viewEngine.loadViewFactory(this.absolutePath || this.path, options, this.moduleId, loadContext); }; UseViewStrategy.prototype.makeRelativeTo = function makeRelativeTo(file) { @@ -238,8 +238,8 @@ var ConventionalViewStrategy = (function (_ViewStrategy2) { _inherits(ConventionalViewStrategy, _ViewStrategy2); - ConventionalViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options) { - return viewEngine.loadViewFactory(this.viewUrl, options, this.moduleId); + ConventionalViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options, loadContext) { + return viewEngine.loadViewFactory(this.viewUrl, options, this.moduleId, loadContext); }; ConventionalViewStrategy.convertModuleIdToViewUrl = function convertModuleIdToViewUrl(moduleId) { @@ -281,12 +281,12 @@ var TemplateRegistryViewStrategy = (function (_ViewStrategy4) { _inherits(TemplateRegistryViewStrategy, _ViewStrategy4); - TemplateRegistryViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options) { + TemplateRegistryViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options, loadContext) { if (this.registryEntry.isReady) { return Promise.resolve(this.registryEntry.factory); } - return viewEngine.loadViewFactory(this.registryEntry, options, this.moduleId); + return viewEngine.loadViewFactory(this.registryEntry, options, this.moduleId, loadContext); }; return TemplateRegistryViewStrategy; @@ -1729,6 +1729,24 @@ function ensureRegistryEntry(loader, urlOrRegistryEntry) { return loader.loadTemplate(urlOrRegistryEntry); } +var ProxyViewFactory = (function () { + function ProxyViewFactory(promise) { + var _this4 = this; + + _classCallCheck(this, ProxyViewFactory); + + promise.then(function (x) { + return _this4.absorb(x); + }); + } + + ProxyViewFactory.prototype.absorb = function absorb(factory) { + this.create = factory.create.bind(factory); + }; + + return ProxyViewFactory; +})(); + var ViewEngine = (function () { function ViewEngine(loader, container, viewCompiler, moduleAnalyzer, appResources) { _classCallCheck(this, ViewEngine); @@ -1744,24 +1762,33 @@ var ViewEngine = (function () { return [_aureliaLoader.Loader, _aureliaDependencyInjection.Container, ViewCompiler, ModuleAnalyzer, ResourceRegistry]; }; - ViewEngine.prototype.loadViewFactory = function loadViewFactory(urlOrRegistryEntry, compileOptions, associatedModuleId) { - var _this4 = this; + ViewEngine.prototype.loadViewFactory = function loadViewFactory(urlOrRegistryEntry, compileOptions, associatedModuleId, loadContext) { + var _this5 = this; + + loadContext = loadContext || []; return ensureRegistryEntry(this.loader, urlOrRegistryEntry).then(function (viewRegistryEntry) { if (viewRegistryEntry.onReady) { - return viewRegistryEntry.onReady; + if (loadContext.indexOf(urlOrRegistryEntry) === -1) { + loadContext.push(urlOrRegistryEntry); + return viewRegistryEntry.onReady; + } + + return Promise.resolve(new ProxyViewFactory(viewRegistryEntry.onReady)); } - return viewRegistryEntry.onReady = _this4.loadTemplateResources(viewRegistryEntry, associatedModuleId).then(function (resources) { + loadContext.push(urlOrRegistryEntry); + + return viewRegistryEntry.onReady = _this5.loadTemplateResources(viewRegistryEntry, associatedModuleId, loadContext).then(function (resources) { viewRegistryEntry.setResources(resources); - var viewFactory = _this4.viewCompiler.compile(viewRegistryEntry.template, resources, compileOptions); + var viewFactory = _this5.viewCompiler.compile(viewRegistryEntry.template, resources, compileOptions); viewRegistryEntry.setFactory(viewFactory); return viewFactory; }); }); }; - ViewEngine.prototype.loadTemplateResources = function loadTemplateResources(viewRegistryEntry, associatedModuleId) { + ViewEngine.prototype.loadTemplateResources = function loadTemplateResources(viewRegistryEntry, associatedModuleId, loadContext) { var resources = new ViewResources(this.appResources, viewRegistryEntry.id), dependencies = viewRegistryEntry.dependencies, importIds, @@ -1779,28 +1806,30 @@ var ViewEngine = (function () { }); logger.debug('importing resources for ' + viewRegistryEntry.id, importIds); - return this.importViewResources(importIds, names, resources, associatedModuleId); + return this.importViewResources(importIds, names, resources, associatedModuleId, loadContext); }; ViewEngine.prototype.importViewModelResource = function importViewModelResource(moduleImport, moduleMember) { - var _this5 = this; + var _this6 = this; return this.loader.loadModule(moduleImport).then(function (viewModelModule) { var normalizedId = _aureliaMetadata.Origin.get(viewModelModule).moduleId, - resourceModule = _this5.moduleAnalyzer.analyze(normalizedId, viewModelModule, moduleMember); + resourceModule = _this6.moduleAnalyzer.analyze(normalizedId, viewModelModule, moduleMember); if (!resourceModule.mainResource) { throw new Error('No view model found in module "' + moduleImport + '".'); } - resourceModule.analyze(_this5.container); + resourceModule.analyze(_this6.container); return resourceModule.mainResource; }); }; - ViewEngine.prototype.importViewResources = function importViewResources(moduleIds, names, resources, associatedModuleId) { - var _this6 = this; + ViewEngine.prototype.importViewResources = function importViewResources(moduleIds, names, resources, associatedModuleId, loadContext) { + var _this7 = this; + + loadContext = loadContext || []; return this.loader.loadAllModules(moduleIds).then(function (imports) { var i, @@ -1809,8 +1838,8 @@ var ViewEngine = (function () { normalizedId, current, associatedModule, - container = _this6.container, - moduleAnalyzer = _this6.moduleAnalyzer, + container = _this7.container, + moduleAnalyzer = _this7.moduleAnalyzer, allAnalysis = new Array(imports.length); for (i = 0, ii = imports.length; i < ii; ++i) { @@ -1833,7 +1862,7 @@ var ViewEngine = (function () { } for (i = 0, ii = allAnalysis.length; i < ii; ++i) { - allAnalysis[i] = allAnalysis[i].load(container); + allAnalysis[i] = allAnalysis[i].load(container, loadContext); } return Promise.all(allAnalysis).then(function () { @@ -2361,8 +2390,8 @@ var HtmlBehaviorResource = (function () { } }; - HtmlBehaviorResource.prototype.load = function load(container, target, viewStrategy, transientView) { - var _this7 = this; + HtmlBehaviorResource.prototype.load = function load(container, target, viewStrategy, transientView, loadContext) { + var _this8 = this; var options; @@ -2377,9 +2406,9 @@ var HtmlBehaviorResource = (function () { viewStrategy.moduleId = _aureliaMetadata.Origin.get(target).moduleId; } - return viewStrategy.loadViewFactory(container.get(ViewEngine), options).then(function (viewFactory) { - if (!transientView || !_this7.viewFactory) { - _this7.viewFactory = viewFactory; + return viewStrategy.loadViewFactory(container.get(ViewEngine), options, loadContext).then(function (viewFactory) { + if (!transientView || !_this8.viewFactory) { + _this8.viewFactory = viewFactory; } return viewFactory; @@ -2638,7 +2667,7 @@ var ResourceModule = (function () { } }; - ResourceModule.prototype.load = function load(container) { + ResourceModule.prototype.load = function load(container, loadContext) { if (this.onLoaded) { return this.onLoaded; } @@ -2650,11 +2679,11 @@ var ResourceModule = (function () { loads = []; if (current) { - loads.push(current.load(container)); + loads.push(current.load(container, loadContext)); } for (i = 0, ii = resources.length; i < ii; ++i) { - loads.push(resources[i].load(container)); + loads.push(resources[i].load(container, loadContext)); } this.onLoaded = Promise.all(loads); @@ -2709,12 +2738,12 @@ var ResourceDescription = (function () { this.metadata.register(registry, name); }; - ResourceDescription.prototype.load = function load(container) { + ResourceDescription.prototype.load = function load(container, loadContext) { var metadata = this.metadata, value = this.value; if ('load' in metadata) { - return metadata.load(container, value); + return metadata.load(container, value, null, null, loadContext); } }; @@ -3072,7 +3101,7 @@ var CompositionEngine = (function () { }; CompositionEngine.prototype.compose = function compose(instruction) { - var _this8 = this; + var _this9 = this; instruction.childContainer = instruction.childContainer || instruction.container.createChild(); instruction.view = ViewStrategy.normalize(instruction.view); @@ -3080,7 +3109,7 @@ var CompositionEngine = (function () { if (instruction.viewModel) { if (typeof instruction.viewModel === 'string') { return this.createViewModel(instruction).then(function (instruction) { - return _this8.createBehaviorAndSwap(instruction); + return _this9.createBehaviorAndSwap(instruction); }); } else { return this.createBehaviorAndSwap(instruction); diff --git a/dist/es6/aurelia-templating.d.ts b/dist/es6/aurelia-templating.d.ts index d13d77bd..83a558a7 100644 --- a/dist/es6/aurelia-templating.d.ts +++ b/dist/es6/aurelia-templating.d.ts @@ -99,12 +99,12 @@ declare module 'aurelia-templating' { } export class UseViewStrategy extends ViewStrategy { constructor(path: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; makeRelativeTo(file: any): any; } export class ConventionalViewStrategy extends ViewStrategy { constructor(moduleId: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; static convertModuleIdToViewUrl(moduleId: any): any; } export class NoViewStrategy extends ViewStrategy { @@ -112,7 +112,7 @@ declare module 'aurelia-templating' { } export class TemplateRegistryViewStrategy extends ViewStrategy { constructor(moduleId: any, registryEntry: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; } export class BindingLanguage { inspectAttribute(resources: any, attrName: any, attrValue: any): any; @@ -196,13 +196,17 @@ declare module 'aurelia-templating' { compileSurrogate(node: any, resources: any): any; compileElement(node: any, resources: any, instructions: any, parentNode: any, parentInjectorId: any, targetLightDOM: any): any; } + class ProxyViewFactory { + constructor(promise: any); + absorb(factory: any): any; + } export class ViewEngine { static inject(): any; constructor(loader: any, container: any, viewCompiler: any, moduleAnalyzer: any, appResources: any); - loadViewFactory(urlOrRegistryEntry: any, compileOptions: any, associatedModuleId: any): any; - loadTemplateResources(viewRegistryEntry: any, associatedModuleId: any): any; + loadViewFactory(urlOrRegistryEntry: any, compileOptions: any, associatedModuleId: any, loadContext: any): any; + loadTemplateResources(viewRegistryEntry: any, associatedModuleId: any, loadContext: any): any; importViewModelResource(moduleImport: any, moduleMember: any): any; - importViewResources(moduleIds: any, names: any, resources: any, associatedModuleId: any): any; + importViewResources(moduleIds: any, names: any, resources: any, associatedModuleId: any, loadContext: any): any; } export class BehaviorInstance { constructor(behavior: any, executionContext: any, instruction: any); @@ -234,7 +238,7 @@ declare module 'aurelia-templating' { static convention(name: any, existing: any): any; addChildBinding(behavior: any): any; analyze(container: any, target: any): any; - load(container: any, target: any, viewStrategy: any, transientView: any): any; + load(container: any, target: any, viewStrategy: any, transientView: any, loadContext: any): any; register(registry: any, name: any): any; compile(compiler: any, resources: any, node: any, instruction: any, parentNode: any): any; create(container: any, instruction?: any, element?: any, bindings?: any): any; @@ -244,13 +248,13 @@ declare module 'aurelia-templating' { constructor(moduleId: any); analyze(container: any): any; register(registry: any, name: any): any; - load(container: any): any; + load(container: any, loadContext: any): any; } export class ResourceDescription { constructor(key: any, exportedValue: any, resourceTypeMeta: any); analyze(container: any): any; register(registry: any, name: any): any; - load(container: any): any; + load(container: any, loadContext: any): any; static get(resource: any, key?: any): any; } export class ModuleAnalyzer { diff --git a/dist/es6/index.js b/dist/es6/index.js index bd3cc1ee..88b0e6b2 100644 --- a/dist/es6/index.js +++ b/dist/es6/index.js @@ -199,12 +199,12 @@ export class UseViewStrategy extends ViewStrategy { this.path = path; } - loadViewFactory(viewEngine, options){ + loadViewFactory(viewEngine, options, loadContext){ if(!this.absolutePath && this.moduleId){ this.absolutePath = relativeToFile(this.path, this.moduleId); } - return viewEngine.loadViewFactory(this.absolutePath || this.path, options, this.moduleId); + return viewEngine.loadViewFactory(this.absolutePath || this.path, options, this.moduleId, loadContext); } makeRelativeTo(file){ @@ -219,8 +219,8 @@ export class ConventionalViewStrategy extends ViewStrategy { this.viewUrl = ConventionalViewStrategy.convertModuleIdToViewUrl(moduleId); } - loadViewFactory(viewEngine, options){ - return viewEngine.loadViewFactory(this.viewUrl, options, this.moduleId); + loadViewFactory(viewEngine, options, loadContext){ + return viewEngine.loadViewFactory(this.viewUrl, options, this.moduleId, loadContext); } static convertModuleIdToViewUrl(moduleId){ @@ -242,12 +242,12 @@ export class TemplateRegistryViewStrategy extends ViewStrategy { this.registryEntry = registryEntry; } - loadViewFactory(viewEngine, options){ + loadViewFactory(viewEngine, options, loadContext){ if(this.registryEntry.isReady){ return Promise.resolve(this.registryEntry.factory); } - return viewEngine.loadViewFactory(this.registryEntry, options, this.moduleId); + return viewEngine.loadViewFactory(this.registryEntry, options, this.moduleId, loadContext); } } @@ -1595,6 +1595,16 @@ function ensureRegistryEntry(loader, urlOrRegistryEntry){ return loader.loadTemplate(urlOrRegistryEntry); } +class ProxyViewFactory { + constructor(promise){ + promise.then(x => this.absorb(x)); + } + + absorb(factory){ + this.create = factory.create.bind(factory); + } +} + export class ViewEngine { static inject() { return [Loader, Container, ViewCompiler, ModuleAnalyzer, ResourceRegistry]; } constructor(loader, container, viewCompiler, moduleAnalyzer, appResources){ @@ -1605,13 +1615,22 @@ export class ViewEngine { this.appResources = appResources; } - loadViewFactory(urlOrRegistryEntry, compileOptions, associatedModuleId){ + loadViewFactory(urlOrRegistryEntry, compileOptions, associatedModuleId, loadContext){ + loadContext = loadContext || []; + return ensureRegistryEntry(this.loader, urlOrRegistryEntry).then(viewRegistryEntry => { if(viewRegistryEntry.onReady){ - return viewRegistryEntry.onReady; + if(loadContext.indexOf(urlOrRegistryEntry) === -1){ + loadContext.push(urlOrRegistryEntry); + return viewRegistryEntry.onReady; + } + + return Promise.resolve(new ProxyViewFactory(viewRegistryEntry.onReady)); } - return viewRegistryEntry.onReady = this.loadTemplateResources(viewRegistryEntry, associatedModuleId).then(resources => { + loadContext.push(urlOrRegistryEntry); + + return viewRegistryEntry.onReady = this.loadTemplateResources(viewRegistryEntry, associatedModuleId, loadContext).then(resources => { viewRegistryEntry.setResources(resources); var viewFactory = this.viewCompiler.compile(viewRegistryEntry.template, resources, compileOptions); viewRegistryEntry.setFactory(viewFactory); @@ -1620,7 +1639,7 @@ export class ViewEngine { }); } - loadTemplateResources(viewRegistryEntry, associatedModuleId){ + loadTemplateResources(viewRegistryEntry, associatedModuleId, loadContext){ var resources = new ViewResources(this.appResources, viewRegistryEntry.id), dependencies = viewRegistryEntry.dependencies, importIds, names; @@ -1633,7 +1652,7 @@ export class ViewEngine { names = dependencies.map(x => x.name); logger.debug(`importing resources for ${viewRegistryEntry.id}`, importIds); - return this.importViewResources(importIds, names, resources, associatedModuleId); + return this.importViewResources(importIds, names, resources, associatedModuleId, loadContext); } importViewModelResource(moduleImport, moduleMember){ @@ -1651,7 +1670,9 @@ export class ViewEngine { }); } - importViewResources(moduleIds, names, resources, associatedModuleId){ + importViewResources(moduleIds, names, resources, associatedModuleId, loadContext){ + loadContext = loadContext || []; + return this.loader.loadAllModules(moduleIds).then(imports => { var i, ii, analysis, normalizedId, current, associatedModule, container = this.container, @@ -1683,7 +1704,7 @@ export class ViewEngine { //cause compile/load of any associated views second //as a result all globals have access to all other globals during compilation for(i = 0, ii = allAnalysis.length; i < ii; ++i){ - allAnalysis[i] = allAnalysis[i].load(container); + allAnalysis[i] = allAnalysis[i].load(container, loadContext); } return Promise.all(allAnalysis).then(() => resources); @@ -2169,7 +2190,7 @@ export class HtmlBehaviorResource { } } - load(container, target, viewStrategy, transientView){ + load(container, target, viewStrategy, transientView, loadContext){ var options; if(this.elementName !== null){ @@ -2183,7 +2204,7 @@ export class HtmlBehaviorResource { viewStrategy.moduleId = Origin.get(target).moduleId; } - return viewStrategy.loadViewFactory(container.get(ViewEngine), options).then(viewFactory => { + return viewStrategy.loadViewFactory(container.get(ViewEngine), options, loadContext).then(viewFactory => { if(!transientView || !this.viewFactory){ this.viewFactory = viewFactory; } @@ -2439,7 +2460,7 @@ export class ResourceModule { } } - load(container){ + load(container, loadContext){ if(this.onLoaded){ return this.onLoaded; } @@ -2449,11 +2470,11 @@ export class ResourceModule { i, ii, loads = []; if(current){ - loads.push(current.load(container)); + loads.push(current.load(container, loadContext)); } for(i = 0, ii = resources.length; i < ii; ++i){ - loads.push(resources[i].load(container)); + loads.push(resources[i].load(container, loadContext)); } this.onLoaded = Promise.all(loads); @@ -2505,12 +2526,12 @@ export class ResourceDescription { this.metadata.register(registry, name); } - load(container){ + load(container, loadContext){ let metadata = this.metadata, value = this.value; if('load' in metadata){ - return metadata.load(container, value); + return metadata.load(container, value, null, null, loadContext); } } diff --git a/dist/index.d.ts b/dist/index.d.ts index d13d77bd..83a558a7 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -99,12 +99,12 @@ declare module 'aurelia-templating' { } export class UseViewStrategy extends ViewStrategy { constructor(path: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; makeRelativeTo(file: any): any; } export class ConventionalViewStrategy extends ViewStrategy { constructor(moduleId: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; static convertModuleIdToViewUrl(moduleId: any): any; } export class NoViewStrategy extends ViewStrategy { @@ -112,7 +112,7 @@ declare module 'aurelia-templating' { } export class TemplateRegistryViewStrategy extends ViewStrategy { constructor(moduleId: any, registryEntry: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; } export class BindingLanguage { inspectAttribute(resources: any, attrName: any, attrValue: any): any; @@ -196,13 +196,17 @@ declare module 'aurelia-templating' { compileSurrogate(node: any, resources: any): any; compileElement(node: any, resources: any, instructions: any, parentNode: any, parentInjectorId: any, targetLightDOM: any): any; } + class ProxyViewFactory { + constructor(promise: any); + absorb(factory: any): any; + } export class ViewEngine { static inject(): any; constructor(loader: any, container: any, viewCompiler: any, moduleAnalyzer: any, appResources: any); - loadViewFactory(urlOrRegistryEntry: any, compileOptions: any, associatedModuleId: any): any; - loadTemplateResources(viewRegistryEntry: any, associatedModuleId: any): any; + loadViewFactory(urlOrRegistryEntry: any, compileOptions: any, associatedModuleId: any, loadContext: any): any; + loadTemplateResources(viewRegistryEntry: any, associatedModuleId: any, loadContext: any): any; importViewModelResource(moduleImport: any, moduleMember: any): any; - importViewResources(moduleIds: any, names: any, resources: any, associatedModuleId: any): any; + importViewResources(moduleIds: any, names: any, resources: any, associatedModuleId: any, loadContext: any): any; } export class BehaviorInstance { constructor(behavior: any, executionContext: any, instruction: any); @@ -234,7 +238,7 @@ declare module 'aurelia-templating' { static convention(name: any, existing: any): any; addChildBinding(behavior: any): any; analyze(container: any, target: any): any; - load(container: any, target: any, viewStrategy: any, transientView: any): any; + load(container: any, target: any, viewStrategy: any, transientView: any, loadContext: any): any; register(registry: any, name: any): any; compile(compiler: any, resources: any, node: any, instruction: any, parentNode: any): any; create(container: any, instruction?: any, element?: any, bindings?: any): any; @@ -244,13 +248,13 @@ declare module 'aurelia-templating' { constructor(moduleId: any); analyze(container: any): any; register(registry: any, name: any): any; - load(container: any): any; + load(container: any, loadContext: any): any; } export class ResourceDescription { constructor(key: any, exportedValue: any, resourceTypeMeta: any); analyze(container: any): any; register(registry: any, name: any): any; - load(container: any): any; + load(container: any, loadContext: any): any; static get(resource: any, key?: any): any; } export class ModuleAnalyzer { diff --git a/dist/index.js b/dist/index.js index bd3cc1ee..88b0e6b2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -199,12 +199,12 @@ export class UseViewStrategy extends ViewStrategy { this.path = path; } - loadViewFactory(viewEngine, options){ + loadViewFactory(viewEngine, options, loadContext){ if(!this.absolutePath && this.moduleId){ this.absolutePath = relativeToFile(this.path, this.moduleId); } - return viewEngine.loadViewFactory(this.absolutePath || this.path, options, this.moduleId); + return viewEngine.loadViewFactory(this.absolutePath || this.path, options, this.moduleId, loadContext); } makeRelativeTo(file){ @@ -219,8 +219,8 @@ export class ConventionalViewStrategy extends ViewStrategy { this.viewUrl = ConventionalViewStrategy.convertModuleIdToViewUrl(moduleId); } - loadViewFactory(viewEngine, options){ - return viewEngine.loadViewFactory(this.viewUrl, options, this.moduleId); + loadViewFactory(viewEngine, options, loadContext){ + return viewEngine.loadViewFactory(this.viewUrl, options, this.moduleId, loadContext); } static convertModuleIdToViewUrl(moduleId){ @@ -242,12 +242,12 @@ export class TemplateRegistryViewStrategy extends ViewStrategy { this.registryEntry = registryEntry; } - loadViewFactory(viewEngine, options){ + loadViewFactory(viewEngine, options, loadContext){ if(this.registryEntry.isReady){ return Promise.resolve(this.registryEntry.factory); } - return viewEngine.loadViewFactory(this.registryEntry, options, this.moduleId); + return viewEngine.loadViewFactory(this.registryEntry, options, this.moduleId, loadContext); } } @@ -1595,6 +1595,16 @@ function ensureRegistryEntry(loader, urlOrRegistryEntry){ return loader.loadTemplate(urlOrRegistryEntry); } +class ProxyViewFactory { + constructor(promise){ + promise.then(x => this.absorb(x)); + } + + absorb(factory){ + this.create = factory.create.bind(factory); + } +} + export class ViewEngine { static inject() { return [Loader, Container, ViewCompiler, ModuleAnalyzer, ResourceRegistry]; } constructor(loader, container, viewCompiler, moduleAnalyzer, appResources){ @@ -1605,13 +1615,22 @@ export class ViewEngine { this.appResources = appResources; } - loadViewFactory(urlOrRegistryEntry, compileOptions, associatedModuleId){ + loadViewFactory(urlOrRegistryEntry, compileOptions, associatedModuleId, loadContext){ + loadContext = loadContext || []; + return ensureRegistryEntry(this.loader, urlOrRegistryEntry).then(viewRegistryEntry => { if(viewRegistryEntry.onReady){ - return viewRegistryEntry.onReady; + if(loadContext.indexOf(urlOrRegistryEntry) === -1){ + loadContext.push(urlOrRegistryEntry); + return viewRegistryEntry.onReady; + } + + return Promise.resolve(new ProxyViewFactory(viewRegistryEntry.onReady)); } - return viewRegistryEntry.onReady = this.loadTemplateResources(viewRegistryEntry, associatedModuleId).then(resources => { + loadContext.push(urlOrRegistryEntry); + + return viewRegistryEntry.onReady = this.loadTemplateResources(viewRegistryEntry, associatedModuleId, loadContext).then(resources => { viewRegistryEntry.setResources(resources); var viewFactory = this.viewCompiler.compile(viewRegistryEntry.template, resources, compileOptions); viewRegistryEntry.setFactory(viewFactory); @@ -1620,7 +1639,7 @@ export class ViewEngine { }); } - loadTemplateResources(viewRegistryEntry, associatedModuleId){ + loadTemplateResources(viewRegistryEntry, associatedModuleId, loadContext){ var resources = new ViewResources(this.appResources, viewRegistryEntry.id), dependencies = viewRegistryEntry.dependencies, importIds, names; @@ -1633,7 +1652,7 @@ export class ViewEngine { names = dependencies.map(x => x.name); logger.debug(`importing resources for ${viewRegistryEntry.id}`, importIds); - return this.importViewResources(importIds, names, resources, associatedModuleId); + return this.importViewResources(importIds, names, resources, associatedModuleId, loadContext); } importViewModelResource(moduleImport, moduleMember){ @@ -1651,7 +1670,9 @@ export class ViewEngine { }); } - importViewResources(moduleIds, names, resources, associatedModuleId){ + importViewResources(moduleIds, names, resources, associatedModuleId, loadContext){ + loadContext = loadContext || []; + return this.loader.loadAllModules(moduleIds).then(imports => { var i, ii, analysis, normalizedId, current, associatedModule, container = this.container, @@ -1683,7 +1704,7 @@ export class ViewEngine { //cause compile/load of any associated views second //as a result all globals have access to all other globals during compilation for(i = 0, ii = allAnalysis.length; i < ii; ++i){ - allAnalysis[i] = allAnalysis[i].load(container); + allAnalysis[i] = allAnalysis[i].load(container, loadContext); } return Promise.all(allAnalysis).then(() => resources); @@ -2169,7 +2190,7 @@ export class HtmlBehaviorResource { } } - load(container, target, viewStrategy, transientView){ + load(container, target, viewStrategy, transientView, loadContext){ var options; if(this.elementName !== null){ @@ -2183,7 +2204,7 @@ export class HtmlBehaviorResource { viewStrategy.moduleId = Origin.get(target).moduleId; } - return viewStrategy.loadViewFactory(container.get(ViewEngine), options).then(viewFactory => { + return viewStrategy.loadViewFactory(container.get(ViewEngine), options, loadContext).then(viewFactory => { if(!transientView || !this.viewFactory){ this.viewFactory = viewFactory; } @@ -2439,7 +2460,7 @@ export class ResourceModule { } } - load(container){ + load(container, loadContext){ if(this.onLoaded){ return this.onLoaded; } @@ -2449,11 +2470,11 @@ export class ResourceModule { i, ii, loads = []; if(current){ - loads.push(current.load(container)); + loads.push(current.load(container, loadContext)); } for(i = 0, ii = resources.length; i < ii; ++i){ - loads.push(resources[i].load(container)); + loads.push(resources[i].load(container, loadContext)); } this.onLoaded = Promise.all(loads); @@ -2505,12 +2526,12 @@ export class ResourceDescription { this.metadata.register(registry, name); } - load(container){ + load(container, loadContext){ let metadata = this.metadata, value = this.value; if('load' in metadata){ - return metadata.load(container, value); + return metadata.load(container, value, null, null, loadContext); } } diff --git a/dist/system/aurelia-templating.d.ts b/dist/system/aurelia-templating.d.ts index d13d77bd..83a558a7 100644 --- a/dist/system/aurelia-templating.d.ts +++ b/dist/system/aurelia-templating.d.ts @@ -99,12 +99,12 @@ declare module 'aurelia-templating' { } export class UseViewStrategy extends ViewStrategy { constructor(path: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; makeRelativeTo(file: any): any; } export class ConventionalViewStrategy extends ViewStrategy { constructor(moduleId: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; static convertModuleIdToViewUrl(moduleId: any): any; } export class NoViewStrategy extends ViewStrategy { @@ -112,7 +112,7 @@ declare module 'aurelia-templating' { } export class TemplateRegistryViewStrategy extends ViewStrategy { constructor(moduleId: any, registryEntry: any); - loadViewFactory(viewEngine: any, options: any): any; + loadViewFactory(viewEngine: any, options: any, loadContext: any): any; } export class BindingLanguage { inspectAttribute(resources: any, attrName: any, attrValue: any): any; @@ -196,13 +196,17 @@ declare module 'aurelia-templating' { compileSurrogate(node: any, resources: any): any; compileElement(node: any, resources: any, instructions: any, parentNode: any, parentInjectorId: any, targetLightDOM: any): any; } + class ProxyViewFactory { + constructor(promise: any); + absorb(factory: any): any; + } export class ViewEngine { static inject(): any; constructor(loader: any, container: any, viewCompiler: any, moduleAnalyzer: any, appResources: any); - loadViewFactory(urlOrRegistryEntry: any, compileOptions: any, associatedModuleId: any): any; - loadTemplateResources(viewRegistryEntry: any, associatedModuleId: any): any; + loadViewFactory(urlOrRegistryEntry: any, compileOptions: any, associatedModuleId: any, loadContext: any): any; + loadTemplateResources(viewRegistryEntry: any, associatedModuleId: any, loadContext: any): any; importViewModelResource(moduleImport: any, moduleMember: any): any; - importViewResources(moduleIds: any, names: any, resources: any, associatedModuleId: any): any; + importViewResources(moduleIds: any, names: any, resources: any, associatedModuleId: any, loadContext: any): any; } export class BehaviorInstance { constructor(behavior: any, executionContext: any, instruction: any); @@ -234,7 +238,7 @@ declare module 'aurelia-templating' { static convention(name: any, existing: any): any; addChildBinding(behavior: any): any; analyze(container: any, target: any): any; - load(container: any, target: any, viewStrategy: any, transientView: any): any; + load(container: any, target: any, viewStrategy: any, transientView: any, loadContext: any): any; register(registry: any, name: any): any; compile(compiler: any, resources: any, node: any, instruction: any, parentNode: any): any; create(container: any, instruction?: any, element?: any, bindings?: any): any; @@ -244,13 +248,13 @@ declare module 'aurelia-templating' { constructor(moduleId: any); analyze(container: any): any; register(registry: any, name: any): any; - load(container: any): any; + load(container: any, loadContext: any): any; } export class ResourceDescription { constructor(key: any, exportedValue: any, resourceTypeMeta: any); analyze(container: any): any; register(registry: any, name: any): any; - load(container: any): any; + load(container: any, loadContext: any): any; static get(resource: any, key?: any): any; } export class ModuleAnalyzer { diff --git a/dist/system/index.js b/dist/system/index.js index e4c4b7b8..1c74518f 100644 --- a/dist/system/index.js +++ b/dist/system/index.js @@ -1,7 +1,7 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-dependency-injection', 'aurelia-loader', 'aurelia-binding', 'aurelia-task-queue', 'aurelia-logging'], function (_export) { 'use strict'; - var core, Metadata, Origin, Decorators, relativeToFile, Container, Loader, TemplateRegistryEntry, bindingMode, ObserverLocator, ValueConverterResource, EventManager, TaskQueue, LogManager, animationEvent, Animator, capitalMatcher, ViewStrategy, UseViewStrategy, ConventionalViewStrategy, NoViewStrategy, TemplateRegistryViewStrategy, BindingLanguage, ResourceRegistry, ViewResources, View, proto, placeholder, ContentSelector, ViewSlot, BoundViewFactory, defaultFactoryOptions, ViewFactory, nextInjectorId, defaultCompileOptions, hasShadowDOM, needsTemplateFixup, ViewCompiler, logger, ViewEngine, BehaviorInstance, BindableProperty, BehaviorPropertyObserver, defaultInstruction, contentSelectorFactoryOptions, hasShadowDOM, HtmlBehaviorResource, ResourceModule, ResourceDescription, ModuleAnalyzer, noMutations, ChildObserver, ChildObserverBinder, CompositionEngine, ElementConfigResource; + var core, Metadata, Origin, Decorators, relativeToFile, Container, Loader, TemplateRegistryEntry, bindingMode, ObserverLocator, ValueConverterResource, EventManager, TaskQueue, LogManager, animationEvent, Animator, capitalMatcher, ViewStrategy, UseViewStrategy, ConventionalViewStrategy, NoViewStrategy, TemplateRegistryViewStrategy, BindingLanguage, ResourceRegistry, ViewResources, View, proto, placeholder, ContentSelector, ViewSlot, BoundViewFactory, defaultFactoryOptions, ViewFactory, nextInjectorId, defaultCompileOptions, hasShadowDOM, needsTemplateFixup, ViewCompiler, logger, ProxyViewFactory, ViewEngine, BehaviorInstance, BindableProperty, BehaviorPropertyObserver, defaultInstruction, contentSelectorFactoryOptions, hasShadowDOM, HtmlBehaviorResource, ResourceModule, ResourceDescription, ModuleAnalyzer, noMutations, ChildObserver, ChildObserverBinder, CompositionEngine, ElementConfigResource; var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); @@ -627,12 +627,12 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende _inherits(UseViewStrategy, _ViewStrategy); - UseViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options) { + UseViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options, loadContext) { if (!this.absolutePath && this.moduleId) { this.absolutePath = relativeToFile(this.path, this.moduleId); } - return viewEngine.loadViewFactory(this.absolutePath || this.path, options, this.moduleId); + return viewEngine.loadViewFactory(this.absolutePath || this.path, options, this.moduleId, loadContext); }; UseViewStrategy.prototype.makeRelativeTo = function makeRelativeTo(file) { @@ -655,8 +655,8 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende _inherits(ConventionalViewStrategy, _ViewStrategy2); - ConventionalViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options) { - return viewEngine.loadViewFactory(this.viewUrl, options, this.moduleId); + ConventionalViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options, loadContext) { + return viewEngine.loadViewFactory(this.viewUrl, options, this.moduleId, loadContext); }; ConventionalViewStrategy.convertModuleIdToViewUrl = function convertModuleIdToViewUrl(moduleId) { @@ -698,12 +698,12 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende _inherits(TemplateRegistryViewStrategy, _ViewStrategy4); - TemplateRegistryViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options) { + TemplateRegistryViewStrategy.prototype.loadViewFactory = function loadViewFactory(viewEngine, options, loadContext) { if (this.registryEntry.isReady) { return Promise.resolve(this.registryEntry.factory); } - return viewEngine.loadViewFactory(this.registryEntry, options, this.moduleId); + return viewEngine.loadViewFactory(this.registryEntry, options, this.moduleId, loadContext); }; return TemplateRegistryViewStrategy; @@ -1907,6 +1907,24 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende logger = LogManager.getLogger('templating'); + ProxyViewFactory = (function () { + function ProxyViewFactory(promise) { + var _this4 = this; + + _classCallCheck(this, ProxyViewFactory); + + promise.then(function (x) { + return _this4.absorb(x); + }); + } + + ProxyViewFactory.prototype.absorb = function absorb(factory) { + this.create = factory.create.bind(factory); + }; + + return ProxyViewFactory; + })(); + ViewEngine = (function () { function ViewEngine(loader, container, viewCompiler, moduleAnalyzer, appResources) { _classCallCheck(this, ViewEngine); @@ -1922,24 +1940,33 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende return [Loader, Container, ViewCompiler, ModuleAnalyzer, ResourceRegistry]; }; - ViewEngine.prototype.loadViewFactory = function loadViewFactory(urlOrRegistryEntry, compileOptions, associatedModuleId) { - var _this4 = this; + ViewEngine.prototype.loadViewFactory = function loadViewFactory(urlOrRegistryEntry, compileOptions, associatedModuleId, loadContext) { + var _this5 = this; + + loadContext = loadContext || []; return ensureRegistryEntry(this.loader, urlOrRegistryEntry).then(function (viewRegistryEntry) { if (viewRegistryEntry.onReady) { - return viewRegistryEntry.onReady; + if (loadContext.indexOf(urlOrRegistryEntry) === -1) { + loadContext.push(urlOrRegistryEntry); + return viewRegistryEntry.onReady; + } + + return Promise.resolve(new ProxyViewFactory(viewRegistryEntry.onReady)); } - return viewRegistryEntry.onReady = _this4.loadTemplateResources(viewRegistryEntry, associatedModuleId).then(function (resources) { + loadContext.push(urlOrRegistryEntry); + + return viewRegistryEntry.onReady = _this5.loadTemplateResources(viewRegistryEntry, associatedModuleId, loadContext).then(function (resources) { viewRegistryEntry.setResources(resources); - var viewFactory = _this4.viewCompiler.compile(viewRegistryEntry.template, resources, compileOptions); + var viewFactory = _this5.viewCompiler.compile(viewRegistryEntry.template, resources, compileOptions); viewRegistryEntry.setFactory(viewFactory); return viewFactory; }); }); }; - ViewEngine.prototype.loadTemplateResources = function loadTemplateResources(viewRegistryEntry, associatedModuleId) { + ViewEngine.prototype.loadTemplateResources = function loadTemplateResources(viewRegistryEntry, associatedModuleId, loadContext) { var resources = new ViewResources(this.appResources, viewRegistryEntry.id), dependencies = viewRegistryEntry.dependencies, importIds, @@ -1957,28 +1984,30 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende }); logger.debug('importing resources for ' + viewRegistryEntry.id, importIds); - return this.importViewResources(importIds, names, resources, associatedModuleId); + return this.importViewResources(importIds, names, resources, associatedModuleId, loadContext); }; ViewEngine.prototype.importViewModelResource = function importViewModelResource(moduleImport, moduleMember) { - var _this5 = this; + var _this6 = this; return this.loader.loadModule(moduleImport).then(function (viewModelModule) { var normalizedId = Origin.get(viewModelModule).moduleId, - resourceModule = _this5.moduleAnalyzer.analyze(normalizedId, viewModelModule, moduleMember); + resourceModule = _this6.moduleAnalyzer.analyze(normalizedId, viewModelModule, moduleMember); if (!resourceModule.mainResource) { throw new Error('No view model found in module "' + moduleImport + '".'); } - resourceModule.analyze(_this5.container); + resourceModule.analyze(_this6.container); return resourceModule.mainResource; }); }; - ViewEngine.prototype.importViewResources = function importViewResources(moduleIds, names, resources, associatedModuleId) { - var _this6 = this; + ViewEngine.prototype.importViewResources = function importViewResources(moduleIds, names, resources, associatedModuleId, loadContext) { + var _this7 = this; + + loadContext = loadContext || []; return this.loader.loadAllModules(moduleIds).then(function (imports) { var i, @@ -1987,8 +2016,8 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende normalizedId, current, associatedModule, - container = _this6.container, - moduleAnalyzer = _this6.moduleAnalyzer, + container = _this7.container, + moduleAnalyzer = _this7.moduleAnalyzer, allAnalysis = new Array(imports.length); for (i = 0, ii = imports.length; i < ii; ++i) { @@ -2011,7 +2040,7 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende } for (i = 0, ii = allAnalysis.length; i < ii; ++i) { - allAnalysis[i] = allAnalysis[i].load(container); + allAnalysis[i] = allAnalysis[i].load(container, loadContext); } return Promise.all(allAnalysis).then(function () { @@ -2528,8 +2557,8 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende } }; - HtmlBehaviorResource.prototype.load = function load(container, target, viewStrategy, transientView) { - var _this7 = this; + HtmlBehaviorResource.prototype.load = function load(container, target, viewStrategy, transientView, loadContext) { + var _this8 = this; var options; @@ -2544,9 +2573,9 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende viewStrategy.moduleId = Origin.get(target).moduleId; } - return viewStrategy.loadViewFactory(container.get(ViewEngine), options).then(function (viewFactory) { - if (!transientView || !_this7.viewFactory) { - _this7.viewFactory = viewFactory; + return viewStrategy.loadViewFactory(container.get(ViewEngine), options, loadContext).then(function (viewFactory) { + if (!transientView || !_this8.viewFactory) { + _this8.viewFactory = viewFactory; } return viewFactory; @@ -2805,7 +2834,7 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende } }; - ResourceModule.prototype.load = function load(container) { + ResourceModule.prototype.load = function load(container, loadContext) { if (this.onLoaded) { return this.onLoaded; } @@ -2817,11 +2846,11 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende loads = []; if (current) { - loads.push(current.load(container)); + loads.push(current.load(container, loadContext)); } for (i = 0, ii = resources.length; i < ii; ++i) { - loads.push(resources[i].load(container)); + loads.push(resources[i].load(container, loadContext)); } this.onLoaded = Promise.all(loads); @@ -2876,12 +2905,12 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende this.metadata.register(registry, name); }; - ResourceDescription.prototype.load = function load(container) { + ResourceDescription.prototype.load = function load(container, loadContext) { var metadata = this.metadata, value = this.value; if ('load' in metadata) { - return metadata.load(container, value); + return metadata.load(container, value, null, null, loadContext); } }; @@ -3239,7 +3268,7 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende }; CompositionEngine.prototype.compose = function compose(instruction) { - var _this8 = this; + var _this9 = this; instruction.childContainer = instruction.childContainer || instruction.container.createChild(); instruction.view = ViewStrategy.normalize(instruction.view); @@ -3247,7 +3276,7 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-depende if (instruction.viewModel) { if (typeof instruction.viewModel === 'string') { return this.createViewModel(instruction).then(function (instruction) { - return _this8.createBehaviorAndSwap(instruction); + return _this9.createBehaviorAndSwap(instruction); }); } else { return this.createBehaviorAndSwap(instruction); diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index c651012c..fe68d92e 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,11 @@ +### 0.13.4 (2015-07-14) + + +#### Bug Fixes + +* **view-engine:** handle circular references between views ([5e023a59](http://github.com/aurelia/templating/commit/5e023a59fc12867a0c1d8bb00399f0e3f4ce53b6)) + + ### 0.13.3 (2015-07-13) diff --git a/package.json b/package.json index 0ca2679f..1ba02d42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-templating", - "version": "0.13.3", + "version": "0.13.4", "description": "An extensible HTML templating engine supporting databinding, custom elements, attached behaviors and more.", "keywords": [ "aurelia", diff --git a/test/html-behavior.spec.js b/test/html-behavior.spec.js index 933dcac0..e69a726b 100644 --- a/test/html-behavior.spec.js +++ b/test/html-behavior.spec.js @@ -36,4 +36,4 @@ describe('html-behavior', () => { expect(resource.attributes['test'].defaultBindingMode).toBe(bindingMode.twoWay); }); -}); \ No newline at end of file +});