@td-design/react-native
Version:
react-native UI组件库
59 lines • 1.74 kB
JavaScript
import { fillOtpCode } from './helpers';
const ACTION_TYPES = {
setOtpTextForIndex: 'setOtpTextForIndex',
setOtpCode: 'setOtpCode',
clearOtp: 'clearOtp',
setHasKeySupport: 'setHasKeySupport'
};
export default ((state, _ref) => {
let {
type,
payload
} = _ref;
switch (type) {
case ACTION_TYPES.setOtpTextForIndex:
{
var _state$handleChange;
const otpCode = {
...state.otpCode,
[`${payload.index}`]: payload.text
};
(_state$handleChange = state.handleChange) === null || _state$handleChange === void 0 ? void 0 : _state$handleChange.call(state, Object.values(otpCode).join(''));
return {
...state,
otpCode,
index: payload.index
};
}
case ACTION_TYPES.setOtpCode:
{
var _state$handleChange2;
const otpCode = fillOtpCode(payload.count, payload.code);
(_state$handleChange2 = state.handleChange) === null || _state$handleChange2 === void 0 ? void 0 : _state$handleChange2.call(state, Object.values(otpCode).join(''));
return {
...state,
otpCode
};
}
case ACTION_TYPES.clearOtp:
{
var _state$handleChange3;
const otpCode = fillOtpCode(payload);
(_state$handleChange3 = state.handleChange) === null || _state$handleChange3 === void 0 ? void 0 : _state$handleChange3.call(state, Object.values(otpCode).join(''));
return {
...state,
otpCode
};
}
case ACTION_TYPES.setHasKeySupport:
{
return {
...state,
hasKeySupport: payload
};
}
default:
return state;
}
});
//# sourceMappingURL=reducer.js.map