* Adds a Resource to the store and notifies subscribers. Replaces existing * resources, unless this new resource is explicitly incomplete.
(resource: Resource)
| 56 | * resources, unless this new resource is explicitly incomplete. |
| 57 | */ |
| 58 | addResource(resource: Resource): void { |
| 59 | // Incomplete resources may miss some properties |
| 60 | if (resource.get(urls.properties.incomplete)) { |
| 61 | // If there is a resource with the same subject, we won't overwrite it with an incomplete one |
| 62 | const existing = this.resources.get(resource.getSubject()); |
| 63 | if (existing && !existing.loading) { |
| 64 | return; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | this.resources.set(resource.getSubject(), resource); |
| 69 | // We clone |
| 70 | this.notify(resource.clone()); |
| 71 | } |
| 72 | |
| 73 | /** Checks if a subject is free to use */ |
| 74 | async checkSubjectTaken(subject: string): Promise<boolean> { |
no test coverage detected