本文整理汇总了TypeScript中aurelia-binding.createOverrideContext函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createOverrideContext函数的具体用法?TypeScript createOverrideContext怎么用?TypeScript createOverrideContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createOverrideContext函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should correctly handle multiple splices adding and removing (i.e Array.prototype.reverse())', () => {
let view4 = new ViewMock();
view4.overrideContext = { item: 'norf' };
let viewSlotMock = new ViewSlotMock();
viewSlotMock.children = [view1, view2, view3, view4];
repeat = new Repeat(new ViewFactoryMock(), instructionMock, viewSlotMock, viewResourcesMock, new ObserverLocator(), {});
let bindingContext = {};
repeat.scope = { bindingContext, overrideContext: createOverrideContext(bindingContext) };
splices = [{
addedCount: 2,
index: 0,
removed: ['foo']
}, {
addedCount: 1,
index: 3,
removed: ['bar', 'norf']
}];
items = ['norf', 'bar', 'qux', 'foo'];
strategy.instanceMutated(repeat, items, splices);
expect(viewSlotMock.children.length).toBe(4);
expect(viewSlotMock.children[0].bindingContext.item).toBe('norf');
expect(viewSlotMock.children[1].bindingContext.item).toBe('bar');
expect(viewSlotMock.children[2].bindingContext.item).toBe('qux');
expect(viewSlotMock.children[3].bindingContext.item).toBe('foo');
expect(viewSlotMock.children[0].overrideContext.$index).toBe(0);
expect(viewSlotMock.children[1].overrideContext.$index).toBe(1);
expect(viewSlotMock.children[2].overrideContext.$index).toBe(2);
expect(viewSlotMock.children[3].overrideContext.$index).toBe(3);
});
示例2: it
it('should correctly delete and add items in the same mutation (issue 284)', () => {
let view4 = new ViewMock();
view4.bindingContext = { item: 'norf' };
view4.overrideContext = {};
let viewSlotMock = new ViewSlotMock();
viewSlotMock.children = [view1, view2, view3, view4];
repeat = new Repeat(new ViewFactoryMock(), instructionMock, viewSlotMock, viewResourcesMock, new ObserverLocator());
let bindingContext = {};
repeat.scope = { bindingContext, overrideContext: createOverrideContext(bindingContext) };
records = [{
type: 'delete',
value: 'foo'
}, {
type: 'delete',
value: 'qux'
}, {
type: 'delete',
value: 'bar'
}, {
type: 'delete',
value: 'norf'
}, {
type: 'add',
value: 'baz'
}, {
type: 'delete',
value: 'baz'
}];
items = new Set();
strategy.instanceMutated(repeat, items, records);
expect(viewSlotMock.children.length).toBe(0);
});
示例3: it
it('should correctly handle adding items after clear (issue 287)', () => {
viewSlot.children = [view1, view2, view3];
repeat = new Repeat(new ViewFactoryMock(), instructionMock, viewSlot, viewResourcesMock, new ObserverLocator());
let bindingContext = {};
repeat.scope = { bindingContext, overrideContext: createOverrideContext(bindingContext) };
records = [
{"type": "clear", "object": {}},
{"type": "add", "object": {}, "key": 'foo'},
{"type": "add", "object": {}, "key": 'qux'},
{"type": "add", "object": {}, "key": 'john'},
{"type": "add", "object": {}, "key": 'norf'}
]
items = new Map([['foo', 'bar'], ['qux', 'qax'], ['john', 'doe'], ['norf', 'narf']]);
strategy.instanceMutated(repeat, items, records);
expect(viewSlot.children.length).toBe(4);
expect(viewSlot.children[0].bindingContext.key).toBe('foo');
expect(viewSlot.children[0].overrideContext.$index).toBe(0);
expect(viewSlot.children[0].overrideContext.$first).toBe(true);
expect(viewSlot.children[0].overrideContext.$last).toBe(false);
expect(viewSlot.children[3].bindingContext.key).toBe('norf');
expect(viewSlot.children[3].overrideContext.$index).toBe(3);
expect(viewSlot.children[3].overrideContext.$first).toBe(false);
expect(viewSlot.children[3].overrideContext.$last).toBe(true);
});
示例4: valueChanged
/**
* Invoked everytime the bound value changes.
* @param newValue The new value.
*/
valueChanged(newValue) {
let overrideContext = createOverrideContext(newValue, this.parentOverrideContext);
let view = this.view;
if (!view) {
view = this.view = this.viewFactory.create();
view.bind(newValue, overrideContext);
this.viewSlot.add(view);
} else {
view.bind(newValue, overrideContext);
}
}
示例5: createFullOverrideContext
export function createFullOverrideContext(repeat, data, index, length, key?: string) {
let bindingContext = {};
let overrideContext = createOverrideContext(bindingContext, repeat.scope.overrideContext);
// is key/value pair (Map)
if (typeof key !== 'undefined') {
bindingContext[repeat.key] = key;
bindingContext[repeat.value] = data;
} else {
bindingContext[repeat.local] = data;
}
updateOverrideContext(overrideContext, index, length);
return overrideContext;
}