Skip to content

Commit

Permalink
fix(templating-engine): allow for overrideContext in enhance
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenVinke committed Apr 20, 2016
1 parent 35885f7 commit 49c99ed
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/templating-engine.js
Expand Up @@ -30,6 +30,10 @@ interface EnhanceInstruction {
* A binding context for the enhancement.
*/
bindingContext?: Object;
/**
* A secondary binding context that can override the standard context.
*/
overrideContext?: any;
}

/**
Expand Down Expand Up @@ -91,7 +95,7 @@ export class TemplatingEngine {
let container = instruction.container || this._container.createChild();
let view = factory.create(container, BehaviorInstruction.enhance());

view.bind(instruction.bindingContext || {});
view.bind(instruction.bindingContext || {}, instruction.overrideContext);

return view;
}
Expand Down
47 changes: 47 additions & 0 deletions test/templating-engine.spec.js
@@ -0,0 +1,47 @@
import './setup';
import {Container} from 'aurelia-dependency-injection';
import {TemplatingEngine} from '../src/templating-engine';
import {ViewResources} from '../src/view-resources';
import {DOM} from 'aurelia-pal';

describe('enhance', () => {
let container;
let element;
let templatingEngine;

beforeEach(() => {
container = new Container();
element = DOM.createElement('div');
templatingEngine = container.get(TemplatingEngine);
});

it('passes bindingContext and overrideContext to .bind()', () => {
let bindingContext = { some: 'var' };
let overrideContext = { foo: 'bar' };

let view = templatingEngine.enhance({
element: element,
bindingContext: bindingContext,
overrideContext: overrideContext
});

expect(view.bindingContext).toBe(bindingContext);
expect(view.overrideContext).toBe(overrideContext);
expect(view.bindingContext.some).toBe('var');
expect(view.overrideContext.foo).toBe('bar');
});

it('supports passing of ViewResources to the view-compiler', () => {
let compileNodeSpy = spyOn(templatingEngine._viewCompiler, '_compileNode');
let resources = new ViewResources();

templatingEngine.enhance({
element: element,
resources: resources
});

let r = compileNodeSpy.calls.argsFor(0)[1];

expect(r).toBe(resources);
});
});

0 comments on commit 49c99ed

Please sign in to comment.