-
Notifications
You must be signed in to change notification settings - Fork 5
Reactive pos-container-contents #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bc915d6
21d6646
5d5bbf4
b8555e1
a59959c
82de425
8115332
079fef7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { sym } from "rdflib"; | ||
| import { labelFromUri, Thing } from "../thing"; | ||
| import { Store } from "../Store"; | ||
| import { debounceTime, filter, map, merge, Observable, startWith } from "rxjs"; | ||
|
|
||
| export interface ContainerContent { | ||
| uri: string; | ||
|
|
@@ -15,6 +16,11 @@ export class LdpContainer extends Thing { | |
| super(uri, store, editable); | ||
| } | ||
|
|
||
| /** | ||
| * Resources that the LDP Container contains | ||
| * | ||
| * @returns Array of objects with uri and name | ||
| */ | ||
| contains(): ContainerContent[] { | ||
| const contains = this.store.statementsMatching( | ||
| sym(this.uri), | ||
|
|
@@ -27,4 +33,22 @@ export class LdpContainer extends Thing { | |
| name: labelFromUri(content.object.value), | ||
| })); | ||
| } | ||
|
|
||
| /** | ||
| * Observe changes to the resources that the LDP Container contains | ||
| * | ||
| * @returns RxJS Observable that pushes a new contains() array when it changes | ||
| */ | ||
| observeContains(): Observable<ContainerContent[]> { | ||
| return merge(this.store.additions$, this.store.removals$).pipe( | ||
| filter( | ||
| (quad) => | ||
| quad.graph.value == this.uri && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Why graph and not subject?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: i wonder if the merge, pipe, filter pattern should be a convenience function on store. I guess we will need it a lot
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The graph limits changes to this container, i.e. ldp:contains triples in other documents won't trigger. In principle this minimises some triple injection issues, though in practice I was simply trying to find an efficient filter.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still expecting that we might want to reuse specific filters - at the moment a new observable is created for every call. |
||
| quad.predicate.value == "http://www.w3.org/ns/ldp#contains", | ||
| ), | ||
| debounceTime(250), | ||
| map(() => this.contains()), | ||
| startWith(this.contains()), | ||
| ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.