Explorar el Código

refactor mutations

pull/342/head
Guillaume Vincent hace 7 años
padre
commit
fb52b9b271
Se han modificado 4 ficheros con 28 adiciones y 24 borrados
  1. +5
    -0
      src/store/actions.js
  2. +4
    -0
      src/store/mutation-types.js
  3. +6
    -5
      src/store/mutations.js
  4. +13
    -19
      test/store.js

+ 5
- 0
src/store/actions.js Ver fichero

@@ -0,0 +1,5 @@
import * as types from './mutation-types'

export const saveDefaultOptions = ({commit}, payload) => {
commit(types.SET_DEFAULT_OPTIONS, payload);
};

+ 4
- 0
src/store/mutation-types.js Ver fichero

@@ -0,0 +1,4 @@
export const LOGOUT = 'LOGOUT';
export const LOGIN = 'LOGIN';
export const SET_CURRENT_PASSWORD = 'SET_CURRENT_PASSWORD';
export const SET_DEFAULT_OPTIONS = 'SET_DEFAULT_OPTIONS';

+ 6
- 5
src/store/mutations.js Ver fichero

@@ -1,20 +1,21 @@
import {set} from 'vue';
import * as types from './mutation-types';

function setState(state, id, object) {
set(state, id, Object.assign({}, object));
}

export const mutations = {
LOGIN(state){
[types.LOGIN](state){
state.authenticated = true;
},
LOGOUT(state){
[types.LOGOUT](state){
state.authenticated = false;
},
SET_CURRENT_PASSWORD_PROFILE(state, passwordProfile){
setState(state, 'currentPasswordProfile', passwordProfile);
[types.SET_CURRENT_PASSWORD](state, {password}){
setState(state, 'currentPassword', password);
},
SET_DEFAULT_OPTIONS(state, options){
[types.SET_DEFAULT_OPTIONS](state, {options}){
setState(state, 'defaultOptions', options);
}
};

+ 13
- 19
test/store.js Ver fichero

@@ -15,24 +15,21 @@ test('LOGIN', t => {
t.true(state.authenticated);
});

test('SET_CURRENT_PASSWORD_PROFILE', t => {
const {SET_CURRENT_PASSWORD_PROFILE} = mutations;
const state = {currentPasswordProfile: null};
SET_CURRENT_PASSWORD_PROFILE(state, {
uppercase: true,
version: 2
});
t.is(state.currentPasswordProfile.version, 2);
t.true(state.currentPasswordProfile.uppercase);
test('SET_CURRENT_PASSWORD', t => {
const {SET_CURRENT_PASSWORD} = mutations;
const state = {currentPassword: null};
SET_CURRENT_PASSWORD(state, {password: {uppercase: true, version: 2}});
t.is(state.currentPassword.version, 2);
t.true(state.currentPassword.uppercase);
});

test('SET_CURRENT_PASSWORD_PROFILE immutable', t => {
const {SET_CURRENT_PASSWORD_PROFILE} = mutations;
test('SET_CURRENT_PASSWORD immutable', t => {
const {SET_CURRENT_PASSWORD} = mutations;
const state = {};
const profile = {version: 2};
SET_CURRENT_PASSWORD_PROFILE(state, profile);
profile.version = 1;
t.is(state.currentPasswordProfile.version, 2);
const password = {version: 2};
SET_CURRENT_PASSWORD(state, {password});
password.version = 1;
t.is(state.currentPassword.version, 2);
});

test('SET_DEFAULT_OPTIONS', t => {
@@ -48,10 +45,7 @@ test('SET_DEFAULT_OPTIONS', t => {
version: 2
}
};
SET_DEFAULT_OPTIONS(state, {
symbols: false,
length: 30
});
SET_DEFAULT_OPTIONS(state, {options: {symbols: false, length: 30}});
t.is(state.defaultOptions.length, 30);
t.false(state.defaultOptions.symbols);
});

Cargando…
Cancelar
Guardar