Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(all): new template registry and global loader
This is a BREAKING CHANGE. The new base loader manages a template registry. This is uses to properly track loaded templates, their dependencies, the final view resources associated with each template and the factory that instantiates views from the template. This is a foundational pieces used by concrete loaders. The default-loader leverages this as part of the way it plugs into the system and require.js loader. This commit also the old createDefaultLoader api in favor of using a global variable for this so that it’s easier to re-use the bootstrapper. Finally, we have changes the name of the “import” element to “au-import” This makes it clearer that this is part of Aurelia as well enables supporting IE9.
- Loading branch information
1 parent
ebf815c
commit 99ec5e2
Showing
5 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import {relativeToFile} from 'aurelia-path'; | ||
|
||
export class TemplateDependency { | ||
constructor(src, name){ | ||
this.src = src; | ||
this.name = name; | ||
} | ||
} | ||
|
||
export class TemplateRegistryEntry { | ||
constructor(id){ | ||
this.id = id; | ||
this.template = null; | ||
this.dependencies = null; | ||
this.resources = null; | ||
this.factory = null; | ||
} | ||
|
||
get templateIsLoaded(){ | ||
return this.template !== null; | ||
} | ||
|
||
get isReady(){ | ||
return this.factory !== null; | ||
} | ||
|
||
setTemplate(template){ | ||
var id = this.id, | ||
auImportElements, i, ii, current, src; | ||
|
||
this.template = template; | ||
auImportElements = template.content.querySelectorAll('au-import'); | ||
this.dependencies = new Array(auImportElements.length); | ||
|
||
if(auImportElements.length === 0){ | ||
return; | ||
} | ||
|
||
for(i = 0, ii = auImportElements.length; i < ii; ++i){ | ||
current = auImportElements[i]; | ||
src = current.getAttribute('from'); | ||
|
||
if(!src){ | ||
throw new Error(`au-import element in ${this.id} has no "from" attribute.`); | ||
} | ||
|
||
this.dependencies[i] = new TemplateDependency( | ||
relativeToFile(src, id), | ||
current.getAttribute('as') | ||
); | ||
|
||
if(current.parentNode){ | ||
current.parentNode.removeChild(current); | ||
} | ||
} | ||
} | ||
|
||
setResources(resources){ | ||
this.resources = resources; | ||
} | ||
|
||
setFactory(factory){ | ||
this.factory = factory; | ||
} | ||
} |