This repository has been archived by the owner on Oct 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
HalCollection #37
Comments
A quick test and this seems to work: class Collection extends Array {
public fetch () {
return Promise.all(this.map(res => res.fetch()))
}
}
var collection = Collection.from(root.sites)
collection.fetch().then(console.log)
Thoughts? |
Hmm. So I got this working nicely, then discovered that Vue converts any classes extending Array to Arrays when it uses them. I'm sure IE will probably have issues as well. So it seems to me that this might also be solved most easily with a For now, I can add it to a model: import { HalResource } from 'hal-rest-client'
export class BaseModel extends HalResource {
public fetchProp (name: string, forceOrParams ?: boolean | object): Promise<HalResource | HalResource[]> {
const prop = this.prop(name)
return Array.isArray(prop)
? Promise.all(prop.map((res: HalResource) => res.fetch(forceOrParams)))
: prop.fetch(forceOrParams)
}
} |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
It seems that fetching collections of links could do with a bit of sugar.
Right now, to collect a list of resources from an array of links we need something along the lines of:
If we had a
HalCollection
class, with perhaps anIFetchable
interface, bothHalResource
andHalCollection
could befetch()
ed:Of course the collection class would be iterable just like an
Array
as well.What do you think?
The text was updated successfully, but these errors were encountered: