Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
feat(config): store is configured client- server-side
Browse files Browse the repository at this point in the history
  • Loading branch information
vhf committed Oct 28, 2019
1 parent 8097185 commit b877a62
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 28 deletions.
3 changes: 2 additions & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ module.exports = async () => {

/*
** Plugins to load before mounting the App
* Order matters!
*/
plugins: [
'@/plugins/libs/rdf',
'@/plugins/libs/proposals',
'@/plugins/models/Class',
'@/plugins/models/Property',
'@/plugins/libs/proposals',
'@/plugins/filters',
'@/plugins/directives',
'@/plugins/nuxt-init.client',
Expand Down
5 changes: 4 additions & 1 deletion pages/proposal/class.vue
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ export default {
}
return this.iri
},
...classGetters(['success', 'error', 'serialized'])
serialized () {
return this.$proposalSerializer(this.clss)
},
...classGetters(['success', 'error'])
},
watch: {
success () {
Expand Down
5 changes: 4 additions & 1 deletion pages/proposal/property.vue
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ export default {
}
return this.iri
},
...propertyGetters(['success', 'error', 'serialized'])
serialized () {
return this.$proposalSerializer(this.prop)
},
...propertyGetters(['success', 'error'])
},
watch: {
success () {
Expand Down
4 changes: 3 additions & 1 deletion plugins/models/Class.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import rdf from 'rdf-ext'
import QuadExt from 'rdf-ext/lib/Quad'
import Resource from './Resource'
import { firstVal, datasetToCanonicalN3 } from '@/libs/utils'
import { firstVal, datasetToCanonicalN3, normalizeLabel } from '@/libs/utils'

export default ({ app, store }, inject) => {
class Class extends Resource {
Expand All @@ -10,13 +10,15 @@ export default ({ app, store }, inject) => {

const {
baseIRI = store.state.config.ontology.classBaseUrl,
iri = '',
// properties newly added to this Class
propChildren = [] // Array<Quad|Property>
} = args

this.proposalType = 'Class'

this.baseIRI = baseIRI
this.iri = iri || this.baseIRI + normalizeLabel(this.label, 'camel')

this.propChildren = propChildren
}
Expand Down
4 changes: 3 additions & 1 deletion plugins/models/Property.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import rdf from 'rdf-ext'
import QuadExt from 'rdf-ext/lib/Quad'
import Resource from './Resource'
import { firstVal, datasetToCanonicalN3 } from '@/libs/utils'
import { firstVal, datasetToCanonicalN3, normalizeLabel } from '@/libs/utils'

export default ({ app, store }, inject) => {
class Property extends Resource {
Expand All @@ -10,6 +10,7 @@ export default ({ app, store }, inject) => {

const {
baseIRI = store.state.config.ontology.propertyBaseUrl,
iri = '',
ranges = [],
// ranges removed from this Property, only used when editing a Property
rangesRemoved = [], // Array<string iri>
Expand All @@ -20,6 +21,7 @@ export default ({ app, store }, inject) => {
this.proposalType = 'Property'

this.baseIRI = baseIRI
this.iri = iri || this.baseIRI + normalizeLabel(this.label, 'camel')

this.ranges = ranges
this.rangesRemoved = rangesRemoved
Expand Down
4 changes: 0 additions & 4 deletions plugins/models/Resource.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { normalizeLabel } from '@/libs/utils'

export default class Resource {
constructor ({
motivation = '',
threadId = null,
iri = '',
// when editing a Resource, originalIRI is the IRI that this.iri will replace
originalIRI = '',
label = '',
Expand Down Expand Up @@ -33,7 +30,6 @@ export default class Resource {

this.threadId = threadId

this.iri = iri || this.baseIRI + normalizeLabel(label, 'camel')
this.originalIRI = originalIRI

this.label = label
Expand Down
23 changes: 14 additions & 9 deletions store/class.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import * as VueDeepSet from 'vue-deepset'
import _get from 'lodash/get'
import gql from 'graphql-tag'
import rdf from 'rdf-ext'

import proposalById from '@/apollo/queries/proposalById'

import { SAVE, SUBMIT, NEW, LOAD } from '@/store/action-types'
import { SET_ID, ERROR, SUCCESS } from '@/store/mutation-types'

export function state () {
return {
clss: {},
error: false,
success: false
}
}
export const state = () => ({
clss: null,
error: false,
success: false
})

export const getters = {
error: (state) => state.error,
success: (state) => state.success,
dataset: (state) => state.clss.proposalDataset(false),
serialized: (state) => this.$proposalSerializer(state.clss)
dataset: (state) => {
if (state.clss) {
if (typeof state.clss.proposalDataset === 'function') {
return state.clss.proposalDataset(false)
}
}
return rdf.dataset()
}
}

export const mutations = VueDeepSet.extendMutation({
Expand Down
6 changes: 5 additions & 1 deletion store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const actions = {
// b. why it will be broken client-side: data will be (de)serialized to/from JSON for the client
async nuxtServerInit ({ commit, dispatch }, { req, res }) {
await dispatch('config/LOAD_CONFIG')
commit('class/NEW')
commit('prop/NEW')

if (req && req.ontology) {
commit('graph/ontologyInit', req.ontology)
Expand All @@ -27,7 +29,9 @@ export const actions = {
commit('graph/structureInit', req.structure)
}
},
async nuxtClientInit ({ dispatch }, context) {
async nuxtClientInit ({ commit, dispatch }, context) {
commit('class/NEW')
commit('prop/NEW')
await dispatch('graph/DESERIALIZE')
}
}
23 changes: 14 additions & 9 deletions store/prop.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import * as VueDeepSet from 'vue-deepset'
import _get from 'lodash/get'
import gql from 'graphql-tag'
import rdf from 'rdf-ext'

import proposalById from '@/apollo/queries/proposalById'

import { SAVE, SUBMIT, NEW, LOAD } from '@/store/action-types'
import { SET_ID, ERROR, SUCCESS } from '@/store/mutation-types'

export function state () {
return {
prop: {},
error: false,
success: false
}
}
export const state = () => ({
prop: null,
error: false,
success: false
})

export const getters = {
dataset: (state) => state.prop.proposalDataset(false),
error: (state) => state.error,
success: (state) => state.success,
serialized: (state) => this.$proposalSerializer(state.prop)
dataset: (state) => {
if (state.prop) {
if (typeof state.prop.proposalDataset === 'function') {
return state.prop.proposalDataset(false)
}
}
return rdf.dataset()
}
}

export const mutations = VueDeepSet.extendMutation({
Expand Down

0 comments on commit b877a62

Please sign in to comment.