Selaa lähdekoodia

use a vuex plugin to persist store in localStorage

pull/342/head
Guillaume Vincent 7 vuotta sitten
vanhempi
commit
9ab7784a2a
3 muutettua tiedostoa jossa 22 lisäystä ja 22 poistoa
  1. +2
    -1
      package.json
  2. +3
    -6
      src/store/actions.js
  3. +17
    -15
      src/store/index.js

+ 2
- 1
package.json Näytä tiedosto

@@ -32,7 +32,8 @@
"lodash.debounce": "^4.0.8",
"vue": "^2.1.10",
"vue-router": "^2.2.0",
"vuex": "^2.1.1"
"vuex": "^2.1.1",
"vuex-persistedstate": "^1.1.0"
},
"devDependencies": {
"ava": "^0.17.0",


+ 3
- 6
src/store/actions.js Näytä tiedosto

@@ -8,27 +8,24 @@ const storage = new Storage();
const auth = new Auth(storage);
const Passwords = new HTTP('passwords', storage);

export const loadLocalStorage = ({state}) => {
Object.assign({}, state, storage.json())
export const loadPasswordFirstTime = ({commit}) => {
commit(types.LOAD_PASSWORD_FIRST_TIME);
};

export const saveDefaultPassword = ({commit}, payload) => {
storage.save(payload);
commit(types.SET_DEFAULT_PASSWORD, payload);
};

export const savePassword = ({commit}, payload) => {
storage.save(payload);
commit(types.SET_PASSWORD, payload);
};

export const saveBaseURL = ({commit}, payload) => {
storage.save(payload);
commit(types.SET_BASE_URL, payload);
};

export const saveVersion = ({commit}, payload) => {
commit(types.SET_BASE_URL, payload);
commit(types.SET_VERSION, payload);
};

export const login = ({commit}) => {


+ 17
- 15
src/store/index.js Näytä tiedosto

@@ -3,33 +3,35 @@ import Vuex from 'vuex'
import * as actions from './actions'
import * as getters from './getters'
import mutations from './mutations'
import createPersistedState from 'vuex-persistedstate';

Vue.use(Vuex);

const defaultPassword = {
login: '',
site: '',
uppercase: true,
lowercase: true,
numbers: true,
symbols: true,
length: 16,
counter: 1,
version: 2
};

const state = {
authenticated: false,
password: null,
password: defaultPassword,
passwords: [],
defaultPassword: {
login: '',
site: '',
uppercase: true,
lowercase: true,
numbers: true,
symbols: true,
length: 16,
counter: 1,
version: 2
},
lastUse: new Date().getTime(),
defaultPassword: defaultPassword,
lastUse: null,
baseURL: 'https://lesspass.com',
};

actions.loadLocalStorage({state});

export default new Vuex.Store({
state,
getters,
actions,
mutations,
plugins: [createPersistedState({key: 'lesspass'})]
});

Ladataan…
Peruuta
Tallenna