Skip to content

Commit

Permalink
[utils/subscribeWithScope] rename
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Oct 17, 2018
1 parent 8ae9b01 commit dd10472
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/ui/public/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import angular from 'angular';
import chrome from '../chrome';
import { isPlainObject } from 'lodash';
import { uiModules } from '../modules';
import { subscribe } from '../utils/subscribe';
import { subscribeWithScope } from '../utils/subscribe_with_scope';

const module = uiModules.get('kibana/config');

Expand Down Expand Up @@ -60,7 +60,7 @@ module.service(`config`, function ($rootScope, Promise) {
//* angular specific methods *
//////////////////////////////

const subscription = subscribe($rootScope, uiSettings.getUpdate$(), {
const subscription = subscribeWithScope($rootScope, uiSettings.getUpdate$(), {
next: ({ key, newValue, oldValue }) => {
$rootScope.$broadcast('change:config', newValue, oldValue, key, this);
$rootScope.$broadcast(`change:config.${key}`, newValue, oldValue, key, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jest.mock('ui/notify/fatal_error', () => ({
}));

import * as Rx from 'rxjs';
import { subscribe } from './subscribe';
import { subscribeWithScope } from './subscribe_with_scope';

let $rootScope: Scope;

Expand All @@ -46,7 +46,7 @@ it('subscribes to the passed observable, returns subscription', () => {
const subSpy = jest.fn(() => unsubSpy);
const observable = new Rx.Observable(subSpy);

const subscription = subscribe($scope as any, observable);
const subscription = subscribeWithScope($scope as any, observable);
expect(subSpy).toHaveBeenCalledTimes(1);
expect(unsubSpy).not.toHaveBeenCalled();

Expand All @@ -61,7 +61,7 @@ it('calls observer.next() if already in a digest cycle, wraps in $scope.$apply i
const nextSpy = jest.fn();
const $scope = new Scope();

subscribe($scope as any, subject, { next: nextSpy });
subscribeWithScope($scope as any, subject, { next: nextSpy });

subject.next();
expect($scope.$apply).toHaveBeenCalledTimes(1);
Expand All @@ -77,7 +77,7 @@ it('calls observer.next() if already in a digest cycle, wraps in $scope.$apply i

it('reports fatalError if observer.next() throws', () => {
const $scope = new Scope();
subscribe($scope as any, Rx.of(undefined), {
subscribeWithScope($scope as any, Rx.of(undefined), {
next() {
throw new Error('foo bar');
},
Expand All @@ -96,12 +96,12 @@ it('reports fatal error if observer.error is not defined and observable errors',
const $scope = new Scope();
const error = new Error('foo');
error.stack = `${error.message}\n---stack trace ---`;
subscribe($scope as any, Rx.throwError(error));
subscribeWithScope($scope as any, Rx.throwError(error));

expect(mockFatalError.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
[Error: Uncaught error in $scope.$subscribe: foo
[Error: Uncaught error in subscribeWithScope(): foo
---stack trace ---],
],
]
Expand All @@ -110,7 +110,7 @@ Array [

it('reports fatal error if observer.error throws', () => {
const $scope = new Scope();
subscribe($scope as any, Rx.throwError(new Error('foo')), {
subscribeWithScope($scope as any, Rx.throwError(new Error('foo')), {
error: () => {
throw new Error('foo');
},
Expand All @@ -127,7 +127,7 @@ Array [

it('does not report fatal error if observer.error handles the error', () => {
const $scope = new Scope();
subscribe($scope as any, Rx.throwError(new Error('foo')), {
subscribeWithScope($scope as any, Rx.throwError(new Error('foo')), {
error: () => {
// noop, swallow error
},
Expand All @@ -138,7 +138,7 @@ it('does not report fatal error if observer.error handles the error', () => {

it('reports fatal error if observer.complete throws', () => {
const $scope = new Scope();
subscribe($scope as any, Rx.EMPTY, {
subscribeWithScope($scope as any, Rx.EMPTY, {
complete: () => {
throw new Error('foo');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function callInDigest<T extends any[]>($scope: IScope, fn: (...args: T) => void,
* Subscribe to an observable at a $scope, ensuring that the digest cycle
* is run for subscriber hooks and routing errors to fatalError if not handled.
*/
export function subscribe<T>(
export function subscribeWithScope<T>(
$scope: IScope,
observable: Rx.Observable<T>,
observer?: Rx.PartialObserver<T>
Expand All @@ -60,7 +60,9 @@ export function subscribe<T>(
observer.error(error);
} else {
throw new Error(
`Uncaught error in $scope.$subscribe: ${error ? error.stack || error.message : error}`
`Uncaught error in subscribeWithScope(): ${
error ? error.stack || error.message : error
}`
);
}
});
Expand Down

0 comments on commit dd10472

Please sign in to comment.