December 2018
Intermediate to advanced
642 pages
15h 5m
English
The functional tests we wrote are quite good, but just won't do for some situations, such as when you work with callbacks. Let's turn to another piece of code we wrote: the user validation routine we used for JWT. Basically, this function received a username, a password, and an error-first callback, which was used to signal whether the username really had that password or not. We wrote very basic validation code (a single user was accepted!), but that doesn't matter here; we want to look at how we can deal with the callback. The important parts we care about now are highlighted in the following code extract:
const validateUser = ( userName: string, password: string, callback: (?string, ?string) => void) => { if (!userName || !password) ...Read now
Unlock full access