【发布时间】:2017-05-13 17:20:48
【问题描述】:
因此,对于 C# 和其他语言,您可以在属性上使用 get 和 set 评估器,构建延迟加载模式非常简单。
我最近才开始使用 Type Script,并且正在尝试实现相同的目标。我正在通过 Ajax 调用加载具有大部分属性的 Poco。问题可以描述如下:
export interface IDeferredObject<T> {
HasLoaded: boolean;
DeferredURI: string;
}
export class Library{
LibraryName: string;
Books: IDeferredObject<Book[]>;
}
export class Book {
Title: string;
UniqueNumber: number;
}
window.onload = () => {
//Instantiate new Library
var lib = new Library();
//Set some properties
lib.LibraryName = "Some Library";
//Set the Deferred URI Rest EndPoint
lib.Books.DeferredURI = "http://somerestendpoint";
lib.Books.HasLoaded;
//Something will trigger a GET to lib.Books which then needs to load using the Deferred Uri
};
几个问题: 我
- 接口是否适合在这里使用?
- 我想在访问图书馆图书属性时触发加载操作。这甚至可能吗?
我知道这是一个非常开放的问题,只是在寻找有关如何构建该模式的一些指导。
谢谢
【问题讨论】:
标签: javascript design-patterns typescript lazy-loading