Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should create clear submit errors action', () => {
expect(clearSubmitErrors('myForm')).toEqual({
type: CLEAR_SUBMIT_ERRORS,
meta: {
form: 'myForm'
}
})
expect(isFSA(clearSubmitErrors('myForm'))).toBe(true)
})
it('should create stopSubmit action', () => {
expect(stopSubmit('myForm')).toEqual({
type: STOP_SUBMIT,
meta: {
form: 'myForm'
},
payload: undefined,
error: false
})
expect(isFSA(stopSubmit('myForm'))).toBe(true)
const errors = {
foo: 'Foo error',
bar: 'Error for bar'
}
expect(stopSubmit('myForm', errors)).toEqual({
type: STOP_SUBMIT,
meta: {
form: 'myForm'
},
payload: errors,
error: true
})
it('should create array insert action', () => {
expect(arrayInsert('myForm', 'myField', 0, 'foo')).toEqual({
type: ARRAY_INSERT,
meta: {
form: 'myForm',
field: 'myField',
index: 0
},
payload: 'foo'
})
expect(isFSA(arrayInsert('myForm', 'myField', 0, 'foo'))).toBe(true)
})
})
expect(isFSA(arrayPush('myForm', 'myField', 'foo'))).toBe(true)
expect(arrayPush('myForm', 'myField')).toEqual({
type: ARRAY_PUSH,
meta: {
form: 'myForm',
field: 'myField'
},
payload: undefined
})
expect(isFSA(arrayPush('myForm', 'myField'))).toBe(true)
})
type: 'ADD_TODO',
payload: {
text: 'Do something.'
}
};
var sample2: ErrorAction = {
type: 'ADD_TODO',
payload: new Error(),
error: true
};
var result1: boolean = isError(sample1);
var result2: boolean = isFSA(sample1);
var result3: boolean = isError(sample2);
var result4: boolean = isFSA(sample2);
declare function alert (message: string): void
function unwrapAction(action: { type: string }) {
if (isFSA(action)) {
if (isError(action)) {
alert(action.payload!.message)
}
return action.payload
}
}
var result5: TextPayload = unwrapAction(sample1)
var result6: Error = unwrapAction(sample2)
const errAction = actionCreator(errObj);
expect(errAction).to.deep.equal({
type,
payload: errObj,
error: true
});
expect(isFSA(errAction)).to.be.true;
const foobar = { foo: 'bar', cid: 5 };
const noErrAction = actionCreator(foobar);
expect(noErrAction).to.deep.equal({
type,
payload: foobar
});
expect(isFSA(noErrAction)).to.be.true;
});
export function reducer(state, action) {
if (isFSA(action)) {
console.log(action.type);
console.dir(state);
return (actions[action.type] || actions.DEFAULT)(state, action);
} else {
console.error("Action does not conform to 'flux-standard-action", action);
}
;
}
;
validateInput(action, options);
if (!shouldCallAPI(getState())) return Promise.resolve(getState());
const [pendingType, successType, errorType] = getActionTypes(
typePrefix,
types,
options,
);
const pendingAction = isFSACompliant
? { payload, type: pendingType }
: { ...payload, type: pendingType };
if (isFSACompliant && !isFSA(pendingAction)) next(action);
else dispatch(pendingAction);
return callAPI()
.then(response => {
const formattedData = formatData(response);
if (typeof formattedData !== 'object') {
throw new Error(errorMessages.formatDataReturn);
}
const successAction = isFSACompliant
? {
type: successType,
payload: {
...payload,
...formattedData,
},
return next => action => {
if (!isFSA(action)) {
return isPromise(action)
? action.then(dispatch)
: next(action)
}
const { meta = {}, payload } = action
const id = _.uniqueId()
if (isPromise(payload)) {
dispatch({
...action,
payload: undefined,
meta: {
...meta,
sequence: {
type: 'start',
const isReduceInAction = (action) => {
const reducer = lodashGetIn(action, path_to_redux_lens_reducer, NOT_SET);
return isFSA(action) &&
lodashGetIn(action, path_to_redux_lens_path, NOT_SET) !== NOT_SET &&
reducer !== NOT_SET;
};