Async-Lodash
This is a very simple wrapper around lodash. It has all the same methods (except chain as of v1.0.0).
Before invoking the lodash method it will resolve all promises that are in the arguments.
Install
npm i async-lodash -s
Why
Lodash is an amazing library, and it is a pretty standard one to include in most modern JavaScript applications. Promises are another amazing addition to the JS standard. When we put them together, life gets pretty easy. Up until now when you wanted to combine them, you might do something like this:
; // This async object could be a user event, an HTTP request, or any other async action. We'll mock it quickly here with Promise.resolve.const asyncObject = Promise; { return { return asyncUser; };} ; // 4
Honestly, that's really not that bad... BUT I think it could be even easier. What if we could do something like?
; // This asynchronous object could be a user event, an HTTP request, or any other async action. We'll mock it quickly here with Promise.resolve.const asyncObject = Promise; { return lodash;} ; // 4
The difference is small, but the benefit is huge. The dirty work of opening and resolving the promise has been taken care of! All you see is the lodash method, just like you would when working with synchronous data.
Usage
; const promise = Promise; { const result = await _; console; // 'value'}
;; { return ; };} { _ ; // 'whatever property value was returned from fetch';}
Nested Methods
Often times when using Lodash, methods are nested within each other. This can still be done with Async-Lodash. Here's an example:
; const data = id: 5 name: 'Tom' isActive: false id: 23 name: 'Billy' isActive: true ; _; // "Billy is an active user"
The above example demonstrates that these async methods can be nested, and when promises are included they will still work.