@appbaseio/reactivesearch-vue 1.33.9 → 1.33.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -107,6 +107,7 @@ var ReactiveMap = {
107
107
  URLParams: VueTypes.bool,
108
108
  autoCenter: VueTypes.bool,
109
109
  getMapRef: VueTypes.func.isRequired,
110
+ getMapPromise: VueTypes.func,
110
111
  center: types.location,
111
112
  defaultCenter: types.location,
112
113
  defaultPin: types.string,
@@ -174,32 +175,37 @@ var ReactiveMap = {
174
175
  }
175
176
  },
176
177
  defaultQuery: function defaultQuery(newVal, oldVal) {
178
+ var _this = this;
177
179
  if (!isQueryIdentical(newVal, oldVal, null, this.$props)) {
178
- var options = getQueryOptions(this.$props);
179
- options.from = 0;
180
- this.$defaultQuery = newVal(null, this.$props);
181
- var _ref = this.$defaultQuery || {},
182
- sort = _ref.sort,
183
- query = _ref.query;
184
- if (sort) {
185
- options.sort = this.$defaultQuery.sort;
186
- }
187
- var queryOptions = getOptionsFromQuery(this.$defaultQuery);
188
- if (queryOptions) {
189
- options = _extends({}, options, getOptionsFromQuery(this.$defaultQuery));
190
- }
191
- // Update calculated default query in store
192
- this.setQueryOptions(this.$props.componentId, options, false);
193
- var persistMapQuery = true;
194
- var forceExecute = true;
195
- // Update default query to include the geo bounding box query
196
- this.setDefaultQueryForRSAPI();
197
- var meta = {
198
- mapBoxBounds: this.mapBoxBounds
199
- };
200
- this.setMapData(this.componentId, query, persistMapQuery, forceExecute, meta);
201
- this.currentPageState = 0;
202
- this.from = 0;
180
+ this.getMapPromise().then(function () {
181
+ var options = getQueryOptions(_this.$props);
182
+ options.from = 0;
183
+ _this.$defaultQuery = newVal(null, _this.$props);
184
+ // Update default query to include the geo bounding box query
185
+ _this.setDefaultQueryForRSAPI();
186
+ if (_this.$defaultQuery) {
187
+ var _ref = _this.$defaultQuery || {},
188
+ sort = _ref.sort,
189
+ query = _ref.query;
190
+ if (sort) {
191
+ options.sort = _this.$defaultQuery.sort;
192
+ }
193
+ var queryOptions = getOptionsFromQuery(_this.$defaultQuery);
194
+ if (queryOptions) {
195
+ options = _extends({}, options, getOptionsFromQuery(_this.$defaultQuery));
196
+ }
197
+ // Update calculated default query in store
198
+ _this.setQueryOptions(_this.$props.componentId, options, false);
199
+ var persistMapQuery = true;
200
+ var forceExecute = true;
201
+ var meta = {
202
+ mapBoxBounds: _this.mapBoxBounds
203
+ };
204
+ _this.setMapData(_this.componentId, query, persistMapQuery, forceExecute, meta);
205
+ _this.currentPageState = 0;
206
+ _this.from = 0;
207
+ }
208
+ });
203
209
  }
204
210
  },
205
211
  promotedResults: function promotedResults(newVal, oldVal) {
@@ -227,7 +233,7 @@ var ReactiveMap = {
227
233
  }
228
234
  },
229
235
  rawData: function rawData(newVal, oldVal) {
230
- var _this = this;
236
+ var _this2 = this;
231
237
  if (!isEqual(newVal, oldVal)) {
232
238
  var promotedResults = this.promotedResults,
233
239
  hits = this.hits;
@@ -246,10 +252,10 @@ var ReactiveMap = {
246
252
  filteredResults = [].concat(parsedPromotedResults, filteredResults);
247
253
  }
248
254
  filteredResults = filteredResults.filter(function (item) {
249
- return !!item[_this.dataField];
255
+ return !!item[_this2.dataField];
250
256
  }).map(function (item) {
251
257
  var _extends2;
252
- return _extends({}, item, (_extends2 = {}, _extends2[_this.dataField] = getLocationObject(item[_this.dataField]), _extends2));
258
+ return _extends({}, item, (_extends2 = {}, _extends2[_this2.dataField] = getLocationObject(item[_this2.dataField]), _extends2));
253
259
  });
254
260
  this.filteredResults = this.addNoise(filteredResults);
255
261
  if (this.calculateMarkers) {
@@ -294,15 +300,15 @@ var ReactiveMap = {
294
300
  return this.parseLocation(MAP_CENTER);
295
301
  },
296
302
  addNoise: function addNoise(hits) {
297
- var _this2 = this;
303
+ var _this3 = this;
298
304
  var hitMap = {};
299
305
  var updatedHits = [];
300
306
  hits.forEach(function (item) {
301
307
  var updatedItem = _extends({}, item);
302
- var location = _this2.parseLocation(item[_this2.dataField]);
308
+ var location = _this3.parseLocation(item[_this3.dataField]);
303
309
  var key = JSON.stringify(location);
304
310
  var count = hitMap[key] || 0;
305
- updatedItem[_this2.dataField] = count ? withDistinctLat(location, count) : location;
311
+ updatedItem[_this3.dataField] = count ? withDistinctLat(location, count) : location;
306
312
  updatedHits = [].concat(updatedHits, [updatedItem]);
307
313
  hitMap[key] = count + 1;
308
314
  });
@@ -315,9 +321,9 @@ var ReactiveMap = {
315
321
  return null;
316
322
  },
317
323
  getHitsCenter: function getHitsCenter(hits) {
318
- var _this3 = this;
324
+ var _this4 = this;
319
325
  var data = hits.map(function (hit) {
320
- return hit[_this3.dataField];
326
+ return hit[_this4.dataField];
321
327
  });
322
328
  if (data.length) {
323
329
  var numCoords = data.length;
@@ -356,7 +362,7 @@ var ReactiveMap = {
356
362
  return false;
357
363
  },
358
364
  getCenter: function getCenter(hits) {
359
- var _this4 = this;
365
+ var _this5 = this;
360
366
  if (this.center) {
361
367
  return this.parseLocation(this.center);
362
368
  }
@@ -364,7 +370,7 @@ var ReactiveMap = {
364
370
  if (mapRef && typeof mapRef.getCenter === 'function' && this.$options.preserveCenter) {
365
371
  var currentCenter = mapRef.getCenter();
366
372
  setTimeout(function () {
367
- _this4.$options.preserveCenter = false;
373
+ _this5.$options.preserveCenter = false;
368
374
  }, 100);
369
375
  return this.parseLocation({
370
376
  lat: currentCenter.lat(),
@@ -422,12 +428,14 @@ var ReactiveMap = {
422
428
  // or whenever searchAsMove is true and the map is dragged
423
429
  if (executeUpdate || !this.skipBoundingBox && !this.mapBoxBounds) {
424
430
  this.$defaultQuery = this.getGeoQuery();
425
- var persistMapQuery = !!this.center;
426
- var forceExecute = this.searchAsMove;
427
- var meta = {
428
- mapBoxBounds: this.mapBoxBounds
429
- };
430
- this.setMapData(this.componentId, this.$defaultQuery, persistMapQuery, forceExecute, meta);
431
+ if (this.$defaultQuery) {
432
+ var persistMapQuery = !!this.center;
433
+ var forceExecute = this.searchAsMove;
434
+ var meta = {
435
+ mapBoxBounds: this.mapBoxBounds
436
+ };
437
+ this.setMapData(this.componentId, this.$defaultQuery, persistMapQuery, forceExecute, meta);
438
+ }
431
439
  }
432
440
  this.skipBoundingBox = false;
433
441
  },
@@ -701,69 +709,77 @@ var ReactiveMap = {
701
709
  this.updateComponentProps(this.internalComponent, {
702
710
  from: this.from
703
711
  }, componentTypes.reactiveMap);
712
+ this.setDefaultQueryForRSAPI();
704
713
  },
705
714
  mounted: function mounted() {
706
- if (this.defaultPage < 0 && this.currentPage > 0) {
707
- if (this.$props.URLParams) {
708
- this.setPageURL(this.$props.componentId, this.currentPage, this.$props.componentId, false, true);
715
+ var _this6 = this;
716
+ this.getMapPromise().then(function () {
717
+ if (_this6.defaultPage < 0 && _this6.currentPage > 0) {
718
+ if (_this6.$props.URLParams) {
719
+ _this6.setPageURL(_this6.$props.componentId, _this6.currentPage, _this6.$props.componentId, false, true);
720
+ }
709
721
  }
710
- }
711
- var options = getQueryOptions(this.$props);
712
- options.from = this.$data.from;
713
- if (this.$props.sortBy) {
714
- var _ref3;
715
- options.sort = [(_ref3 = {}, _ref3[this.$props.dataField] = {
716
- order: this.$props.sortBy
717
- }, _ref3)];
718
- }
719
- this.$defaultQuery = null;
720
- if (this.$props.defaultQuery) {
721
- this.$defaultQuery = this.$props.defaultQuery() || {};
722
- options = _extends({}, options, getOptionsFromQuery(this.$defaultQuery));
723
-
724
- // Override sort query with defaultQuery's sort if defined
725
- if (this.$defaultQuery.sort) {
726
- options.sort = this.$defaultQuery.sort;
722
+ var options = getQueryOptions(_this6.$props);
723
+ options.from = _this6.$data.from;
724
+ if (_this6.$props.sortBy) {
725
+ var _ref3;
726
+ options.sort = [(_ref3 = {}, _ref3[_this6.$props.dataField] = {
727
+ order: _this6.$props.sortBy
728
+ }, _ref3)];
727
729
  }
728
- // since we want defaultQuery to be executed anytime
729
- // map component's query is being executed
730
- var persistMapQuery = true;
731
- // no need to forceExecute because setReact() will capture the main query
732
- // and execute the defaultQuery along with it
733
- var forceExecute = false;
730
+ _this6.$defaultQuery = null;
731
+ if (_this6.$props.defaultQuery) {
732
+ _this6.$defaultQuery = _this6.$props.defaultQuery();
733
+ // Update default query for RS API
734
+ _this6.setDefaultQueryForRSAPI();
735
+ if (_this6.$defaultQuery) {
736
+ options = _extends({}, options, getOptionsFromQuery(_this6.$defaultQuery));
734
737
 
735
- // Update default query for RS API
736
- this.setDefaultQueryForRSAPI();
737
- var meta = {
738
- mapBoxBounds: this.mapBoxBounds
739
- };
740
- this.setMapData(this.componentId, this.$defaultQuery.query, persistMapQuery, forceExecute, meta);
741
- } else {
742
- // only apply geo-distance when defaultQuery prop is not set
743
- var query = this.getGeoDistanceQuery();
744
- if (query) {
745
- // - only persist the map query if center prop is set
746
- // - ideally, persist the map query if you want to keep executing it
747
- // whenever there is a change (due to subscription) in the component query
748
- var _persistMapQuery = !!this.center;
738
+ // Override sort query with defaultQuery's sort if defined
739
+ if (_this6.$defaultQuery.sort) {
740
+ options.sort = _this6.$defaultQuery.sort;
741
+ }
742
+ // since we want defaultQuery to be executed anytime
743
+ // map component's query is being executed
744
+ var persistMapQuery = true;
745
+ // no need to forceExecute because setReact() will capture the main query
746
+ // and execute the defaultQuery along with it
747
+ var forceExecute = false;
748
+ var meta = {
749
+ mapBoxBounds: _this6.mapBoxBounds
750
+ };
751
+ if (_this6.$defaultQuery) {
752
+ _this6.setMapData(_this6.componentId, _this6.$defaultQuery.query, persistMapQuery, forceExecute, meta);
753
+ _this6.setQueryOptions(_this6.componentId, options);
754
+ }
755
+ }
756
+ } else {
757
+ // only apply geo-distance when defaultQuery prop is not set
758
+ var query = _this6.getGeoDistanceQuery();
759
+ if (query) {
760
+ // - only persist the map query if center prop is set
761
+ // - ideally, persist the map query if you want to keep executing it
762
+ // whenever there is a change (due to subscription) in the component query
763
+ var _persistMapQuery = !!_this6.center;
749
764
 
750
- // - forceExecute will make sure that the component query + Map query gets executed
751
- // irrespective of the changes in the component query
752
- // - forceExecute will only come into play when searchAsMove is true
753
- // - kindly note that forceExecute may result in one additional network request
754
- // since it bypasses the gatekeeping
755
- var _forceExecute = this.searchAsMove;
756
- // Set meta for `distance` and `coordinates` in selected value
757
- var center = this.center || this.defaultCenter;
758
- var coordinatesObject = this.getArrPosition(center);
759
- var _meta = {
760
- distance: this.defaultRadius,
761
- coordinates: coordinatesObject.lat + ", " + coordinatesObject.lon
762
- };
763
- this.setMapData(this.componentId, query, _persistMapQuery, _forceExecute, _meta);
765
+ // - forceExecute will make sure that the component query + Map query gets executed
766
+ // irrespective of the changes in the component query
767
+ // - forceExecute will only come into play when searchAsMove is true
768
+ // - kindly note that forceExecute may result in one additional network request
769
+ // since it bypasses the gatekeeping
770
+ var _forceExecute = _this6.searchAsMove;
771
+ // Set meta for `distance` and `coordinates` in selected value
772
+ var center = _this6.center || _this6.defaultCenter;
773
+ var coordinatesObject = _this6.getArrPosition(center);
774
+ var _meta = {
775
+ distance: _this6.defaultRadius,
776
+ coordinates: coordinatesObject.lat + ", " + coordinatesObject.lon
777
+ };
778
+ _this6.setMapData(_this6.componentId, query, _persistMapQuery, _forceExecute, _meta);
779
+ }
780
+ _this6.setQueryOptions(_this6.componentId, options);
764
781
  }
765
- }
766
- this.setQueryOptions(this.componentId, options, !(this.$defaultQuery && this.$defaultQuery.query));
782
+ });
767
783
  },
768
784
  render: function render() {
769
785
  var h = arguments[0];
@@ -2019,9 +2035,18 @@ var ReactiveGoogleMap = {
2019
2035
  calculateMarkers: VueTypes.func,
2020
2036
  highlightMarkerOnHover: VueTypes.bool.def(true)
2021
2037
  },
2038
+ created: function created() {
2039
+ var _this = this;
2040
+ this.mapRefPromiseResolve = null;
2041
+ this.mapRefPromiseRejecter = null;
2042
+ this.mapRefPromise = new Promise(function (resolve, reject) {
2043
+ _this.mapRefPromiseResolver = resolve;
2044
+ _this.mapRefPromiseRejecter = reject;
2045
+ });
2046
+ },
2022
2047
  methods: {
2023
2048
  renderMap: function renderMap(_ref) {
2024
- var _this = this;
2049
+ var _this2 = this;
2025
2050
  var resultsToRender = _ref.resultsToRender,
2026
2051
  center = _ref.center,
2027
2052
  zoom = _ref.zoom,
@@ -2070,7 +2095,7 @@ var ReactiveGoogleMap = {
2070
2095
  "highlightMarkerOnHover": this.highlightMarkerOnHover,
2071
2096
  "renderItem": this.$scopedSlots.renderItem ? function () {
2072
2097
  return {
2073
- custom: _this.$scopedSlots.renderItem
2098
+ custom: _this2.$scopedSlots.renderItem
2074
2099
  };
2075
2100
  } : this.renderItem,
2076
2101
  "defaultPin": defaultPin,
@@ -2085,6 +2110,9 @@ var ReactiveGoogleMap = {
2085
2110
  getMapRef: function getMapRef() {
2086
2111
  return this.mapRef;
2087
2112
  },
2113
+ getMapRefPromise: function getMapRefPromise() {
2114
+ return this.mapRefPromise;
2115
+ },
2088
2116
  removeMarkers: function removeMarkers() {
2089
2117
  var clusterManagerInstance;
2090
2118
  var currentInstance = this;
@@ -2105,11 +2133,12 @@ var ReactiveGoogleMap = {
2105
2133
  }
2106
2134
  },
2107
2135
  mounted: function mounted() {
2108
- var _this2 = this;
2136
+ var _this3 = this;
2109
2137
  if (this.$refs.mapRef) {
2110
2138
  this.$refs.mapRef.$mapPromise.then(function (map) {
2111
- _this2.mapRef = map;
2112
- });
2139
+ _this3.mapRef = map;
2140
+ _this3.mapRefPromiseResolver(_this3.mapRef);
2141
+ })["catch"](this.mapRefPromiseRejecter);
2113
2142
  }
2114
2143
  },
2115
2144
  render: function render() {
@@ -2117,6 +2146,7 @@ var ReactiveGoogleMap = {
2117
2146
  return h(RMConnected, _mergeJSXProps([{
2118
2147
  "attrs": {
2119
2148
  "getMapRef": this.getMapRef,
2149
+ "getMapPromise": this.getMapRefPromise,
2120
2150
  "renderMap": this.renderMap,
2121
2151
  "componentId": this.componentId,
2122
2152
  "className": this.className,