context.js
1 const state = [] 2 3 const mutations = { 4 goGo(state, x){ 5 state.length = 0 6 x.forEach(y => state.push(y)) 7 window.scrollTo(0, 0); 8 }, 9 goDeeper(state, target){ 10 let targetIndex = state.indexOf(target) 11 if (targetIndex === -1){ 12 state.push(target) 13 } else if (targetIndex !== state.length - 1){ 14 let swapy = state[state.length - 1] 15 state[state.length - 1] = target 16 state[targetIndex] = swapy 17 } 18 window.scrollTo(0, 0); 19 }, 20 goHigher(state, tId){ 21 let popped = false 22 let i = 0 23 popped, i 24 while(state[state.length - 1] !== tId && state.length !== 1) { 25 popped = state.pop() 26 i ++ 27 } 28 }, 29 addParent(state, tId){ 30 let p = state.pop() 31 state.push(tId) 32 state.push(p) 33 }, 34 applyEvent(state, ev){ 35 if (ev.type === 'task-removed' && ev.taskId === state[state.length - 1]){ 36 state.pop() 37 } 38 if (ev.type === 'member-purged' && ev.memberId === state[state.length - 1]){ 39 state.pop() 40 } 41 if (state.length === 0){ 42 state.push(ev.blame) 43 } 44 } 45 } 46 47 const actions = {} 48 49 const getters = {} 50 51 export default { 52 state, 53 mutations, 54 actions, 55 getters, 56 }