Skip to content
iamchenxin edited this page Jun 6, 2016 · 2 revisions

Why need dynamic check?

  1. Data go though typed and untyped packages.(this case should be resolved by flow typed all packages)
  2. 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).
  3. 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).

about this package.

Basiclly, this package is divided to two parts. Checkers and validators. Checker is a wrapper to that functions(need check) using unchecked params. validators are tools which be used to valid a given value,it will return a validate value with Flow typed.

Simple usage illustration

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
});

More usage ..

  1. Link the data type(Flow typed) between server and client.