mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-27 01:02:14 +05:30
Decouple pure and private accounts actions from async actions.
This commit is contained in:
parent
bf1cfda59c
commit
acf912d979
@ -5,6 +5,16 @@ import { updateUser, setGuest } from 'components/user/actions';
|
||||
import { setLocale } from 'components/i18n/actions';
|
||||
import logger from 'services/logger';
|
||||
|
||||
import {
|
||||
add,
|
||||
remove,
|
||||
activate,
|
||||
reset,
|
||||
updateToken
|
||||
} from 'components/accounts/actions/pure-actions';
|
||||
|
||||
export { updateToken };
|
||||
|
||||
/**
|
||||
* @typedef {object} Account
|
||||
* @property {string} id
|
||||
@ -64,6 +74,8 @@ export function authenticate({token, refreshToken}) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove one account from current user's account list
|
||||
*
|
||||
* @param {Account} account
|
||||
*
|
||||
* @return {function}
|
||||
@ -135,73 +147,3 @@ export function logoutStrangers() {
|
||||
return Promise.resolve();
|
||||
};
|
||||
}
|
||||
|
||||
export const ADD = 'accounts:add';
|
||||
/**
|
||||
* @api private
|
||||
*
|
||||
* @param {Account} account
|
||||
*
|
||||
* @return {object} - action definition
|
||||
*/
|
||||
export function add(account) {
|
||||
return {
|
||||
type: ADD,
|
||||
payload: account
|
||||
};
|
||||
}
|
||||
|
||||
export const REMOVE = 'accounts:remove';
|
||||
/**
|
||||
* @api private
|
||||
*
|
||||
* @param {Account} account
|
||||
*
|
||||
* @return {object} - action definition
|
||||
*/
|
||||
export function remove(account) {
|
||||
return {
|
||||
type: REMOVE,
|
||||
payload: account
|
||||
};
|
||||
}
|
||||
|
||||
export const ACTIVATE = 'accounts:activate';
|
||||
/**
|
||||
* @api private
|
||||
*
|
||||
* @param {Account} account
|
||||
*
|
||||
* @return {object} - action definition
|
||||
*/
|
||||
export function activate(account) {
|
||||
return {
|
||||
type: ACTIVATE,
|
||||
payload: account
|
||||
};
|
||||
}
|
||||
|
||||
export const RESET = 'accounts:reset';
|
||||
/**
|
||||
* @api private
|
||||
*
|
||||
* @return {object} - action definition
|
||||
*/
|
||||
export function reset() {
|
||||
return {
|
||||
type: RESET
|
||||
};
|
||||
}
|
||||
|
||||
export const UPDATE_TOKEN = 'accounts:updateToken';
|
||||
/**
|
||||
* @param {string} token
|
||||
*
|
||||
* @return {object} - action definition
|
||||
*/
|
||||
export function updateToken(token) {
|
||||
return {
|
||||
type: UPDATE_TOKEN,
|
||||
payload: token
|
||||
};
|
||||
}
|
||||
|
69
src/components/accounts/actions/pure-actions.js
Normal file
69
src/components/accounts/actions/pure-actions.js
Normal file
@ -0,0 +1,69 @@
|
||||
export const ADD = 'accounts:add';
|
||||
/**
|
||||
* @api private
|
||||
*
|
||||
* @param {Account} account
|
||||
*
|
||||
* @return {object} - action definition
|
||||
*/
|
||||
export function add(account) {
|
||||
return {
|
||||
type: ADD,
|
||||
payload: account
|
||||
};
|
||||
}
|
||||
|
||||
export const REMOVE = 'accounts:remove';
|
||||
/**
|
||||
* @api private
|
||||
*
|
||||
* @param {Account} account
|
||||
*
|
||||
* @return {object} - action definition
|
||||
*/
|
||||
export function remove(account) {
|
||||
return {
|
||||
type: REMOVE,
|
||||
payload: account
|
||||
};
|
||||
}
|
||||
|
||||
export const ACTIVATE = 'accounts:activate';
|
||||
/**
|
||||
* @api private
|
||||
*
|
||||
* @param {Account} account
|
||||
*
|
||||
* @return {object} - action definition
|
||||
*/
|
||||
export function activate(account) {
|
||||
return {
|
||||
type: ACTIVATE,
|
||||
payload: account
|
||||
};
|
||||
}
|
||||
|
||||
export const RESET = 'accounts:reset';
|
||||
/**
|
||||
* @api private
|
||||
*
|
||||
* @return {object} - action definition
|
||||
*/
|
||||
export function reset() {
|
||||
return {
|
||||
type: RESET
|
||||
};
|
||||
}
|
||||
|
||||
export const UPDATE_TOKEN = 'accounts:updateToken';
|
||||
/**
|
||||
* @param {string} token
|
||||
*
|
||||
* @return {object} - action definition
|
||||
*/
|
||||
export function updateToken(token) {
|
||||
return {
|
||||
type: UPDATE_TOKEN,
|
||||
payload: token
|
||||
};
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { ADD, REMOVE, ACTIVATE, RESET, UPDATE_TOKEN } from './actions';
|
||||
import { ADD, REMOVE, ACTIVATE, RESET, UPDATE_TOKEN } from './actions/pure-actions';
|
||||
|
||||
/**
|
||||
* @typedef {AccountsState}
|
||||
|
@ -3,18 +3,19 @@ import sinon from 'sinon';
|
||||
|
||||
import { routeActions } from 'react-router-redux';
|
||||
|
||||
import accounts from 'services/api/accounts';
|
||||
import authentication from 'services/api/authentication';
|
||||
import {
|
||||
authenticate,
|
||||
revoke,
|
||||
add, ADD,
|
||||
activate, ACTIVATE,
|
||||
remove,
|
||||
reset,
|
||||
logoutAll,
|
||||
logoutStrangers
|
||||
} from 'components/accounts/actions';
|
||||
import {
|
||||
add, ADD,
|
||||
activate, ACTIVATE,
|
||||
remove,
|
||||
reset
|
||||
} from 'components/accounts/actions/pure-actions';
|
||||
import { SET_LOCALE } from 'components/i18n/actions';
|
||||
|
||||
import { updateUser, setUser } from 'components/user/actions';
|
||||
|
@ -2,9 +2,12 @@ import expect from 'unexpected';
|
||||
|
||||
import accounts from 'components/accounts/reducer';
|
||||
import {
|
||||
updateToken, add, remove, activate, reset,
|
||||
ADD, REMOVE, ACTIVATE, UPDATE_TOKEN, RESET
|
||||
updateToken
|
||||
} from 'components/accounts/actions';
|
||||
import {
|
||||
add, remove, activate, reset,
|
||||
ADD, REMOVE, ACTIVATE, UPDATE_TOKEN, RESET
|
||||
} from 'components/accounts/actions/pure-actions';
|
||||
|
||||
const account = {
|
||||
id: 1,
|
||||
|
Loading…
Reference in New Issue
Block a user