Skip to content

Commit

Permalink
fix: fix onLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
stepankuzmin committed Oct 18, 2017
1 parent da5d660 commit aa4509e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
"styleguide": "styleguidist server",
"styleguide:build": "styleguidist build",
"styleguide:deploy": "gh-pages -d styleguide",
"commit": "npm run build && git-cz",
"commit": "git-cz",
"release": "standard-version",
"postpublish": "npm run docs && npm run styleguide:build && npm run styleguide:deploy"
},
"jest": {
"setupFiles": [
"<rootDir>/test/setup.js"
]
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
Expand Down
13 changes: 10 additions & 3 deletions src/components/MapGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ type Props = {
* map. The object passed to the callback contains viewport properties
* such as `longitude`, `latitude`, `zoom` etc.
*/
onViewportChange: (viewport: Viewport) => void
onViewportChange: (viewport: Viewport) => void,

/** The onLoad callback for the map */
onLoad: Function
};

type State = {
Expand All @@ -65,7 +68,9 @@ class MapGL extends PureComponent<Props, State> {
accessToken: null,
preserveDrawingBuffer: false,
bearing: 0,
pitch: 0
pitch: 0,
onViewportChange: null,
onLoad: null
};

constructor(props: Props) {
Expand Down Expand Up @@ -102,7 +107,9 @@ class MapGL extends PureComponent<Props, State> {
preserveDrawingBuffer: this.props.preserveDrawingBuffer
});

map.once('load', () => this.setState({ loaded: true }));
map.once('load', () => {
this.setState({ loaded: true }, this.props.onLoad);
});

if (this.props.onViewportChange) {
map.on('dragend', this._onViewportChange);
Expand Down
4 changes: 2 additions & 2 deletions test/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import MapGL from '../src';
Enzyme.configure({ adapter: new Adapter() });

const mockOn = jest.fn();
const mockOnce = jest.fn();
const mockOnce = jest.fn((_, fn) => fn());
const mockFlyTo = jest.fn();
const mockGetCanvas = jest.fn();
const mockGetCenter = jest.fn(() => ({ lat: 0, lng: 0 }));
Expand Down Expand Up @@ -37,5 +37,5 @@ test('MapGL#render', () => {
test('MapGL#onLoad', () => {
const onLoad = jest.fn();
mount(<MapGL latitude={0} longitude={0} zoom={0} onLoad={onLoad} />);
expect(mockOnce).toHaveBeenCalledWith('load', onLoad);
expect(onLoad).toHaveBeenCalled();
});
3 changes: 3 additions & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global.requestAnimationFrame = function requestAnimationFrame(callback) {
setTimeout(callback, 0);
};

0 comments on commit aa4509e

Please sign in to comment.