本文整理匯總了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;
}