diff --git a/src/behavior-instance.js b/src/behavior-instance.js index caa9c1a1..ed3d537d 100644 --- a/src/behavior-instance.js +++ b/src/behavior-instance.js @@ -1,9 +1,9 @@ export class BehaviorInstance { - constructor(behavior, executionContext, instruction){ - this.behavior = behavior; - this.executionContext = executionContext; + constructor(behavior, executionContext, instruction){ + this.behavior = behavior; + this.executionContext = executionContext; - var observerLookup = behavior.observerLocator.getObserversLookup(executionContext), + var observerLookup = behavior.observerLocator.getObserversLookup(executionContext), handlesBind = behavior.handlesBind, attributes = instruction.attributes, boundProperties = this.boundProperties = [], @@ -13,7 +13,7 @@ export class BehaviorInstance { for(i = 0, ii = properties.length; i < ii; ++i){ properties[i].initialize(executionContext, observerLookup, attributes, handlesBind, boundProperties); } - } + } created(context){ if(this.behavior.handlesCreated){ @@ -21,8 +21,8 @@ export class BehaviorInstance { } } - bind(context){ - var skipSelfSubscriber = this.behavior.handlesBind, + bind(context){ + var skipSelfSubscriber = this.behavior.handlesBind, boundProperties = this.boundProperties, i, ii, x, observer, selfSubscriber; @@ -50,9 +50,9 @@ export class BehaviorInstance { if(this.view){ this.view.bind(this.executionContext); } - } + } - unbind(){ + unbind(){ var boundProperties = this.boundProperties, i, ii; @@ -67,7 +67,7 @@ export class BehaviorInstance { for(i = 0, ii = boundProperties.length; i < ii; ++i){ boundProperties[i].binding.unbind(); } - } + } attached(){ if(this.behavior.handlesAttached){ diff --git a/src/children.js b/src/children.js index 75deff78..3b5d433b 100644 --- a/src/children.js +++ b/src/children.js @@ -1,7 +1,7 @@ var noMutations = []; export class ChildObserver { - constructor(property, changeHandler, selector){ + constructor(property, changeHandler, selector){ this.selector = selector; this.changeHandler = changeHandler; this.property = property; @@ -13,86 +13,86 @@ export class ChildObserver { } export class ChildObserverBinder { - constructor(selector, target, property, behavior, changeHandler){ - this.selector = selector; - this.target = target; - this.property = property; - this.target = target; + constructor(selector, target, property, behavior, changeHandler){ + this.selector = selector; + this.target = target; + this.property = property; + this.target = target; this.behavior = behavior; this.changeHandler = changeHandler; - this.observer = new MutationObserver(this.onChange.bind(this)); - } + this.observer = new MutationObserver(this.onChange.bind(this)); + } - bind(source){ + bind(source){ var items, results, i, ii, node, behavior = this.behavior; - this.observer.observe(this.target, {childList:true, subtree: true}); + this.observer.observe(this.target, {childList:true, subtree: true}); - items = behavior[this.property]; - if(!items){ - items = behavior[this.property] = []; - }else{ - items.length = 0; - } + items = behavior[this.property]; + if(!items){ + items = behavior[this.property] = []; + }else{ + items.length = 0; + } - results = this.target.querySelectorAll(this.selector); + results = this.target.querySelectorAll(this.selector); - for(i = 0, ii = results.length; i < ii; ++i){ - node = results[i]; - items.push(node.primaryBehavior ? node.primaryBehavior.executionContext : node); - } + for(i = 0, ii = results.length; i < ii; ++i){ + node = results[i]; + items.push(node.primaryBehavior ? node.primaryBehavior.executionContext : node); + } if(this.changeHandler){ this.behavior[this.changeHandler](noMutations); } - } + } - unbind(){ - this.observer.disconnect(); - } + unbind(){ + this.observer.disconnect(); + } - onChange(mutations){ - var items = this.behavior[this.property], - selector = this.selector; + onChange(mutations){ + var items = this.behavior[this.property], + selector = this.selector; - mutations.forEach(record => { - var added = record.addedNodes, - removed = record.removedNodes, - prev = record.previousSibling, + mutations.forEach(record => { + var added = record.addedNodes, + removed = record.removedNodes, + prev = record.previousSibling, i, ii, primary, index, node; - for(i = 0, ii = removed.length; i < ii; ++i){ - node = removed[i]; - if(node.nodeType === 1 && node.matches(selector)){ - primary = node.primaryBehavior ? node.primaryBehavior.executionContext : node; - index = items.indexOf(primary); - if(index != -1){ - items.splice(index, 1); - } - } - } - - for(i = 0, ii = added.length; i < ii; ++i){ - node = added[i]; - if(node.nodeType === 1 && node.matches(selector)){ - primary = node.primaryBehavior ? node.primaryBehavior.executionContext : node; - index = 0; - - while(prev){ - if(prev.nodeType === 1 && prev.matches(selector)){ - index++; - } - - prev = prev.previousSibling; - } - - items.splice(index, 0, primary); - } - } - }); + for(i = 0, ii = removed.length; i < ii; ++i){ + node = removed[i]; + if(node.nodeType === 1 && node.matches(selector)){ + primary = node.primaryBehavior ? node.primaryBehavior.executionContext : node; + index = items.indexOf(primary); + if(index != -1){ + items.splice(index, 1); + } + } + } + + for(i = 0, ii = added.length; i < ii; ++i){ + node = added[i]; + if(node.nodeType === 1 && node.matches(selector)){ + primary = node.primaryBehavior ? node.primaryBehavior.executionContext : node; + index = 0; + + while(prev){ + if(prev.nodeType === 1 && prev.matches(selector)){ + index++; + } + + prev = prev.previousSibling; + } + + items.splice(index, 0, primary); + } + } + }); if(this.changeHandler){ this.behavior[this.changeHandler](mutations); } - } + } } \ No newline at end of file diff --git a/src/content-selector.js b/src/content-selector.js index 9b306bb6..de0a5004 100644 --- a/src/content-selector.js +++ b/src/content-selector.js @@ -8,27 +8,27 @@ if (Element && !Element.prototype.matches) { var placeholder = []; function findInsertionPoint(groups, index){ - var insertionPoint; + var insertionPoint; - while(!insertionPoint && index >= 0){ - insertionPoint = groups[index][0]; - index--; - } + while(!insertionPoint && index >= 0){ + insertionPoint = groups[index][0]; + index--; + } - return insertionPoint || anchor; + return insertionPoint || anchor; } export class ContentSelector { - static applySelectors(view, contentSelectors, callback){ - var currentChild = view.fragment.firstChild, - contentMap = new Map(), - nextSibling, i, ii, contentSelector; + static applySelectors(view, contentSelectors, callback){ + var currentChild = view.fragment.firstChild, + contentMap = new Map(), + nextSibling, i, ii, contentSelector; - while (currentChild) { + while (currentChild) { nextSibling = currentChild.nextSibling; if(currentChild.viewSlot){ - var viewSlotSelectors = contentSelectors.map(x => x.copyForViewSlot()); + var viewSlotSelectors = contentSelectors.map(x => x.copyForViewSlot()); currentChild.viewSlot.installContentSelectors(viewSlotSelectors); }else{ for(i = 0, ii = contentSelectors.length; i < ii; i++){ @@ -50,61 +50,61 @@ export class ContentSelector { } for(i = 0, ii = contentSelectors.length; i < ii; ++i){ - contentSelector = contentSelectors[i]; - callback(contentSelector, contentMap.get(contentSelector) || placeholder); + contentSelector = contentSelectors[i]; + callback(contentSelector, contentMap.get(contentSelector) || placeholder); } - } - - constructor(anchor, selector){ - this.anchor = anchor; - this.selector = selector; - this.all = !this.selector; - this.groups = []; - } - - copyForViewSlot(){ - return new ContentSelector(this.anchor, this.selector); - } - - matches(node){ - return this.all || - (node.nodeType === 1 && node.matches(this.selector)); - } - - add(group){ - var anchor = this.anchor, - parent = anchor.parentNode, + } + + constructor(anchor, selector){ + this.anchor = anchor; + this.selector = selector; + this.all = !this.selector; + this.groups = []; + } + + copyForViewSlot(){ + return new ContentSelector(this.anchor, this.selector); + } + + matches(node){ + return this.all || + (node.nodeType === 1 && node.matches(this.selector)); + } + + add(group){ + var anchor = this.anchor, + parent = anchor.parentNode, i, ii; - for(i = 0, ii = group.length; i < ii; ++i){ - parent.insertBefore(group[i], anchor); - } + for(i = 0, ii = group.length; i < ii; ++i){ + parent.insertBefore(group[i], anchor); + } - this.groups.push(group); - } + this.groups.push(group); + } - insert(index, group){ - if(group.length){ - var anchor = findInsertionPoint(this.groups, index) || this.anchor, - parent = anchor.parentNode, + insert(index, group){ + if(group.length){ + var anchor = findInsertionPoint(this.groups, index) || this.anchor, + parent = anchor.parentNode, i, ii; - for(i = 0, ii = group.length; i < ii; ++i){ - parent.insertBefore(group[i], anchor); - } - } + for(i = 0, ii = group.length; i < ii; ++i){ + parent.insertBefore(group[i], anchor); + } + } - this.groups.splice(index, 0, group); - } + this.groups.splice(index, 0, group); + } - removeAt(index, fragment){ - var group = this.groups[index], + removeAt(index, fragment){ + var group = this.groups[index], i, ii; - for(i = 0, ii = group.length; i < ii; ++i){ - fragment.appendChild(group[i]); - } + for(i = 0, ii = group.length; i < ii; ++i){ + fragment.appendChild(group[i]); + } - this.groups.splice(index, 1); - } + this.groups.splice(index, 1); + } } \ No newline at end of file diff --git a/src/resource-registry.js b/src/resource-registry.js index 42160209..5120463f 100644 --- a/src/resource-registry.js +++ b/src/resource-registry.js @@ -18,15 +18,15 @@ function register(lookup, name, resource, type){ } export class ResourceRegistry { - constructor(){ - this.attributes = {}; + constructor(){ + this.attributes = {}; this.elements = {}; this.valueConverters = {}; this.attributeMap = {}; this.baseResourceUrl = ''; - } + } - registerElement(tagName, behavior){ + registerElement(tagName, behavior){ register(this.elements, tagName, behavior, 'an Element'); } @@ -44,7 +44,7 @@ export class ResourceRegistry { } registerValueConverter(name, valueConverter){ - register(this.valueConverters, name, valueConverter, 'a ValueConverter'); + register(this.valueConverters, name, valueConverter, 'a ValueConverter'); } getValueConverter(name){ @@ -53,12 +53,12 @@ export class ResourceRegistry { } export class ViewResources extends ResourceRegistry { - constructor(parent, viewUrl){ - super(); - this.parent = parent; + constructor(parent, viewUrl){ + super(); + this.parent = parent; this.viewUrl = viewUrl; this.valueConverterLookupFunction = this.getValueConverter.bind(this); - } + } relativeToView(path){ return relativeToFile(path, this.viewUrl); diff --git a/src/view-engine.js b/src/view-engine.js index 412f80fe..85b81a72 100644 --- a/src/view-engine.js +++ b/src/view-engine.js @@ -10,15 +10,15 @@ var logger = LogManager.getLogger('templating'); export class ViewEngine { static inject() { return [Loader, Container, ViewCompiler, ModuleAnalyzer, ResourceRegistry]; } - constructor(loader, container, viewCompiler, moduleAnalyzer, appResources){ - this.loader = loader; + constructor(loader, container, viewCompiler, moduleAnalyzer, appResources){ + this.loader = loader; this.container = container; - this.viewCompiler = viewCompiler; + this.viewCompiler = viewCompiler; this.moduleAnalyzer = moduleAnalyzer; this.appResources = appResources; - } + } - loadViewFactory(url, compileOptions, associatedModuleId){ + loadViewFactory(url, compileOptions, associatedModuleId){ return this.loader.loadTemplate(url).then(viewRegistryEntry => { if(viewRegistryEntry.isReady){ return viewRegistryEntry.factory; diff --git a/src/view-strategy.js b/src/view-strategy.js index a9afc121..660d5b78 100644 --- a/src/view-strategy.js +++ b/src/view-strategy.js @@ -45,17 +45,17 @@ export class ViewStrategy { } export class UseView extends ViewStrategy { - constructor(path){ - this.path = path; - } + constructor(path){ + this.path = path; + } - loadViewFactory(viewEngine, options){ + loadViewFactory(viewEngine, options){ 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); + } makeRelativeTo(file){ this.absolutePath = relativeToFile(this.path, file); @@ -63,14 +63,14 @@ export class UseView extends ViewStrategy { } export class ConventionalView extends ViewStrategy { - constructor(moduleId){ - this.moduleId = moduleId; + constructor(moduleId){ + this.moduleId = moduleId; this.viewUrl = ConventionalView.convertModuleIdToViewUrl(moduleId); - } + } - loadViewFactory(viewEngine, options){ - return viewEngine.loadViewFactory(this.viewUrl, options, this.moduleId); - } + loadViewFactory(viewEngine, options){ + return viewEngine.loadViewFactory(this.viewUrl, options, this.moduleId); + } static convertModuleIdToViewUrl(moduleId){ return moduleId + '.html'; @@ -78,7 +78,7 @@ export class ConventionalView extends ViewStrategy { } export class NoView extends ViewStrategy { - loadViewFactory(){ - return Promise.resolve(null); - } + loadViewFactory(){ + return Promise.resolve(null); + } } \ No newline at end of file