1- import LoadingStoreCollection from './LoadingStoreCollection '
2- import Resource from './interfaces/Resource '
3- import Collection from './interfaces/Collection '
1+ import LoadingCollection from './LoadingCollection '
2+ import ResourceInterface from './interfaces/ResourceInterface '
3+ import CollectionInterface from './interfaces/CollectionInterface '
44
55/**
66 * Creates a placeholder for an entity which has not yet finished loading from the API.
7- * Such a LoadingStoreValue can safely be used in Vue components, since it will render as an empty
7+ * Such a LoadingResource can safely be used in Vue components, since it will render as an empty
88 * string and Vue's reactivity system will replace it with the real data once that is available.
99 *
10- * Accessing nested functions in a LoadingStoreValue yields another LoadingStoreValue :
11- * new LoadingStoreValue (...).author().organization() // gives another LoadingStoreValue
10+ * Accessing nested functions in a LoadingResource yields another LoadingResource :
11+ * new LoadingResource (...).author().organization() // gives another LoadingResource
1212 *
13- * Using a LoadingStoreValue or a property of a LoadingStoreValue in a view renders to empty strings:
14- * let user = new LoadingStoreValue (...)
13+ * Using a LoadingResource or a property of a LoadingResource in a view renders to empty strings:
14+ * let user = new LoadingResource (...)
1515 * 'The "' + user + '" is called "' + user.name + '"' // gives 'The "" is called ""'
1616 */
17- class LoadingStoreValue implements Resource {
17+ class LoadingResource implements ResourceInterface {
1818 public _meta : {
1919 self : string | null ,
20- load : Promise < Resource >
20+ load : Promise < ResourceInterface >
2121 loading : boolean
2222 }
2323
24- private loadResource : Promise < Resource >
24+ private loadResource : Promise < ResourceInterface >
2525
2626 /**
27- * @param entityLoaded a Promise that resolves to a StoreValue when the entity has finished
27+ * @param entityLoaded a Promise that resolves to a Resource when the entity has finished
2828 * loading from the API
2929 * @param absoluteSelf optional fully qualified URI of the entity being loaded, if available. If passed, the
30- * returned LoadingStoreValue will return it in calls to .self and ._meta.self
30+ * returned LoadingResource will return it in calls to .self and ._meta.self
3131 */
32- constructor ( loadResource : Promise < Resource > , absoluteSelf : string | null = null ) {
32+ constructor ( loadResource : Promise < ResourceInterface > , absoluteSelf : string | null = null ) {
3333 this . _meta = {
3434 self : absoluteSelf ,
3535 load : loadResource ,
@@ -39,28 +39,28 @@ class LoadingStoreValue implements Resource {
3939 this . loadResource = loadResource
4040
4141 const handler = {
42- get : function ( target : LoadingStoreValue , prop : string | number | symbol ) {
43- // This is necessary so that Vue's reactivity system understands to treat this LoadingStoreValue
42+ get : function ( target : LoadingResource , prop : string | number | symbol ) {
43+ // This is necessary so that Vue's reactivity system understands to treat this LoadingResource
4444 // like a normal object.
4545 if ( prop === Symbol . toPrimitive ) {
4646 return ( ) => ''
4747 }
4848
49- // This is necessary so that Vue's reactivity system understands to treat this LoadingStoreValue
49+ // This is necessary so that Vue's reactivity system understands to treat this LoadingResource
5050 // like a normal object.
5151 if ( [ 'then' , Symbol . toStringTag , 'state' , 'getters' , '$options' , '_isVue' , '__file' , 'render' , 'constructor' ] . includes ( prop as string ) ) {
5252 return undefined
5353 }
5454
55- // proxy to properties that actually exist on LoadingStoreValue (_meta, $reload, etc.)
55+ // proxy to properties that actually exist on LoadingResource (_meta, $reload, etc.)
5656 if ( Reflect . has ( target , prop ) ) {
5757 return Reflect . get ( target , prop )
5858 }
5959
60- // Proxy to all other unknown properties: return a function that yields another LoadingStoreValue
60+ // Proxy to all other unknown properties: return a function that yields another LoadingResource
6161 const loadProperty = loadResource . then ( resource => resource [ prop ] )
6262
63- const result = templateParams => new LoadingStoreValue ( loadProperty . then ( property => {
63+ const result = templateParams => new LoadingResource ( loadProperty . then ( property => {
6464 try {
6565 return property ( templateParams ) . _meta . load
6666 } catch ( e ) {
@@ -76,28 +76,28 @@ class LoadingStoreValue implements Resource {
7676 return new Proxy ( this , handler )
7777 }
7878
79- get items ( ) : Array < Resource > {
80- return LoadingStoreCollection . create ( this . loadResource . then ( resource => ( resource as Collection ) . items ) )
79+ get items ( ) : Array < ResourceInterface > {
80+ return LoadingCollection . create ( this . loadResource . then ( resource => ( resource as CollectionInterface ) . items ) )
8181 }
8282
83- get allItems ( ) : Array < Resource > {
84- return LoadingStoreCollection . create ( this . loadResource . then ( resource => ( resource as Collection ) . allItems ) )
83+ get allItems ( ) : Array < ResourceInterface > {
84+ return LoadingCollection . create ( this . loadResource . then ( resource => ( resource as CollectionInterface ) . allItems ) )
8585 }
8686
87- public $reload ( ) : Promise < Resource > {
87+ public $reload ( ) : Promise < ResourceInterface > {
8888 // Skip reloading entities that are already loading
8989 return this . _meta . load
9090 }
9191
92- public $loadItems ( ) : Promise < Collection > {
93- return this . _meta . load . then ( resource => ( resource as Collection ) . $loadItems ( ) )
92+ public $loadItems ( ) : Promise < CollectionInterface > {
93+ return this . _meta . load . then ( resource => ( resource as CollectionInterface ) . $loadItems ( ) )
9494 }
9595
96- public $post ( data : unknown ) : Promise < Resource | null > {
96+ public $post ( data : unknown ) : Promise < ResourceInterface | null > {
9797 return this . _meta . load . then ( resource => resource . $post ( data ) )
9898 }
9999
100- public $patch ( data : unknown ) : Promise < Resource > {
100+ public $patch ( data : unknown ) : Promise < ResourceInterface > {
101101 return this . _meta . load . then ( resource => resource . $patch ( data ) )
102102 }
103103
@@ -114,4 +114,4 @@ class LoadingStoreValue implements Resource {
114114 }
115115}
116116
117- export default LoadingStoreValue
117+ export default LoadingResource
0 commit comments