summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/releases/mount_index.js
blob: 59f6ebfc928ee4237401bbbaaa762eaf0724aff7 (plain)
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
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import Vuex from 'vuex';
import createDefaultClient from '~/lib/graphql';
import ReleaseIndexApp from './components/app_index.vue';
import ReleaseIndexApollopClientApp from './components/app_index_apollo_client.vue';
import createStore from './stores';
import createIndexModule from './stores/modules/index';

export default () => {
  const el = document.getElementById('js-releases-page');

  if (window.gon?.features?.releasesIndexApolloClient) {
    Vue.use(VueApollo);

    const apolloProvider = new VueApollo({
      defaultClient: createDefaultClient(
        {},
        {
          // This page attempts to decrease the perceived loading time
          // by sending two requests: one request for the first item only (which
          // completes relatively quickly), and one for all the items (which is slower).
          // By default, Apollo Client batches these requests together, which defeats
          // the purpose of making separate requests. So we explicitly
          // disable batching on this page.
          batchMax: 1,
          assumeImmutableResults: true,
        },
      ),
    });

    return new Vue({
      el,
      apolloProvider,
      provide: { ...el.dataset },
      render: (h) => h(ReleaseIndexApollopClientApp),
    });
  }

  Vue.use(Vuex);

  return new Vue({
    el,
    store: createStore({
      modules: {
        index: createIndexModule(el.dataset),
      },
    }),
    render: (h) => h(ReleaseIndexApp),
  });
};