-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* ♻️ add callback capabilities to observable * ♻️ use new capabilities for domMutationObservable * 👌 tweak API * 👌 simplify implementation
- Loading branch information
Showing
10 changed files
with
114 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Observable } from '@datadog/browser-core' | ||
|
||
describe('observable', () => { | ||
let observable: Observable<void> | ||
let subscriber: jasmine.Spy<jasmine.Func> | ||
|
||
beforeEach(() => { | ||
observable = new Observable() | ||
subscriber = jasmine.createSpy('sub') | ||
}) | ||
|
||
it('should allow to subscribe and be notified', () => { | ||
observable.subscribe(subscriber) | ||
expect(subscriber).not.toHaveBeenCalled() | ||
|
||
observable.notify() | ||
expect(subscriber).toHaveBeenCalledTimes(1) | ||
|
||
observable.notify() | ||
expect(subscriber).toHaveBeenCalledTimes(2) | ||
}) | ||
|
||
it('should notify multiple clients', () => { | ||
const otherSubscriber = jasmine.createSpy('sub2') | ||
observable.subscribe(subscriber) | ||
observable.subscribe(otherSubscriber) | ||
|
||
observable.notify() | ||
|
||
expect(subscriber).toHaveBeenCalled() | ||
expect(otherSubscriber).toHaveBeenCalled() | ||
}) | ||
|
||
it('should allow to unsubscribe', () => { | ||
const subscription = observable.subscribe(subscriber) | ||
|
||
subscription.unsubscribe() | ||
observable.notify() | ||
|
||
expect(subscriber).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('should execute onFirstSubscribe callback', () => { | ||
const onFirstSubscribe = jasmine.createSpy('callback') | ||
const otherSubscriber = jasmine.createSpy('sub2') | ||
observable = new Observable(onFirstSubscribe) | ||
expect(onFirstSubscribe).not.toHaveBeenCalled() | ||
|
||
observable.subscribe(subscriber) | ||
expect(onFirstSubscribe).toHaveBeenCalledTimes(1) | ||
|
||
observable.subscribe(otherSubscriber) | ||
expect(onFirstSubscribe).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('should execute onLastUnsubscribe callback', () => { | ||
const onLastUnsubscribe = jasmine.createSpy('callback') | ||
const otherSubscriber = jasmine.createSpy('sub2') | ||
observable = new Observable(() => onLastUnsubscribe) | ||
const subscription = observable.subscribe(subscriber) | ||
const otherSubscription = observable.subscribe(otherSubscriber) | ||
expect(onLastUnsubscribe).not.toHaveBeenCalled() | ||
|
||
subscription.unsubscribe() | ||
expect(onLastUnsubscribe).not.toHaveBeenCalled() | ||
|
||
otherSubscription.unsubscribe() | ||
expect(onLastUnsubscribe).toHaveBeenCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters