Thanks to the fact validate function returns input values (basically proxies them) it's very convenient to use for React.js action creators.
This model can be expressed with byContract interfaces in a separate module like that:
export const ENTITY_REF = {
id: "string"
}
export const GROUP_REF = {
...ENTITY_REF
};
export const TEST_REF = {
...ENTITY_REF,
groupId: "string"
};
export const ENTITY = {
editing: "boolean=",
disabled: "boolean="
};
export const GROUP = {
title: "string=",
tests: "*[]",
...GROUP_REF
};
export const TEST = {
title: "string=",
commands: "*[]",
...TEST_REF
};
import { validate } from "bycontract";
import * as I from "interface";
export const addGroup = ( data, ref = null ) => ({
type: constants.ADD_GROUP,
payload: {
data: validate( data, { ...I.ENTITY, ...I.GROUP } ),
ref: validate( ref, I.GROUP_REF )
}
});
export const addTest = ( data, ref = null ) => ({
type: constants.ADD_TEST,
payload: {
data: validate( data, { ...I.ENTITY, ...I.TEST } ),
ref: validate( ref, I.TEST_REF )
}
});
export const removeTest = ( ref ) => ({
type: constants.REMOVE_TEST,
payload: {
ref: validate( ref, I.TEST_REF )
}
});