So with C# and other languages where you have a get and set assessor on properties, it's quite simple to build a lazy loading pattern.
I only recently started playing with Type Script and I'm trying to achieve something the same. I'm loading a Poco with most of it's properties via a Ajax Call. The problem can be described below:
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
};
Couple of questions: I
- Is a Interface even the right thing to use here?
- I'd like to trigger a Load action when something accesses the Library Books Property. Is this even possible?
I know it's quite an open question, just looking for some guidance on how to build that pattern.
Thanks