1
- import CanHaveItems from './CanHaveItems'
2
1
// import LoadingStoreCollection from './LoadingStoreCollection'
3
2
import Resource , { EmbeddedCollectionType } from './interfaces/Resource'
4
- import ApiActions from './interfaces/ApiActions'
5
- import { InternalConfig } from './interfaces/Config'
6
- import StoreData , { Link } from './interfaces/StoreData'
3
+ import { Link } from './interfaces/StoreData'
7
4
8
5
/**
9
6
* Imitates a full standalone collection with an items property, even if there is no separate URI (as it
@@ -12,7 +9,7 @@ import StoreData, { Link } from './interfaces/StoreData'
12
9
* URI, we need to reload the whole entity containing the embedded collection. Some extra info about the
13
10
* containing entity must therefore be passed to the constrcutor.
14
11
*/
15
- class EmbeddedCollection extends CanHaveItems implements EmbeddedCollectionType {
12
+ class EmbeddedCollection implements EmbeddedCollectionType {
16
13
public _meta : {
17
14
load : Promise < EmbeddedCollectionType > ,
18
15
reload : { // TODO: do we want/need to expose this externally? or sufficient if we keep this in the store and expose $reload()?
@@ -21,6 +18,10 @@ class EmbeddedCollection extends CanHaveItems implements EmbeddedCollectionType
21
18
}
22
19
}
23
20
21
+ _storeData : {
22
+ items : Array < Link >
23
+ }
24
+
24
25
/**
25
26
* @param items array of items, which can be mixed primitive values and entity references
26
27
* @param reloadUri URI of the entity containing the embedded collection (for reloading)
@@ -29,29 +30,30 @@ class EmbeddedCollection extends CanHaveItems implements EmbeddedCollectionType
29
30
* @param config dependency injection of config object
30
31
* @param loadParent a promise that will resolve when the parent entity has finished (re-)loading
31
32
*/
32
- constructor ( items : Array < Link > , reloadUri : string , reloadProperty : string , apiActions : ApiActions , config : InternalConfig , loadParent : Promise < StoreData > | null = null ) {
33
- super ( apiActions , config , items , reloadUri , reloadProperty )
33
+ constructor ( items : Array < Link > , reloadUri : string , reloadProperty : string , loadCollection : Promise < EmbeddedCollectionType > | null = null ) {
34
+ this . _storeData = {
35
+ items
36
+ }
34
37
35
38
this . _meta = {
36
- load : loadParent
37
- ? loadParent . then ( parentResource => new EmbeddedCollection ( parentResource [ reloadProperty ] , reloadUri , reloadProperty , apiActions , config ) )
38
- : Promise . resolve ( this ) ,
39
+ load : loadCollection || Promise . resolve ( this ) ,
39
40
reload : {
40
41
uri : reloadUri ,
41
42
property : reloadProperty
42
43
}
43
44
}
44
45
}
45
46
47
+ /*
46
48
$loadItems () :Promise<Array<Resource>> {
47
49
return new Promise((resolve) => {
48
- const items = this . items
50
+ const items = this._storeData. items
49
51
// TODO: this is probably broken as LoadingStoreCollection has no constructor anymore
50
52
// if (items instanceof LoadingStoreCollection) items._meta.load.then(result => resolve(result))
51
53
// else resolve(items)
52
54
resolve(items)
53
55
})
54
- }
56
+ } */
55
57
}
56
58
57
59
export default EmbeddedCollection
0 commit comments