diff --git a/package-lock.json b/package-lock.json index 1aad114..1524b08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3087,6 +3087,11 @@ "integrity": "sha512-gCubfBUZ6KxzoibJ+SCUc/57Ms1jz5NjHe4+dI2krNmU5zCPAphyLJYyTOg06ueIyfj+SaCUqmzun7ImlxDcKg==", "dev": true }, + "@urbn/vuex-helpers": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@urbn/vuex-helpers/-/vuex-helpers-0.1.0.tgz", + "integrity": "sha512-9yPAWnCA8JHNrebU/dh0/Zz/6ojZc+xL25eNjIhDuuR4TgRLOLpAeY3+JH3WkF3DfebD/F5FQ6qBHmA76rXjHw==" + }, "@vue/component-compiler-utils": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/@vue/component-compiler-utils/-/component-compiler-utils-3.1.2.tgz", diff --git a/package.json b/package.json index a7a7c9b..dde853e 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "license": "MIT", "dependencies": { "@tweenjs/tween.js": "^18.6.0", + "@urbn/vuex-helpers": "^0.1.0", "axios": "^0.18.1", "dat.gui": "^0.7.7", "oimo": "^1.0.9", diff --git a/src/App.vue b/src/App.vue index 53406cd..9997276 100644 --- a/src/App.vue +++ b/src/App.vue @@ -40,7 +40,8 @@ diff --git a/src/components/objects/Project.vue b/src/components/objects/Project.vue index 00dec08..17e31c3 100644 --- a/src/components/objects/Project.vue +++ b/src/components/objects/Project.vue @@ -1,9 +1,9 @@ diff --git a/src/store/modules/project.js b/src/store/modules/project.js new file mode 100644 index 0000000..fc14883 --- /dev/null +++ b/src/store/modules/project.js @@ -0,0 +1,25 @@ +// https://codeburst.io/dynamic-modules-with-vuex-and-vue-b9c481ca792 +// https://www.brophy.org/post/instance-aware-vuex-modules-1/ + +// import qs from 'querystring' +// import { REST } from 'api/rest-axios' + +export default { + namespaced: true, + + // initial state + state: { + }, + + // getters + getters: { + }, + + // mutations + mutations: { + }, + + // actions + actions: { + } +} diff --git a/src/store/modules/projects.js b/src/store/modules/projects.js index fe7a77f..33002c4 100644 --- a/src/store/modules/projects.js +++ b/src/store/modules/projects.js @@ -1,6 +1,7 @@ // import qs from 'querystring' // import { REST } from 'api/rest-axios' import { GRAPHQL } from 'api/graphql-axios' +import projectMod from 'store/modules/project' export default { namespaced: true, @@ -24,6 +25,19 @@ export default { setProjects (state, projects) { // record the retrieved data state.projects = projects + console.log('setProjects', this) + // register a new module only if doesn't exist + let name + projects.forEach((project, i) => { + name = `project:${project.id}` + if (!(this.state && this.state[name])) { + projectMod.state = { ...project } + this.registerModule(name, projectMod) + } else { + // re-use the already existing module + console.log(`reusing module poject:${project.id}`) + } + }) // randomly define building sizes let totalW = 0 @@ -126,16 +140,16 @@ export default { // async get authors getProjects ({ dispatch, commit, state }) { // GRAPHQL - let query = `query { - projects { - id - Weight - Titre - } - }` - GRAPHQL.post('', { query: query }) - .then((resp) => { - console.log('graphql projects', resp) + GRAPHQL.post('', { query: `query { + projects { + id + Weight + Titre + } + }` }) + .then(({ data: { data: { projects } = null } }) => { + console.log('graphql projects', projects) + commit('setProjects', projects) }) .catch((error) => { console.warn('Issue with getProjects', error)