Home
iamchenxin edited this page Jun 6, 2016
·
2 revisions
- Data go though typed and untyped packages.(this case should be resolved by flow typed all packages)
- Data are in a complex code stream between packages,too complex for flow type between those packages. (Like grapgql's resolver,which be used in graphql-relay,and the params are narrowed to a custom type).
- Data from remote,out of your control.(In this case,flow-dynamic could be used at both client and server,with single type valid logic).
Basiclly, this package is divided to two parts. Checker
s and validator
s. Checker
is a wrapper to that functions(need check) using unchecked params. validator
s are tools which be used to valid a given value,it will return a validate value with Flow typed.
a simple dynamic check will like this:
//Assume you have a function, its params are out of static flow type check.
const oriFn = (src) => {
// .... doing something
});
above function can be checked like:
const wrappedFn = sourceCheck(
(src) => ({
mail:pro.isString.isEmail(src.mail) // check src.mail.
}), (src) => { // Now, the src is be validated and have a Flow type {mail:string}
// .... doing something
});
- Link the data type(Flow typed) between server and client.