Skip to content

Commit 3cc6d3c

Browse files
chore(all): prepare release 1.0.0-beta.1.1.0
1 parent bdff323 commit 3cc6d3c

14 files changed

+216
-85
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aurelia-templating",
3-
"version": "1.0.0-beta.1.0.3",
3+
"version": "1.0.0-beta.1.1.0",
44
"description": "An extensible HTML templating engine supporting databinding, custom elements, attached behaviors and more.",
55
"keywords": [
66
"aurelia",

dist/amd/aurelia-templating.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ declare module 'aurelia-templating' {
880880
*/
881881
constructor(parentContainer: Container, viewFactory: ViewFactory, partReplacements?: Object);
882882

883+
// This is referenced internally in the controller's bind method.
883884
/**
884885
* Creates a view or returns one from the internal cache, if available.
885886
* @return The created view.
@@ -1363,12 +1364,12 @@ declare module 'aurelia-templating' {
13631364
}
13641365

13651366
/**
1366-
* Creates a behavior property that references an array of immediate content child elememnts that matches the provided selector.
1367+
* Creates a behavior property that references an array of immediate content child elements that matches the provided selector.
13671368
*/
13681369
export function children(selectorOrConfig: string | Object): any;
13691370

13701371
/**
1371-
* Creates a behavior property that references an immediate content child elememnt that matches the provided selector.
1372+
* Creates a behavior property that references an immediate content child element that matches the provided selector.
13721373
*/
13731374
export function child(selectorOrConfig: string | Object): any;
13741375
class ChildObserver {

dist/amd/aurelia-templating.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-pa
187187
instruction.host = host;
188188
instruction.viewModel = viewModel;
189189
instruction.viewFactory = viewFactory;
190+
instruction.inheritBindingContext = true;
190191
return instruction;
191192
};
192193

@@ -212,6 +213,7 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-pa
212213
this.attributes = null;
213214
this.type = null;
214215
this.attrName = null;
216+
this.inheritBindingContext = false;
215217
}
216218

217219
return BehaviorInstruction;
@@ -2674,7 +2676,7 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-pa
26742676
this.isAttached = false;
26752677
this.view = null;
26762678
this.isBound = false;
2677-
this.bindingContext = null;
2679+
this.scope = null;
26782680

26792681
var observerLookup = behavior.observerLocator.getOrCreateObserversLookup(viewModel);
26802682
var handlesBind = behavior.handlesBind;
@@ -2717,18 +2719,17 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-pa
27172719
var x = undefined;
27182720
var observer = undefined;
27192721
var selfSubscriber = undefined;
2720-
var context = scope.bindingContext;
27212722

27222723
if (this.isBound) {
2723-
if (this.bindingContext === context) {
2724+
if (this.scope === scope) {
27242725
return;
27252726
}
27262727

27272728
this.unbind();
27282729
}
27292730

27302731
this.isBound = true;
2731-
this.bindingContext = context;
2732+
this.scope = scope;
27322733

27332734
for (i = 0, ii = boundProperties.length; i < ii; ++i) {
27342735
x = boundProperties[i];
@@ -2747,14 +2748,29 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-pa
27472748
observer.selfSubscriber = selfSubscriber;
27482749
}
27492750

2751+
var overrideContext = undefined;
27502752
if (this.view !== null) {
27512753
if (skipSelfSubscriber) {
27522754
this.view.viewModelScope = scope;
27532755
}
27542756

2755-
this.view.bind(this.viewModel, _aureliaBinding.createOverrideContext(this.viewModel, scope.overrideContext));
2757+
if (this.viewModel === scope.overrideContext.bindingContext) {
2758+
overrideContext = scope.overrideContext;
2759+
} else if (this.instruction.inheritBindingContext) {
2760+
overrideContext = _aureliaBinding.createOverrideContext(this.viewModel, scope.overrideContext);
2761+
} else {
2762+
overrideContext = _aureliaBinding.createOverrideContext(this.viewModel);
2763+
overrideContext.__parentOverrideContext = scope.overrideContext;
2764+
}
2765+
this.view.bind(this.viewModel, overrideContext);
27562766
} else if (skipSelfSubscriber) {
2757-
this.viewModel.bind(context, scope.overrideContext);
2767+
overrideContext = scope.overrideContext;
2768+
2769+
if (scope.overrideContext.__parentOverrideContext !== undefined && this.viewModel.viewFactory && this.viewModel.viewFactory.factoryCreateInstruction.partReplacements) {
2770+
overrideContext = Object.assign({}, scope.overrideContext);
2771+
overrideContext.parentOverrideContext = scope.overrideContext.__parentOverrideContext;
2772+
}
2773+
this.viewModel.bind(scope.bindingContext, overrideContext);
27582774
}
27592775
};
27602776

@@ -3279,7 +3295,7 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-pa
32793295
node = template;
32803296
}
32813297
} else if (this.elementName !== null) {
3282-
var _partReplacements2 = instruction.partReplacements = {};
3298+
var _partReplacements2 = {};
32833299

32843300
if (this.processContent(compiler, resources, node, instruction) && node.hasChildNodes()) {
32853301
if (this.usesShadowDOM) {
@@ -3293,6 +3309,7 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-pa
32933309
if (currentChild.tagName === 'TEMPLATE' && (toReplace = currentChild.getAttribute('replace-part'))) {
32943310
_partReplacements2[toReplace] = compiler.compile(currentChild, resources);
32953311
_aureliaPal.DOM.removeNode(currentChild, parentNode);
3312+
instruction.partReplacements = _partReplacements2;
32963313
}
32973314

32983315
currentChild = nextSibling;
@@ -3311,6 +3328,7 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-pa
33113328
if (currentChild.tagName === 'TEMPLATE' && (toReplace = currentChild.getAttribute('replace-part'))) {
33123329
_partReplacements2[toReplace] = compiler.compile(currentChild, resources);
33133330
_aureliaPal.DOM.removeNode(currentChild, parentNode);
3331+
instruction.partReplacements = _partReplacements2;
33143332
} else {
33153333
fragment.appendChild(currentChild);
33163334
}

dist/aurelia-templating.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ declare module 'aurelia-templating' {
880880
*/
881881
constructor(parentContainer: Container, viewFactory: ViewFactory, partReplacements?: Object);
882882

883+
// This is referenced internally in the controller's bind method.
883884
/**
884885
* Creates a view or returns one from the internal cache, if available.
885886
* @return The created view.
@@ -1363,12 +1364,12 @@ declare module 'aurelia-templating' {
13631364
}
13641365

13651366
/**
1366-
* Creates a behavior property that references an array of immediate content child elememnts that matches the provided selector.
1367+
* Creates a behavior property that references an array of immediate content child elements that matches the provided selector.
13671368
*/
13681369
export function children(selectorOrConfig: string | Object): any;
13691370

13701371
/**
1371-
* Creates a behavior property that references an immediate content child elememnt that matches the provided selector.
1372+
* Creates a behavior property that references an immediate content child element that matches the provided selector.
13721373
*/
13731374
export function child(selectorOrConfig: string | Object): any;
13741375
class ChildObserver {

dist/aurelia-templating.js

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ export class BehaviorInstruction {
266266
instruction.host = host;
267267
instruction.viewModel = viewModel;
268268
instruction.viewFactory = viewFactory;
269+
instruction.inheritBindingContext = true;
269270
return instruction;
270271
}
271272

@@ -286,6 +287,7 @@ export class BehaviorInstruction {
286287
this.attributes = null;
287288
this.type = null;
288289
this.attrName = null;
290+
this.inheritBindingContext = false;
289291
}
290292
}
291293

@@ -2086,7 +2088,7 @@ export class BoundViewFactory {
20862088
constructor(parentContainer: Container, viewFactory: ViewFactory, partReplacements?: Object) {
20872089
this.parentContainer = parentContainer;
20882090
this.viewFactory = viewFactory;
2089-
this.factoryCreateInstruction = { partReplacements: partReplacements };
2091+
this.factoryCreateInstruction = { partReplacements: partReplacements }; //This is referenced internally in the controller's bind method.
20902092
}
20912093

20922094
/**
@@ -3226,7 +3228,7 @@ export class Controller {
32263228
this.isAttached = false;
32273229
this.view = null;
32283230
this.isBound = false;
3229-
this.bindingContext = null;
3231+
this.scope = null;
32303232

32313233
let observerLookup = behavior.observerLocator.getOrCreateObserversLookup(viewModel);
32323234
let handlesBind = behavior.handlesBind;
@@ -3264,7 +3266,7 @@ export class Controller {
32643266
this.view.overrideContext = overrideContext || createOverrideContext(this.viewModel);
32653267
this.view._isUserControlled = true;
32663268

3267-
if(this.behavior.handlesCreated) {
3269+
if (this.behavior.handlesCreated) {
32683270
this.viewModel.created(owningView || null, this.view);
32693271
}
32703272

@@ -3283,18 +3285,17 @@ export class Controller {
32833285
let x;
32843286
let observer;
32853287
let selfSubscriber;
3286-
let context = scope.bindingContext;
32873288

32883289
if (this.isBound) {
3289-
if (this.bindingContext === context) {
3290+
if (this.scope === scope) {
32903291
return;
32913292
}
32923293

32933294
this.unbind();
32943295
}
32953296

32963297
this.isBound = true;
3297-
this.bindingContext = context;
3298+
this.scope = scope;
32983299

32993300
for (i = 0, ii = boundProperties.length; i < ii; ++i) {
33003301
x = boundProperties[i];
@@ -3313,14 +3314,40 @@ export class Controller {
33133314
observer.selfSubscriber = selfSubscriber;
33143315
}
33153316

3317+
let overrideContext;
33163318
if (this.view !== null) {
33173319
if (skipSelfSubscriber) {
33183320
this.view.viewModelScope = scope;
33193321
}
3320-
3321-
this.view.bind(this.viewModel, createOverrideContext(this.viewModel, scope.overrideContext));
3322+
// do we need to create an overrideContext or is the scope's overrideContext
3323+
// valid for this viewModel?
3324+
if (this.viewModel === scope.overrideContext.bindingContext) {
3325+
overrideContext = scope.overrideContext;
3326+
// should we inherit the parent scope? (eg compose / router)
3327+
} else if (this.instruction.inheritBindingContext) {
3328+
overrideContext = createOverrideContext(this.viewModel, scope.overrideContext);
3329+
// create the overrideContext and capture the parent without making it
3330+
// available to AccessScope. We may need it later for template-part replacements.
3331+
} else {
3332+
overrideContext = createOverrideContext(this.viewModel);
3333+
overrideContext.__parentOverrideContext = scope.overrideContext;
3334+
}
3335+
this.view.bind(this.viewModel, overrideContext);
33223336
} else if (skipSelfSubscriber) {
3323-
this.viewModel.bind(context, scope.overrideContext);
3337+
overrideContext = scope.overrideContext;
3338+
// the factoryCreateInstruction's partReplacements will either be null or an object
3339+
// containing the replacements. If there are partReplacements we need to preserve the parent
3340+
// context to allow replacement parts to bind to both the custom element scope and the ambient scope.
3341+
// Note that factoryCreateInstruction is a property defined on BoundViewFactory. The code below assumes the
3342+
// behavior stores a the BoundViewFactory on its viewModel under the name of viewFactory. This is implemented
3343+
// by the replaceable custom attribute.
3344+
if (scope.overrideContext.__parentOverrideContext !== undefined
3345+
&& this.viewModel.viewFactory && this.viewModel.viewFactory.factoryCreateInstruction.partReplacements) {
3346+
// clone the overrideContext and connect the ambient context.
3347+
overrideContext = Object.assign({}, scope.overrideContext);
3348+
overrideContext.parentOverrideContext = scope.overrideContext.__parentOverrideContext;
3349+
}
3350+
this.viewModel.bind(scope.bindingContext, overrideContext);
33243351
}
33253352
}
33263353

@@ -3932,7 +3959,7 @@ export class HtmlBehaviorResource {
39323959
node = template;
39333960
}
39343961
} else if (this.elementName !== null) { //custom element
3935-
let partReplacements = instruction.partReplacements = {};
3962+
let partReplacements = {};
39363963

39373964
if (this.processContent(compiler, resources, node, instruction) && node.hasChildNodes()) {
39383965
if (this.usesShadowDOM) {
@@ -3946,6 +3973,7 @@ export class HtmlBehaviorResource {
39463973
if (currentChild.tagName === 'TEMPLATE' && (toReplace = currentChild.getAttribute('replace-part'))) {
39473974
partReplacements[toReplace] = compiler.compile(currentChild, resources);
39483975
DOM.removeNode(currentChild, parentNode);
3976+
instruction.partReplacements = partReplacements;
39493977
}
39503978

39513979
currentChild = nextSibling;
@@ -3964,6 +3992,7 @@ export class HtmlBehaviorResource {
39643992
if (currentChild.tagName === 'TEMPLATE' && (toReplace = currentChild.getAttribute('replace-part'))) {
39653993
partReplacements[toReplace] = compiler.compile(currentChild, resources);
39663994
DOM.removeNode(currentChild, parentNode);
3995+
instruction.partReplacements = partReplacements;
39673996
} else {
39683997
fragment.appendChild(currentChild);
39693998
}
@@ -4144,14 +4173,14 @@ function createChildObserverDecorator(selectorOrConfig, all) {
41444173
}
41454174

41464175
/**
4147-
* Creates a behavior property that references an array of immediate content child elememnts that matches the provided selector.
4176+
* Creates a behavior property that references an array of immediate content child elements that matches the provided selector.
41484177
*/
41494178
export function children(selectorOrConfig: string | Object): any {
41504179
return createChildObserverDecorator(selectorOrConfig, true);
41514180
}
41524181

41534182
/**
4154-
* Creates a behavior property that references an immediate content child elememnt that matches the provided selector.
4183+
* Creates a behavior property that references an immediate content child element that matches the provided selector.
41554184
*/
41564185
export function child(selectorOrConfig: string | Object): any {
41574186
return createChildObserverDecorator(selectorOrConfig, false);

dist/commonjs/aurelia-templating.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ declare module 'aurelia-templating' {
880880
*/
881881
constructor(parentContainer: Container, viewFactory: ViewFactory, partReplacements?: Object);
882882

883+
// This is referenced internally in the controller's bind method.
883884
/**
884885
* Creates a view or returns one from the internal cache, if available.
885886
* @return The created view.
@@ -1363,12 +1364,12 @@ declare module 'aurelia-templating' {
13631364
}
13641365

13651366
/**
1366-
* Creates a behavior property that references an array of immediate content child elememnts that matches the provided selector.
1367+
* Creates a behavior property that references an array of immediate content child elements that matches the provided selector.
13671368
*/
13681369
export function children(selectorOrConfig: string | Object): any;
13691370

13701371
/**
1371-
* Creates a behavior property that references an immediate content child elememnt that matches the provided selector.
1372+
* Creates a behavior property that references an immediate content child element that matches the provided selector.
13721373
*/
13731374
export function child(selectorOrConfig: string | Object): any;
13741375
class ChildObserver {

0 commit comments

Comments
 (0)