58 lines
954 B
JavaScript
58 lines
954 B
JavaScript
// import axios from 'axios';
|
|
import uuid from 'uuid/v4';
|
|
|
|
export class Resource {
|
|
|
|
constructor() {
|
|
this.uri_PRIVATE = undefined;
|
|
this.uuid_PRIVATE = undefined;
|
|
this.instanceUuid_PRIVATE = uuid();
|
|
}
|
|
|
|
fromJSON({uri, uuid}) {
|
|
this.uri_PRIVATE = uri;
|
|
this.uuid_PRIVATE = uuid;
|
|
return this;
|
|
}
|
|
|
|
get instanceUuid() {
|
|
return this.instanceUuid_PRIVATE;
|
|
}
|
|
|
|
regenerateUuid() {
|
|
this.uuid_PRIVATE = uuid();
|
|
}
|
|
|
|
get uuid() {
|
|
return this.uuid_PRIVATE;
|
|
}
|
|
|
|
set uuid(uuid) {
|
|
this.uuid_PRIVATE = uuid;
|
|
}
|
|
|
|
get uri() {
|
|
return this.uri_PRIVATE;
|
|
}
|
|
|
|
set uri(uri) {
|
|
this.uri_PRIVATE = uri;
|
|
}
|
|
|
|
toJSON() {
|
|
return {
|
|
uuid: this.uuid_PRIVATE,
|
|
uri: this.uri_PRIVATE,
|
|
};
|
|
}
|
|
|
|
}
|
|
|
|
Resource.createLoader = function(C) {
|
|
return (uri) => Resource.read(uri).then((O) => (new C()).fromJSON(O));
|
|
}
|
|
|
|
Resource.read = function(uri) {
|
|
return axios.get(uri).then(response => response.data);
|
|
}
|