Apply store pattern to track global app state
[vchess.git] / client / src / main.js
1 import Vue from "vue";
2 import App from "./App.vue";
3 import router from "./router";
4 // Global store: see https://medium.com/fullstackio/managing-state-in-vue-js-23a0352b1c87
5 import { store } from "./store";
6
7 Vue.config.productionTip = false;
8
9 new Vue({
10 router,
11 render: function(h) {
12 return h(App);
13 },
14 // watch: {
15 // $route: function(newRoute) {
16 // //console.log(this.$route.params);
17 // console.log("navig to " + newRoute);
18 // //TODO: conn.send("enter", newRoute)
19 // },
20 // },
21 created: function() {
22 window.doClick = (elemId) => { document.getElementById(elemId).click() };
23
24 //TODO: si une partie en cours dans storage, rediriger vers cette partie
25 //(à condition que l'URL n'y corresponde pas déjà !)
26 // TODO: à l'arrivée sur le site : set peerID (un identifiant unique
27 // en tout cas...) si pas trouvé dans localStorage "myid"
28 // (l'identifiant de l'utilisateur si connecté)
29 // if (!!localStorage["variant"])
30 // location.hash = "#game?id=" + localStorage["gameId"];
31 },
32 // Later, for icons (if using feather):
33 // mounted: function() {
34 // feather.replace();
35 // },
36 mounted: function() {
37 store.initialize();
38 },
39 }).$mount("#app");
40
41 // TODO: get rules, dynamic import
42 // Load a rules page (AJAX)
43 // router.get("/rules/:vname([a-zA-Z0-9]+)", access.ajax, (req,res) => {
44 // const lang = selectLanguage(req, res);
45 // res.render("rules/" + req.params["vname"] + "/" + lang);
46 // });
47 //
48 // board2, 3, 4 automatiquement, mais rules separement (les 3 pour une)
49 // game : aussi systématique
50 // problems: on-demand
51 //
52 // See https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes
53 // created: function() {
54 // window.onhashchange = this.setDisplay;
55 // },
56 //});