I've been reading about nodes lately (like many others). I find it interesting for some use cases, but I'm struggling to understand the inner workings, especially the interaction between the process of closing and the process of code flow. Let me assume that I have a function that accepts the key -The value array function should be checked that values are followed by some data-quality guidelines of values before collecting data (for example, in some keys Value should be, other keys should be in the form of values etc.).
resultName = validateName (data.name) resultAddress = validateAddress (Data.address) resultID = validateID (data.id) if (result & amp; amp; result clearance & amp; resultID) { Get results for other {sendErrorToUser (data)} assumptions, and either explain the error message to the user or archive the data and return any type of confirmation. The flow is very clear.
The way I node To understand JS, the way to do this is to assign assumptions to a different function (to avoid waiting for each verification to finish), and two callback functions that validate the fragmentation of the data: * A callback call To validate when verification is successful * Verification fails to make a callback call
Now the user has the "Please Wait" message, but save the data For or to clear me first user to explain the problem will have to wait for all beliefs (or fail). One simple way to complete all the assumptions is that I think of using a variable that counts a function called callback, and emits a "validation" event to store valid data (Or return the user) with any error) or, alternatively, after the completion of each verification, an event is emitted and the code check of that event is "sto "/" Error "is met all assumptions before emission events.
My question is - am I coming to this right? Or the nodes of these types of things There is a more appropriate way to do this with JS (or similar event-based system).
Thank you! Allen
Is your recognition asynchronous? If they are not, you can use the code used by "regular" one.
var validateUniqueEmail = function (data, callback) If verification is asynchronous (for example to check the specificity of an email), you must provide callback:
var validateUniqueEmail = {Db.find ({email: data.email}, function (fault, result) {callback (error, result === tap);})}} var validateandstore = function (data, callback) {asyncValidation (data, function (Mistake, is_valid) {if (err) {callback (err, null);} else if (! Is_valid) {callback ('email is not unique' tap);} and {db.store (data, callback);} }); } The above code can be very simplified using some validators or ORM modules already present
Example :.
Comments
Post a Comment