Skip to content

Commit

Permalink
refactor #start, #pause, #dispose (#716)
Browse files Browse the repository at this point in the history
Replaced confusing set of three methods with just two
.start - starts locationManager service
.stop - stops locationManager service

.stop internally calls `dispose`, however stop is more sementic in our
usecases

remove .pause
  • Loading branch information
ferdicus authored Mar 11, 2020
1 parent 319529a commit 77f4247
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 23 deletions.
6 changes: 3 additions & 3 deletions __tests__/components/UserLocation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('UserLocation', () => {
beforeEach(() => {
ul = new UserLocation();
jest.spyOn(locationManager, 'start').mockImplementation(jest.fn());
jest.spyOn(locationManager, 'dispose').mockImplementation(jest.fn());
jest.spyOn(locationManager, 'stop').mockImplementation(jest.fn());
jest
.spyOn(locationManager, 'getLastKnownLocation')
.mockImplementation(() => position);
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('UserLocation', () => {
expect(ul.setState).toHaveBeenCalledWith({
coordinates: lastKnownLocation,
});
expect(locationManager.dispose).not.toHaveBeenCalled();
expect(locationManager.stop).not.toHaveBeenCalled();
});

test('called with "running" false', async () => {
Expand All @@ -202,7 +202,7 @@ describe('UserLocation', () => {
expect(ul.locationManagerRunning).toStrictEqual(false);
// only once from start
expect(locationManager.start).toHaveBeenCalledTimes(1);
expect(locationManager.dispose).toHaveBeenCalledTimes(1);
expect(locationManager.stop).toHaveBeenCalledTimes(1);
});
});

Expand Down
2 changes: 1 addition & 1 deletion example/src/examples/SetDisplacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SetDisplacement extends React.Component {
}

componentWillUnmount() {
MapboxGL.locationManager.dispose();
MapboxGL.locationManager.stop();
}

onDisplacementChange = index => {
Expand Down
2 changes: 1 addition & 1 deletion example/src/examples/SetHeading.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SetHeading extends React.Component {
}

componentWillUnmount() {
MapboxGL.locationManager.dispose();
MapboxGL.locationManager.stop();
}

onHeadingChange(index, heading) {
Expand Down
2 changes: 1 addition & 1 deletion example/src/examples/SetPitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SetPitch extends React.Component {
}

componentWillUnmount() {
MapboxGL.locationManager.dispose();
MapboxGL.locationManager.stop();
}

onUpdatePitch(index, pitch) {
Expand Down
2 changes: 1 addition & 1 deletion example/src/examples/ShowMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ShowMap extends React.Component {
}

componentWillUnmount() {
MapboxGL.locationManager.dispose();
MapboxGL.locationManager.stop();
}

onMapChange(index, styleURL) {
Expand Down
2 changes: 1 addition & 1 deletion javascript/components/UserLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class UserLocation extends React.Component {
});
}
} else if (!running) {
locationManager.dispose();
locationManager.stop();
}
}
};
Expand Down
16 changes: 1 addition & 15 deletions javascript/modules/location/locationManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class LocationManager {
this._listeners = [];
this._lastKnownLocation = null;
this._isListening = false;
this._isPaused = false;
this.onUpdate = this.onUpdate.bind(this);
}

Expand Down Expand Up @@ -45,12 +44,6 @@ class LocationManager {
}

start(displacement = 0) {
if (this._isPaused) {
MapboxGLLocationManager.start(displacement);
this._isPaused = false;
return;
}

if (!this._isListening) {
MapboxGLLocationManager.start(displacement);

Expand All @@ -63,14 +56,7 @@ class LocationManager {
}
}

pause() {
if (!this._isPaused && this._isListening) {
MapboxGLLocationManager.pause();
this._isListening = false;
}
}

dispose() {
stop() {
MapboxGLLocationManager.stop();

if (this._isListening) {
Expand Down

0 comments on commit 77f4247

Please sign in to comment.