本文整理汇总了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;未经允许,请勿转载。 |
请发表评论