Skip to content

Commit

Permalink
feat(view-engine): preliminary support for element enhancement
Browse files Browse the repository at this point in the history
This may change in implementation and api when the web components
export is implemented. However, this appears to work for now.
  • Loading branch information
EisenbergEffect committed Jul 31, 2015
1 parent 91724b4 commit e807868
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 18 deletions.
1 change: 1 addition & 0 deletions dist/amd/aurelia-templating.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ declare module 'aurelia-templating' {
export class ViewEngine {
static inject(): any;
constructor(loader: Loader, container: Container, viewCompiler: ViewCompiler, moduleAnalyzer: ModuleAnalyzer, appResources: ResourceRegistry);
enhance(container: any, element: any, resources: any, bindingContext: any): any;
loadViewFactory(urlOrRegistryEntry: string | TemplateRegistryEntry, compileOptions?: Object, associatedModuleId?: string, loadContext?: string[]): Promise<ViewFactory>;
loadTemplateResources(viewRegistryEntry: TemplateRegistryEntry, associatedModuleId?: string, loadContext?: string[]): Promise<ResourceRegistry>;
importViewModelResource(moduleImport: string, moduleMember: string): Promise<ResourceDescription>;
Expand Down
23 changes: 20 additions & 3 deletions dist/amd/aurelia-templating.js
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,8 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-loade

var defaultFactoryOptions = {
systemControlled: false,
suppressBind: false
suppressBind: false,
enhance: false
};

var ViewFactory = (function () {
Expand All @@ -1355,7 +1356,7 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-loade
var options = arguments[2] === undefined ? defaultFactoryOptions : arguments[2];
var element = arguments[3] === undefined ? null : arguments[3];

var fragment = this.template.cloneNode(true),
var fragment = options.enhance ? this.template : this.template.cloneNode(true),
instructables = fragment.querySelectorAll('.au-target'),
instructions = this.instructions,
resources = this.resources,
Expand Down Expand Up @@ -1880,6 +1881,21 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-loade
return [_aureliaLoader.Loader, _aureliaDependencyInjection.Container, ViewCompiler, ModuleAnalyzer, ResourceRegistry];
};

ViewEngine.prototype.enhance = function enhance(container, element, resources, bindingContext) {
var instructions = {};

this.viewCompiler.compileNode(element, resources, instructions, element.parentNode, 'root', true);

var factory = new ViewFactory(element, instructions, resources);
var options = {
systemControlled: false,
suppressBind: false,
enhance: true
};

return factory.create(container, bindingContext, options);
};

ViewEngine.prototype.loadViewFactory = function loadViewFactory(urlOrRegistryEntry, compileOptions, associatedModuleId, loadContext) {
var _this5 = this;

Expand Down Expand Up @@ -2402,7 +2418,7 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-loade
})();

var defaultInstruction = { suppressBind: false },
contentSelectorFactoryOptions = { suppressBind: true },
contentSelectorFactoryOptions = { suppressBind: true, enhance: false },
hasShadowDOM = !!HTMLElement.prototype.createShadowRoot;

function doProcessContent() {
Expand Down Expand Up @@ -2654,6 +2670,7 @@ define(['exports', 'core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-loade
element.primaryBehavior = behaviorInstance;
} else if (this.elementName !== null) {
viewFactory = instruction.viewFactory || this.viewFactory;
container.viewModel = executionContext;

if (viewFactory) {
behaviorInstance.view = viewFactory.create(container, executionContext, instruction, element);
Expand Down
1 change: 1 addition & 0 deletions dist/aurelia-templating.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ declare module 'aurelia-templating' {
export class ViewEngine {
static inject(): any;
constructor(loader: Loader, container: Container, viewCompiler: ViewCompiler, moduleAnalyzer: ModuleAnalyzer, appResources: ResourceRegistry);
enhance(container: any, element: any, resources: any, bindingContext: any): any;
loadViewFactory(urlOrRegistryEntry: string | TemplateRegistryEntry, compileOptions?: Object, associatedModuleId?: string, loadContext?: string[]): Promise<ViewFactory>;
loadTemplateResources(viewRegistryEntry: TemplateRegistryEntry, associatedModuleId?: string, loadContext?: string[]): Promise<ResourceRegistry>;
importViewModelResource(moduleImport: string, moduleMember: string): Promise<ResourceDescription>;
Expand Down
23 changes: 20 additions & 3 deletions dist/aurelia-templating.js
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,8 @@ export class BoundViewFactory {

var defaultFactoryOptions = {
systemControlled:false,
suppressBind:false
suppressBind:false,
enhance:false
};

export class ViewFactory{
Expand All @@ -1249,7 +1250,7 @@ export class ViewFactory{
}

create(container, executionContext, options=defaultFactoryOptions, element=null){
var fragment = this.template.cloneNode(true),
var fragment = options.enhance ? this.template : this.template.cloneNode(true),
instructables = fragment.querySelectorAll('.au-target'),
instructions = this.instructions,
resources = this.resources,
Expand Down Expand Up @@ -1720,6 +1721,21 @@ export class ViewEngine {
this.appResources = appResources;
}

enhance(container, element, resources, bindingContext){
let instructions = {};

this.viewCompiler.compileNode(element, resources, instructions, element.parentNode, 'root', true);

let factory = new ViewFactory(element, instructions, resources);
let options = {
systemControlled:false,
suppressBind:false,
enhance:true
};

return factory.create(container, bindingContext, options);
}

loadViewFactory(urlOrRegistryEntry:string|TemplateRegistryEntry, compileOptions?:Object, associatedModuleId?:string, loadContext?:string[]):Promise<ViewFactory>{
loadContext = loadContext || [];

Expand Down Expand Up @@ -2195,7 +2211,7 @@ class BehaviorPropertyObserver {
}

var defaultInstruction = { suppressBind:false },
contentSelectorFactoryOptions = { suppressBind:true },
contentSelectorFactoryOptions = { suppressBind:true, enhance:false },
hasShadowDOM = !!HTMLElement.prototype.createShadowRoot;

function doProcessContent(){
Expand Down Expand Up @@ -2439,6 +2455,7 @@ export class HtmlBehaviorResource {
} else if(this.elementName !== null){
//custom element
viewFactory = instruction.viewFactory || this.viewFactory;
container.viewModel = executionContext;

if(viewFactory){
behaviorInstance.view = viewFactory.create(container, executionContext, instruction, element);
Expand Down
1 change: 1 addition & 0 deletions dist/commonjs/aurelia-templating.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ declare module 'aurelia-templating' {
export class ViewEngine {
static inject(): any;
constructor(loader: Loader, container: Container, viewCompiler: ViewCompiler, moduleAnalyzer: ModuleAnalyzer, appResources: ResourceRegistry);
enhance(container: any, element: any, resources: any, bindingContext: any): any;
loadViewFactory(urlOrRegistryEntry: string | TemplateRegistryEntry, compileOptions?: Object, associatedModuleId?: string, loadContext?: string[]): Promise<ViewFactory>;
loadTemplateResources(viewRegistryEntry: TemplateRegistryEntry, associatedModuleId?: string, loadContext?: string[]): Promise<ResourceRegistry>;
importViewModelResource(moduleImport: string, moduleMember: string): Promise<ResourceDescription>;
Expand Down
23 changes: 20 additions & 3 deletions dist/commonjs/aurelia-templating.js
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,8 @@ exports.BoundViewFactory = BoundViewFactory;

var defaultFactoryOptions = {
systemControlled: false,
suppressBind: false
suppressBind: false,
enhance: false
};

var ViewFactory = (function () {
Expand All @@ -1374,7 +1375,7 @@ var ViewFactory = (function () {
var options = arguments[2] === undefined ? defaultFactoryOptions : arguments[2];
var element = arguments[3] === undefined ? null : arguments[3];

var fragment = this.template.cloneNode(true),
var fragment = options.enhance ? this.template : this.template.cloneNode(true),
instructables = fragment.querySelectorAll('.au-target'),
instructions = this.instructions,
resources = this.resources,
Expand Down Expand Up @@ -1899,6 +1900,21 @@ var ViewEngine = (function () {
return [_aureliaLoader.Loader, _aureliaDependencyInjection.Container, ViewCompiler, ModuleAnalyzer, ResourceRegistry];
};

ViewEngine.prototype.enhance = function enhance(container, element, resources, bindingContext) {
var instructions = {};

this.viewCompiler.compileNode(element, resources, instructions, element.parentNode, 'root', true);

var factory = new ViewFactory(element, instructions, resources);
var options = {
systemControlled: false,
suppressBind: false,
enhance: true
};

return factory.create(container, bindingContext, options);
};

ViewEngine.prototype.loadViewFactory = function loadViewFactory(urlOrRegistryEntry, compileOptions, associatedModuleId, loadContext) {
var _this5 = this;

Expand Down Expand Up @@ -2421,7 +2437,7 @@ var BehaviorPropertyObserver = (function () {
})();

var defaultInstruction = { suppressBind: false },
contentSelectorFactoryOptions = { suppressBind: true },
contentSelectorFactoryOptions = { suppressBind: true, enhance: false },
hasShadowDOM = !!HTMLElement.prototype.createShadowRoot;

function doProcessContent() {
Expand Down Expand Up @@ -2673,6 +2689,7 @@ var HtmlBehaviorResource = (function () {
element.primaryBehavior = behaviorInstance;
} else if (this.elementName !== null) {
viewFactory = instruction.viewFactory || this.viewFactory;
container.viewModel = executionContext;

if (viewFactory) {
behaviorInstance.view = viewFactory.create(container, executionContext, instruction, element);
Expand Down
1 change: 1 addition & 0 deletions dist/es6/aurelia-templating.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ declare module 'aurelia-templating' {
export class ViewEngine {
static inject(): any;
constructor(loader: Loader, container: Container, viewCompiler: ViewCompiler, moduleAnalyzer: ModuleAnalyzer, appResources: ResourceRegistry);
enhance(container: any, element: any, resources: any, bindingContext: any): any;
loadViewFactory(urlOrRegistryEntry: string | TemplateRegistryEntry, compileOptions?: Object, associatedModuleId?: string, loadContext?: string[]): Promise<ViewFactory>;
loadTemplateResources(viewRegistryEntry: TemplateRegistryEntry, associatedModuleId?: string, loadContext?: string[]): Promise<ResourceRegistry>;
importViewModelResource(moduleImport: string, moduleMember: string): Promise<ResourceDescription>;
Expand Down
23 changes: 20 additions & 3 deletions dist/es6/aurelia-templating.js
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,8 @@ export class BoundViewFactory {

var defaultFactoryOptions = {
systemControlled:false,
suppressBind:false
suppressBind:false,
enhance:false
};

export class ViewFactory{
Expand All @@ -1249,7 +1250,7 @@ export class ViewFactory{
}

create(container, executionContext, options=defaultFactoryOptions, element=null){
var fragment = this.template.cloneNode(true),
var fragment = options.enhance ? this.template : this.template.cloneNode(true),
instructables = fragment.querySelectorAll('.au-target'),
instructions = this.instructions,
resources = this.resources,
Expand Down Expand Up @@ -1720,6 +1721,21 @@ export class ViewEngine {
this.appResources = appResources;
}

enhance(container, element, resources, bindingContext){
let instructions = {};

this.viewCompiler.compileNode(element, resources, instructions, element.parentNode, 'root', true);

let factory = new ViewFactory(element, instructions, resources);
let options = {
systemControlled:false,
suppressBind:false,
enhance:true
};

return factory.create(container, bindingContext, options);
}

loadViewFactory(urlOrRegistryEntry:string|TemplateRegistryEntry, compileOptions?:Object, associatedModuleId?:string, loadContext?:string[]):Promise<ViewFactory>{
loadContext = loadContext || [];

Expand Down Expand Up @@ -2195,7 +2211,7 @@ class BehaviorPropertyObserver {
}

var defaultInstruction = { suppressBind:false },
contentSelectorFactoryOptions = { suppressBind:true },
contentSelectorFactoryOptions = { suppressBind:true, enhance:false },
hasShadowDOM = !!HTMLElement.prototype.createShadowRoot;

function doProcessContent(){
Expand Down Expand Up @@ -2439,6 +2455,7 @@ export class HtmlBehaviorResource {
} else if(this.elementName !== null){
//custom element
viewFactory = instruction.viewFactory || this.viewFactory;
container.viewModel = executionContext;

if(viewFactory){
behaviorInstance.view = viewFactory.create(container, executionContext, instruction, element);
Expand Down
1 change: 1 addition & 0 deletions dist/system/aurelia-templating.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ declare module 'aurelia-templating' {
export class ViewEngine {
static inject(): any;
constructor(loader: Loader, container: Container, viewCompiler: ViewCompiler, moduleAnalyzer: ModuleAnalyzer, appResources: ResourceRegistry);
enhance(container: any, element: any, resources: any, bindingContext: any): any;
loadViewFactory(urlOrRegistryEntry: string | TemplateRegistryEntry, compileOptions?: Object, associatedModuleId?: string, loadContext?: string[]): Promise<ViewFactory>;
loadTemplateResources(viewRegistryEntry: TemplateRegistryEntry, associatedModuleId?: string, loadContext?: string[]): Promise<ResourceRegistry>;
importViewModelResource(moduleImport: string, moduleMember: string): Promise<ResourceDescription>;
Expand Down
23 changes: 20 additions & 3 deletions dist/system/aurelia-templating.js
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,8 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-loader'

defaultFactoryOptions = {
systemControlled: false,
suppressBind: false
suppressBind: false,
enhance: false
};

ViewFactory = (function () {
Expand All @@ -1631,7 +1632,7 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-loader'
var options = arguments[2] === undefined ? defaultFactoryOptions : arguments[2];
var element = arguments[3] === undefined ? null : arguments[3];

var fragment = this.template.cloneNode(true),
var fragment = options.enhance ? this.template : this.template.cloneNode(true),
instructables = fragment.querySelectorAll('.au-target'),
instructions = this.instructions,
resources = this.resources,
Expand Down Expand Up @@ -2101,6 +2102,21 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-loader'
return [Loader, Container, ViewCompiler, ModuleAnalyzer, ResourceRegistry];
};

ViewEngine.prototype.enhance = function enhance(container, element, resources, bindingContext) {
var instructions = {};

this.viewCompiler.compileNode(element, resources, instructions, element.parentNode, 'root', true);

var factory = new ViewFactory(element, instructions, resources);
var options = {
systemControlled: false,
suppressBind: false,
enhance: true
};

return factory.create(container, bindingContext, options);
};

ViewEngine.prototype.loadViewFactory = function loadViewFactory(urlOrRegistryEntry, compileOptions, associatedModuleId, loadContext) {
var _this5 = this;

Expand Down Expand Up @@ -2612,7 +2628,7 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-loader'
})();

defaultInstruction = { suppressBind: false };
contentSelectorFactoryOptions = { suppressBind: true };
contentSelectorFactoryOptions = { suppressBind: true, enhance: false };
hasShadowDOM = !!HTMLElement.prototype.createShadowRoot;

HtmlBehaviorResource = (function () {
Expand Down Expand Up @@ -2860,6 +2876,7 @@ System.register(['core-js', 'aurelia-metadata', 'aurelia-path', 'aurelia-loader'
element.primaryBehavior = behaviorInstance;
} else if (this.elementName !== null) {
viewFactory = instruction.viewFactory || this.viewFactory;
container.viewModel = executionContext;

if (viewFactory) {
behaviorInstance.view = viewFactory.create(container, executionContext, instruction, element);
Expand Down
3 changes: 2 additions & 1 deletion src/html-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {ResourceRegistry} from './resource-registry';
import {DOMBoundary} from './dom';

var defaultInstruction = { suppressBind:false },
contentSelectorFactoryOptions = { suppressBind:true },
contentSelectorFactoryOptions = { suppressBind:true, enhance:false },
hasShadowDOM = !!HTMLElement.prototype.createShadowRoot;

function doProcessContent(){
Expand Down Expand Up @@ -257,6 +257,7 @@ export class HtmlBehaviorResource {
} else if(this.elementName !== null){
//custom element
viewFactory = instruction.viewFactory || this.viewFactory;
container.viewModel = executionContext;

if(viewFactory){
behaviorInstance.view = viewFactory.create(container, executionContext, instruction, element);
Expand Down
15 changes: 15 additions & 0 deletions src/view-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ export class ViewEngine {
this.appResources = appResources;
}

enhance(container, element, resources, bindingContext){
let instructions = {};

this.viewCompiler.compileNode(element, resources, instructions, element.parentNode, 'root', true);

let factory = new ViewFactory(element, instructions, resources);
let options = {
systemControlled:false,
suppressBind:false,
enhance:true
};

return factory.create(container, bindingContext, options);
}

loadViewFactory(urlOrRegistryEntry:string|TemplateRegistryEntry, compileOptions?:Object, associatedModuleId?:string, loadContext?:string[]):Promise<ViewFactory>{
loadContext = loadContext || [];

Expand Down
5 changes: 3 additions & 2 deletions src/view-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ export class BoundViewFactory {

var defaultFactoryOptions = {
systemControlled:false,
suppressBind:false
suppressBind:false,
enhance:false
};

export class ViewFactory{
Expand All @@ -246,7 +247,7 @@ export class ViewFactory{
}

create(container, executionContext, options=defaultFactoryOptions, element=null){
var fragment = this.template.cloneNode(true),
var fragment = options.enhance ? this.template : this.template.cloneNode(true),
instructables = fragment.querySelectorAll('.au-target'),
instructions = this.instructions,
resources = this.resources,
Expand Down

0 comments on commit e807868

Please sign in to comment.