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


TypeScript Services.checkAndUpdateView方法代码示例

本文整理汇总了TypeScript中@angular/core/src/view/index.Services.checkAndUpdateView方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Services.checkAndUpdateView方法的具体用法?TypeScript Services.checkAndUpdateView怎么用?TypeScript Services.checkAndUpdateView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@angular/core/src/view/index.Services的用法示例。


在下文中一共展示了Services.checkAndUpdateView方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

        it(`should support ${ArgumentType[inlineDynamic]} bindings`, () => {
          let values: any[];

          const {view, rootNodes} = createAndGetRootNodes(compViewDef(
              [
                elementDef(NodeFlags.None, null, null, 2, 'span'), pureArrayDef(2),
                directiveDef(NodeFlags.None, null, 0, Service, [], {data: [0, 'data']})
              ],
              (check, view) => {
                const pureValue = checkNodeInlineOrDynamic(check, view, 1, inlineDynamic, values);
                checkNodeInlineOrDynamic(check, view, 2, inlineDynamic, [pureValue]);
              }));
          const service = asProviderData(view, 2).instance;

          values = [1, 2];
          Services.checkAndUpdateView(view);
          const arr0 = service.data;
          expect(arr0).toEqual([1, 2]);

          // instance should not change
          // if the values don't change
          Services.checkAndUpdateView(view);
          expect(service.data).toBe(arr0);

          values = [3, 2];
          Services.checkAndUpdateView(view);
          const arr1 = service.data;
          expect(arr1).not.toBe(arr0);
          expect(arr1).toEqual([3, 2]);
        });
开发者ID:rlugojr,项目名称:angular,代码行数:30,代码来源:pure_expression_spec.ts

示例2: it

      it('should support detaching and attaching component views for dirty checking', () => {
        class AComp {
          a: any;
        }

        const update = jasmine.createSpy('updater');

        const {view, rootNodes} = createAndGetRootNodes(compViewDef([
          elementDef(
              0, NodeFlags.None, null, null, 1, 'div', null, null, null, null,
              () => compViewDef(
                  [
                    elementDef(0, NodeFlags.None, null, null, 0, 'span'),
                  ],
                  update)),
          directiveDef(1, NodeFlags.Component, null, 0, AComp, [], null, null),
        ]));

        const compView = asElementData(view, 0).componentView;

        Services.checkAndUpdateView(view);
        update.calls.reset();

        compView.state &= ~ViewState.ChecksEnabled;
        Services.checkAndUpdateView(view);
        expect(update).not.toHaveBeenCalled();

        compView.state |= ViewState.ChecksEnabled;
        Services.checkAndUpdateView(view);
        expect(update).toHaveBeenCalled();
      });
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:31,代码来源:component_view_spec.ts

示例3: it

      it('should update view queries if embedded views are added or removed', () => {
        const {view} = createAndGetRootNodes(compViewDef([
          elementDef(NodeFlags.None, null, null, 1, 'div'),
          ...viewQueryProviders([
            anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0, embeddedViewDef([
                        elementDef(NodeFlags.None, null, null, 1, 'div'),
                        aServiceProvider(),
                      ])),
          ]),
        ]));

        Services.checkAndUpdateView(view);

        const comp: QueryService = asProviderData(view, 1).instance;
        expect(comp.a.length).toBe(0);

        const compView = asProviderData(view, 1).componentView;
        const childView = Services.createEmbeddedView(compView, compView.def.nodes[1]);
        attachEmbeddedView(asElementData(compView, 1), 0, childView);
        Services.checkAndUpdateView(view);

        expect(comp.a.length).toBe(1);

        detachEmbeddedView(asElementData(compView, 1), 0);
        Services.checkAndUpdateView(view);

        expect(comp.a.length).toBe(0);
      });
开发者ID:tolemac,项目名称:angular,代码行数:28,代码来源:query_spec.ts

示例4: it

        it(`should update via strategy ${inlineDynamic}`, () => {
          let values: any[];

          const {view, rootNodes} = createAndGetRootNodes(compViewDef(
              [
                elementDef(NodeFlags.None, null, null, 2, 'span'), pureObjectDef(['a', 'b']),
                directiveDef(NodeFlags.None, null, 0, Service, [], {data: [0, 'data']})
              ],
              (check, view) => {
                const pureValue = checkNodeInlineOrDynamic(check, view, 1, inlineDynamic, values);
                checkNodeInlineOrDynamic(check, view, 2, inlineDynamic, [pureValue]);
              }));
          const service = asProviderData(view, 2).instance;

          values = [1, 2];
          Services.checkAndUpdateView(view);
          const obj0 = service.data;
          expect(obj0).toEqual({a: 1, b: 2});

          // instance should not change
          // if the values don't change
          Services.checkAndUpdateView(view);
          expect(service.data).toBe(obj0);

          values = [3, 2];
          Services.checkAndUpdateView(view);
          const obj1 = service.data;
          expect(obj1).not.toBe(obj0);
          expect(obj1).toEqual({a: 3, b: 2});
        });
开发者ID:JohnnyQQQQ,项目名称:angular,代码行数:30,代码来源:pure_expression_spec.ts

示例5: it

      it('should update content queries if embedded views are added or removed', () => {
        const {view} = createAndGetRootNodes(compViewDef([
          elementDef(0, NodeFlags.None, null, null, 3, 'div'),
          ...contentQueryProviders(1),
          anchorDef(NodeFlags.EmbeddedViews, null, null, 0, null, compViewDefFactory([
                      elementDef(0, NodeFlags.None, null, null, 1, 'div'),
                      aServiceProvider(1),
                    ])),
        ]));

        Services.checkAndUpdateView(view);

        const qs: QueryService = asProviderData(view, 1).instance;
        expect(qs.a.length).toBe(0);

        const childView = createEmbeddedView(view, view.def.nodes[3]);
        attachEmbeddedView(view, asElementData(view, 3), 0, childView);
        Services.checkAndUpdateView(view);

        expect(qs.a.length).toBe(1);

        detachEmbeddedView(asElementData(view, 3), 0);

        Services.checkAndUpdateView(view);

        expect(qs.a.length).toBe(0);
      });
开发者ID:IdeaBlade,项目名称:angular,代码行数:27,代码来源:query_spec.ts

示例6: it

      it('should query all matches', () => {
        class QueryService {
          // TODO(issue/24571): remove '!'.
          a !: QueryList<AService>;
        }

        const {view} = createAndGetRootNodes(compViewDef([
          elementDef(0, NodeFlags.None, null, null, 4, 'div'),
          directiveDef(1, NodeFlags.None, null, 1, QueryService, []),
          queryDef(
              NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
              {'a': QueryBindingType.All}),
          aServiceProvider(3),
          aServiceProvider(4),
        ]));

        Services.checkAndUpdateView(view);

        const qs: QueryService = asProviderData(view, 1).instance;
        expect(qs.a instanceof QueryList).toBeTruthy();
        expect(qs.a.toArray()).toEqual([
          asProviderData(view, 3).instance,
          asProviderData(view, 4).instance,
        ]);
      });
开发者ID:Cammisuli,项目名称:angular,代码行数:25,代码来源:query_spec.ts

示例7: createAndGetRootNodes

                 () => {
                   class AComp {
                     a: any;
                   }

                   const update = jasmine.createSpy('updater');

                   const {view, rootNodes} = createAndGetRootNodes(compViewDef([
          elementDef(NodeFlags.None, null, null, 1, 'div', null, null, null, null, () => compViewDef(
                  [
                    elementDef(NodeFlags.None, null, null, 0, 'span', null, [[BindingType.ElementAttribute, 'a', SecurityContext.NONE]]),
                  ],
                  null, update)),
          directiveDef(
              NodeFlags.IsComponent, null, 0, AComp, [], null, null,
              ),
        ]));

                   const compView = asElementData(view, 0).componentView;

                   update.and.callFake(
                       (check: NodeCheckFn, view: ViewData) => { throw new Error('Test'); });
                   expect(() => Services.checkAndUpdateView(view)).toThrowError('Test');
                   expect(update).toHaveBeenCalled();

                   update.calls.reset();
                   Services.checkAndUpdateView(view);
                   expect(update).not.toHaveBeenCalled();
                 });
开发者ID:rlugojr,项目名称:angular,代码行数:29,代码来源:component_view_spec.ts

示例8: it

      it('should query providers in embedded views', () => {
        const {view} = createAndGetRootNodes(compViewDef([
          elementDef(NodeFlags.None, null, null, 5, 'div'),
          ...contentQueryProviders(),
          anchorDef(NodeFlags.EmbeddedViews, null, null, 2, null, embeddedViewDef([
                      elementDef(NodeFlags.None, null, null, 1, 'div'),
                      aServiceProvider(),
                    ])),
          ...contentQueryProviders(),
        ]));

        const childView = Services.createEmbeddedView(view, view.def.nodes[3]);
        attachEmbeddedView(view, asElementData(view, 3), 0, childView);
        Services.checkAndUpdateView(view);

        // queries on parent elements of anchors
        const qs1: QueryService = asProviderData(view, 1).instance;
        expect(qs1.a.length).toBe(1);
        expect(qs1.a.first instanceof AService).toBe(true);

        // queries on the anchor
        const qs2: QueryService = asProviderData(view, 4).instance;
        expect(qs2.a.length).toBe(1);
        expect(qs2.a.first instanceof AService).toBe(true);
      });
开发者ID:ballipongala,项目名称:angular,代码行数:25,代码来源:query_spec.ts


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