• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript message_bus.MessageBus类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@angular/platform-webworker/src/web_workers/shared/message_bus.MessageBus的典型用法代码示例。如果您正苦于以下问题:TypeScript MessageBus类的具体用法?TypeScript MessageBus怎么用?TypeScript MessageBus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: beforeEach

 beforeEach(() => {
   const buses = createPairedMessageBuses();
   uiBus = buses.ui;
   workerBus = buses.worker;
   workerBus.initChannel('ng-Router');
   uiBus.initChannel('ng-Router');
   broker = new SpyMessageBroker();
 });
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:8,代码来源:platform_location_spec.ts


示例2: inject

       inject([AsyncTestCompleter, NgZone], (async: AsyncTestCompleter, zone: MockNgZone) => {
         bus = createConnectedMessageBus();
         setup(false, zone);

         let wasCalled = false;
         bus.from(CHANNEL).subscribe({next: (message: any) => { wasCalled = true; }});
         bus.to(CHANNEL).emit('hi');

         flushMessages(() => {
           expect(wasCalled).toBeTruthy();
           async.done();
         });
       }), 10000);
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:13,代码来源:message_bus_spec.ts


示例3: createConnectedMessageBus

               (async: AsyncTestCompleter, zone: MockNgZone) => {
                 bus = createConnectedMessageBus();
                 setup(true, zone);

                 var wasCalled = false;
                 bus.from(CHANNEL).subscribe({next: (message: any) => { wasCalled = true; }});
                 bus.to(CHANNEL).emit('hi');


                 flushMessages(() => {
                   expect(wasCalled).toBeFalsy();

                   zone.simulateZoneExit();
                   flushMessages(() => {
                     expect(wasCalled).toBeTruthy();
                     async.done();
                   });
                 });
               }),
开发者ID:JanStureNielsen,项目名称:angular,代码行数:19,代码来源:message_bus_spec.ts


示例4: describe

  describe('PostMessageBusSink', () => {
    let bus: MessageBus;
    const CHANNEL = 'Test Channel';

    function setup(runInZone: boolean, zone: NgZone) {
      bus.attachToZone(zone);
      bus.initChannel(CHANNEL, runInZone);
    }

    /**
     * Flushes pending messages and then runs the given function.
     */
    // TODO(mlaval): timeout is fragile, test to be rewritten
    function flushMessages(fn: () => void) { setTimeout(fn, 50); }

    it('should buffer messages and wait for the zone to exit before sending',
       withModule({providers: [{provide: NgZone, useClass: MockNgZone}]})
           .inject(
               [AsyncTestCompleter, NgZone],
               (async: AsyncTestCompleter, zone: MockNgZone) => {
                 bus = createConnectedMessageBus();
                 setup(true, zone);

                 let wasCalled = false;
                 bus.from(CHANNEL).subscribe({next: (message: any) => { wasCalled = true; }});
                 bus.to(CHANNEL).emit('hi');


                 flushMessages(() => {
                   expect(wasCalled).toBeFalsy();

                   zone.simulateZoneExit();
                   flushMessages(() => {
                     expect(wasCalled).toBeTruthy();
                     async.done();
                   });
                 });
               }),
       500);

    it('should send messages immediately when run outside the zone',
       inject([AsyncTestCompleter, NgZone], (async: AsyncTestCompleter, zone: MockNgZone) => {
         bus = createConnectedMessageBus();
         setup(false, zone);

         let wasCalled = false;
         bus.from(CHANNEL).subscribe({next: (message: any) => { wasCalled = true; }});
         bus.to(CHANNEL).emit('hi');

         flushMessages(() => {
           expect(wasCalled).toBeTruthy();
           async.done();
         });
       }), 10000);
  });
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:55,代码来源:message_bus_spec.ts


示例5: describe

  describe('WebWorkerPlatformLocation', () => {
    let uiBus: MessageBus = null !;
    let workerBus: MessageBus = null !;
    let broker: any = null;

    const TEST_LOCATION = new LocationType(
        'http://www.example.com', 'http', 'example.com', 'example.com', '80', '/', '', '',
        'http://www.example.com');


    function createWebWorkerPlatformLocation(loc: LocationType): WebWorkerPlatformLocation {
      broker.spy('runOnService')
          .and.callFake((args: UiArguments, returnType: Type<any>| SerializerTypes) => {
            if (args.method === 'getLocation') {
              return Promise.resolve(loc);
            }
          });
      const factory = new MockMessageBrokerFactory(broker);
      return new WebWorkerPlatformLocation(factory, workerBus, null !);
    }

    function testPushOrReplaceState(pushState: boolean) {
      const platformLocation = createWebWorkerPlatformLocation(null !);
      const TITLE = 'foo';
      const URL = 'http://www.example.com/foo';
      expectBrokerCall(broker, pushState ? 'pushState' : 'replaceState', [null, TITLE, URL]);
      if (pushState) {
        platformLocation.pushState(null, TITLE, URL);
      } else {
        platformLocation.replaceState(null, TITLE, URL);
      }
    }

    beforeEach(() => {
      const buses = createPairedMessageBuses();
      uiBus = buses.ui;
      workerBus = buses.worker;
      workerBus.initChannel('ng-Router');
      uiBus.initChannel('ng-Router');
      broker = new SpyMessageBroker();
    });

    it('should throw if getBaseHrefFromDOM is called', () => {
      const platformLocation = createWebWorkerPlatformLocation(null !);
      expect(() => platformLocation.getBaseHrefFromDOM()).toThrowError();
    });

    it('should get location on init', () => {
      const platformLocation = createWebWorkerPlatformLocation(null !);
      expectBrokerCall(broker, 'getLocation');
      platformLocation.init();
    });

    it('should throw if set pathname is called before init finishes', () => {
      const platformLocation = createWebWorkerPlatformLocation(null !);
      platformLocation.init();
      expect(() => platformLocation.pathname = 'TEST').toThrowError();
    });

    it('should send pathname to render thread', done => {
      const platformLocation = createWebWorkerPlatformLocation(TEST_LOCATION);
      platformLocation.init().then((_) => {
        const PATHNAME = '/test';
        expectBrokerCall(broker, 'setPathname', [PATHNAME]);
        platformLocation.pathname = PATHNAME;
        done();
      });
    });

    it('should send pushState to render thread', () => { testPushOrReplaceState(true); });

    it('should send replaceState to render thread', () => { testPushOrReplaceState(false); });
  });
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:73,代码来源:platform_location_spec.ts


示例6: it

    it('should broadcast', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
         const CHANNEL = 'CHANNEL 1';
         const MESSAGE = 'TESTING';
         const NUM_LISTENERS = 2;
         bus.initChannel(CHANNEL, false);

         let callCount = 0;
         const emitHandler = (message: any) => {
           expect(message).toEqual(MESSAGE);
           callCount++;
           if (callCount == NUM_LISTENERS) {
             async.done();
           }
         };

         for (let i = 0; i < NUM_LISTENERS; i++) {
           const emitter = bus.from(CHANNEL);
           emitter.subscribe({next: emitHandler});
         }

         const toEmitter = bus.to(CHANNEL);
         toEmitter.emit(MESSAGE);
       }));
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:23,代码来源:message_bus_spec.ts


示例7: setup

 function setup(runInZone: boolean, zone: NgZone) {
   bus.attachToZone(zone);
   bus.initChannel(CHANNEL, runInZone);
 }
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:4,代码来源:message_bus_spec.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap