-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstate.js
62 lines (53 loc) · 1.5 KB
/
state.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { HookRouter } from '~/utils/reactive.js';
import { reactive } from 'vue'
import { toRaw } from 'vue';
import { useRouter } from 'vue-router';
globalThis.getRawState = () => toRaw(getState());
let State = {
/** @type {Array<ReturnType<typeof Attraction>>} */
attractions: [],
_minRatingsCount: 10,
activeView: 'map',
showItinerary: false,
_sortOrder: 'distance',
_homeLocation:undefined,
_title: '',
_minStars: 4.5,
showModal: false,
markers: [],
autocomplete: null,
_selectedAttractions: [] ,
/** @type {'attraction' | 'food'} */
_placeType: 'attraction',
};
/** @param {google.maps.places.PlaceResult} details */
export const Attraction = (details,{distance,type}) => {
return {
id: details.place_id,
name: details.name,
rating: details.rating,
user_ratings_total: details.user_ratings_total,
address: details.vicinity,
reviews: details.reviews,
photos: details.photos,
location: details.geometry.location,
get inItinerary() {
return getState()._selectedAttractions.includes(this.id);
},
distance: distance,
type: type
}
}
/**
* @returns {State}
*/
export const getState = () => {
if (!globalThis.state) {
State = globalThis.state = reactive(State)
let router = useRouter();
nextTick(() => { //wait for watch initialized
HookRouter(State, router);
});
}
return globalThis.state;
}