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

TypeScript recentHistory.service.RecentHistoryService类代码示例

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

本文整理汇总了TypeScript中core/history/recentHistory.service.RecentHistoryService的典型用法代码示例。如果您正苦于以下问题:TypeScript service.RecentHistoryService类的具体用法?TypeScript service.RecentHistoryService怎么用?TypeScript service.RecentHistoryService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: describe

describe('recent history service', () => {

  let service: RecentHistoryService,
      deckCacheFactory: DeckCacheService,
      backingCache: ICache;

  beforeEach(
    mock.module(
      RECENT_HISTORY_SERVICE
    )
  );

  beforeEach(mock.inject((recentHistoryService: RecentHistoryService, _deckCacheFactory_: DeckCacheService) => {
    service = recentHistoryService;
    deckCacheFactory = _deckCacheFactory_;
    deckCacheFactory.clearCache('history', 'user');
    backingCache = deckCacheFactory.getCache('history', 'user');
  }));

  describe('getItems returns items most recent first', () => {

    it('returns an empty list if none found', () => {
      expect(service.getItems('something')).toEqual([]);
    });

    it('returns whatever is in cache if something is found, ordered by accessTime', () => {
      backingCache.put('whatever', [{ accessTime: 1 }, { accessTime: 3 }, { accessTime: 2 }]);
      expect(service.getItems('whatever').map((item) => { return item.accessTime; })).toEqual([3, 2, 1]);
    });
  });

  describe('addItem is fancy', () => {

    function initializeCache(count: number) {
      const start = Date.now() - 1;
      const currentItems = range(0, count).map((idx: number) => {
        return { id: '' + idx, params: { id: idx }, accessTime: start - idx };
      });
      backingCache.put('whatever', currentItems);
    }

    it('puts items in cache most recent first', () => {
      initializeCache(2);
      service.addItem('whatever', 'state', { id: 'new item' });
      const ids = service.getItems('whatever').map((item) => { return item.params.id; });
      expect(ids).toEqual(['new item', 0, 1]);
    });

    it('replaces oldest item if cache is full', () => {
      initializeCache(15);
      service.addItem('whatever', 'state', { id: 'new item' });
      const ids = service.getItems('whatever').map((item) => { return item.params.id; });
      expect(ids).toEqual(['new item', 0, 1, 2, 3]);
    });

    it('removes previous entry and adds replacement if params match, ignoring undefined values', () => {
      initializeCache(3);
      service.addItem('whatever', 'state', { id: 1, someUndefinedValue: undefined });
      const ids = service.getItems('whatever').map((item) => { return item.params.id; });
      expect(ids).toEqual([1, 0, 2]);
    });

    it('only matches on specified params if supplied', () => {
      const start = Date.now() - 1;
      const currentItems = range(0, 3).map((idx: number) => {
        return { params: { id: idx, importantParam: idx, ignoredParam: idx + 1 }, accessTime: start - idx };
      });
      backingCache.put('whatever', currentItems);
      service.addItem('whatever', 'state', { id: 1, importantParam: 1, ignoredParam: 1000 }, ['importantParam', 'id']);
      let ids = service.getItems('whatever').map((item) => { return item.params.id; });
      expect(ids).toEqual([1, 0, 2]);
      service.addItem('whatever', 'state', { id: 1, importantParam: 1, ignoredParam: 1001 }, ['ignoredParam']);
      ids = service.getItems('whatever').map((item) => { return item.params.id; });
      expect(ids).toEqual([1, 1, 0, 2]);
    });
  });

  describe('remove item from history cache by app name', () => {
    beforeEach(() => {
        const start = Date.now() - 1;
        const currentItems = ['foo', 'bar', 'baz'].map((appName, index) => {
          return { params: { application: appName, accessTime: start - index } };
        });
        backingCache.put('applications', currentItems);
      }
    );

    it('should have 3 items in the "applications" cache', () => {
      const items = service.getItems('applications');
      expect(items.length).toBe(3);
    });

    it('should have 2 items in the "application" cache when we remove "foo" by application name', () => {
      service.removeByAppName('foo');
      const items = service.getItems('applications');
      expect(items.length).toBe(2);
      expect(some(items, { params: { application: 'foo' } })).toBeFalsy();
    });
  });

//.........这里部分代码省略.........
开发者ID:robfletcher,项目名称:deck,代码行数:101,代码来源:recentHistory.service.spec.ts


示例2: it

 it('only matches on specified params if supplied', () => {
   const start = Date.now() - 1;
   const currentItems = range(0, 3).map((idx: number) => {
     return { params: { id: idx, importantParam: idx, ignoredParam: idx + 1 }, accessTime: start - idx };
   });
   backingCache.put('whatever', currentItems);
   service.addItem('whatever', 'state', { id: 1, importantParam: 1, ignoredParam: 1000 }, ['importantParam', 'id']);
   let ids = service.getItems('whatever').map((item) => { return item.params.id; });
   expect(ids).toEqual([1, 0, 2]);
   service.addItem('whatever', 'state', { id: 1, importantParam: 1, ignoredParam: 1001 }, ['ignoredParam']);
   ids = service.getItems('whatever').map((item) => { return item.params.id; });
   expect(ids).toEqual([1, 1, 0, 2]);
 });
开发者ID:robfletcher,项目名称:deck,代码行数:13,代码来源:recentHistory.service.spec.ts


示例3:

 .then((task: any): any => {
   this.recentHistoryService.removeByAppName(application.name);
   return task;
 })
开发者ID:sghill,项目名称:deck,代码行数:4,代码来源:application.write.service.ts



注:本文中的core/history/recentHistory.service.RecentHistoryService类示例由纯净天空整理自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