当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript aurelia-binding.createOverrideContext函数代码示例

本文整理汇总了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);
    });
开发者ID:aurelia,项目名称:templating-resources,代码行数:32,代码来源:array-repeat-strategy.spec.ts

示例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);
    });
开发者ID:aurelia,项目名称:templating-resources,代码行数:33,代码来源:set-repeat-strategy.spec.ts

示例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);
    });
开发者ID:aurelia,项目名称:templating-resources,代码行数:25,代码来源:map-repeat-strategy.spec.ts

示例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);
   }
 }
开发者ID:aurelia,项目名称:templating-resources,代码行数:15,代码来源:with.ts

示例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;
}
开发者ID:aurelia,项目名称:templating-resources,代码行数:13,代码来源:repeat-utilities.ts


注:本文中的aurelia-binding.createOverrideContext函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。