summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/snippets/index.js
blob: bb5e7d6e3f0a31dae5c9263d927cd203be818486 (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
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import Translate from '~/vue_shared/translate';
import createDefaultClient from '~/lib/graphql';

import SnippetsShow from './components/show.vue';
import SnippetsEdit from './components/edit.vue';

Vue.use(VueApollo);
Vue.use(Translate);

function appFactory(el, Component) {
  if (!el) {
    return false;
  }

  const apolloProvider = new VueApollo({
    defaultClient: createDefaultClient(),
  });

  return new Vue({
    el,
    apolloProvider,
    render(createElement) {
      return createElement(Component, {
        props: {
          ...el.dataset,
        },
      });
    },
  });
}

export const SnippetShowInit = () => {
  appFactory(document.getElementById('js-snippet-view'), SnippetsShow);
};

export const SnippetEditInit = () => {
  appFactory(document.getElementById('js-snippet-edit'), SnippetsEdit);
};