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

TypeScript og-lru-cache-factory.OgLruCache类代码示例

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

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



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

示例1: describe

	describe("new", (): void => {
		let ogLruCache: OgLruCache;

		it("should return an LruCache", (): Chai.Assertion => ogLruCacheFactory.new(10, []).should.be.an("object"));

		describe("LruCache (empty)", (): void => {
			beforeEach((): OgLruCache => (ogLruCache = ogLruCacheFactory.new(10, [])));

			it("should have the specified capacity", (): Chai.Assertion => ogLruCache["capacity"].should.equal(10));

			it("should have no items", (): Chai.Assertion => ogLruCache.list.should.be.an("array").that.is.empty);
		});

		describe("LruCache", (): void => {
			const capacity: number = 10;
			let	data: OgCacheEntry[],
					list: OgCacheEntry[];

			beforeEach((): void => {
				// Populate the data with capacity + 1 items (to check that the oldest item is evicted)
				data = [...Array(capacity + 1).keys()].reverse().map((id: number): OgCacheEntry => ({id, name: `item ${id}`}));
				list = data.slice(0, capacity);

				// Create the LruCache
				ogLruCache = ogLruCacheFactory.new(capacity, data);
			});

			it("should be populated with the initial set of items", (): Chai.Assertion => ogLruCache["items"].should.deep.equal(list));

			describe("put", (): void => {
				it("should leave the list unchanged if the item is already the current head", (): Chai.Assertion => ogLruCache.put({id: capacity, name: `item ${capacity}`}).should.deep.equal(list));

				const scenarios: {description: string, item: OgCacheEntry, currentIndex?: number}[] = [
					{
						description: "move an existing item from the tail of the list to the head of the list",
						item: {id: 1, name: "item 1"}
					},
					{
						description: "move an existing item to the head of the list",
						item: {id: 2, name: "item 2"},
						currentIndex: 8
					},
					{
						description: "add a new item to the list",
						item: {id: 11, name: "item 11"}
					}
				];

				scenarios.forEach((scenario: {description: string, item: OgCacheEntry, currentIndex?: number}): void => {
					it(`should ${scenario.description}`, (): void => {
						const newList: OgCacheEntry[] = ogLruCache.put(scenario.item);

						if (scenario.currentIndex) {
							list.splice(scenario.currentIndex, 1);
						} else {
							list.pop();
						}
						list.unshift(scenario.item);
						newList.should.deep.equal(list);
					});
				});

				it("should add a new item to an empty list", (): void => {
					ogLruCache["items"] = [];

					const item: OgCacheEntry = {id: 11, name: "item 11"},
								newList: OgCacheEntry[] = ogLruCache.put(item);

					list = [item];
					newList.should.deep.equal(list);
				});
			});

			describe("remove", (): void => {
				it("should leave the list unchanged if the item does not exist", (): Chai.Assertion => ogLruCache.remove(-1).should.deep.equal(list));

				describe("existing item", (): void => {
					let id: number;

					it("should remove the only item from the list", (): void => {
						id = 1;
						ogLruCache["items"] = [
							{id, name: `item ${id}`}
						];

						ogLruCache.remove(id);
						ogLruCache["items"].should.be.an("array").that.is.empty;
					});

					it("should remove an item from the head of the list", (): void => {
						id = 10;
						ogLruCache.remove(id);
						ogLruCache["items"].should.deep.equal(list.slice(1, capacity));
					});

					it("should remove an item from the tail of the list", (): void => {
						id = 1;
						ogLruCache.remove(id);
						ogLruCache["items"].should.deep.equal(list.slice(0, capacity - 1));
					});
//.........这里部分代码省略.........
开发者ID:scottohara,项目名称:loot,代码行数:101,代码来源:og-lru-cache-factory.ts


示例2: removeRecent

	// Remove an item from the LRU cache
	public removeRecent(id: number): void {
		// Remove the item from the LRU cache
		this.recent = this.lruCache.remove(id);

		// Update local storage with the new list
		this.$window.localStorage.setItem(this.LRU_LOCAL_STORAGE_KEY, JSON.stringify(this.lruCache.list));
	}
开发者ID:scottohara,项目名称:loot,代码行数:8,代码来源:payee.ts


示例3: addRecent

	// Put an item into the LRU cache
	public addRecent(payee: Payee): void {
		// Put the item into the LRU cache
		this.recent = this.lruCache.put(payee);

		// Update local storage with the new list
		this.$window.localStorage.setItem(this.LRU_LOCAL_STORAGE_KEY, JSON.stringify(this.lruCache.list));
	}
开发者ID:scottohara,项目名称:loot,代码行数:8,代码来源:payee.ts


示例4:

					it("should remove the only item from the list", (): void => {
						id = 1;
						ogLruCache["items"] = [
							{id, name: `item ${id}`}
						];

						ogLruCache.remove(id);
						ogLruCache["items"].should.be.an("array").that.is.empty;
					});
开发者ID:scottohara,项目名称:loot,代码行数:9,代码来源:og-lru-cache-factory.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript types.OgTableNavigableScope类代码示例发布时间:2022-05-25
下一篇:
TypeScript og-lru-cache-factory.new函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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