Skip to content

Commit 32b7d7d

Browse files
feat(LdpContainer): observeContains only runs contains after debounce time
1 parent 2d6a7f9 commit 32b7d7d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

core/src/ldp-container/LdpContainer.contains.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ describe("LDP container", () => {
9494
store: Store,
9595
subscriber: jest.Mock,
9696
subscription: Subscription,
97+
container: LdpContainer,
9798
observable: Observable<ContainerContent[]>;
9899

99100
beforeEach(() => {
@@ -111,7 +112,7 @@ describe("LDP container", () => {
111112
internalStore,
112113
);
113114
subscriber = jest.fn();
114-
const container = new LdpContainer("https://pod.test/container/", store);
115+
container = new LdpContainer("https://pod.test/container/", store);
115116
observable = container.observeContains();
116117
subscription = observable.subscribe(subscriber);
117118
});
@@ -142,6 +143,7 @@ describe("LDP container", () => {
142143
});
143144

144145
it("pushes new values once per group of changes until unsubcribe, ignoring irrelevant changes", () => {
146+
const containsSpy = jest.spyOn(container, "contains");
145147
// wait for first push to settle
146148
jest.advanceTimersByTime(250);
147149
// then update container contents
@@ -167,6 +169,7 @@ describe("LDP container", () => {
167169
]);
168170
jest.advanceTimersByTime(255);
169171
expect(subscriber).toHaveBeenCalledTimes(2);
172+
expect(containsSpy).toHaveBeenCalledTimes(2);
170173
expect(subscriber.mock.calls).toEqual([
171174
[
172175
[
@@ -199,6 +202,7 @@ describe("LDP container", () => {
199202
sym("https://pod.test/container/"),
200203
);
201204
expect(subscriber).toHaveBeenCalledTimes(2);
205+
expect(containsSpy).toHaveBeenCalledTimes(2);
202206
});
203207
});
204208
});

core/src/ldp-container/LdpContainer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class LdpContainer extends Thing {
3636

3737
/**
3838
* Observe changes to the resources that the LDP Container contains
39-
*
39+
*
4040
* @returns RxJS Observable that pushes a new contains() array when it changes
4141
*/
4242
observeContains(): Observable<ContainerContent[]> {
@@ -46,9 +46,9 @@ export class LdpContainer extends Thing {
4646
quad.graph.value == this.uri &&
4747
quad.predicate.value == "http://www.w3.org/ns/ldp#contains",
4848
),
49-
map(() => this.contains()),
5049
startWith(this.contains()),
5150
debounceTime(250),
51+
map(() => this.contains()),
5252
);
5353
}
5454
}

0 commit comments

Comments
 (0)