Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. // Works like underscore-contrib's getPath function.
  2. // Takes a promise that will resolve to an object and a dot notation string specifying a path.
  3. //
  4. // Cannot know if path exists in resolved value - returned promise will reject with a TypeError if you
  5. // specify a subkey of a nonexistent key, and undefined for a single
  6. // nonexistent key.
  7.  
  8. function promiseForPath(promise, path) {
  9. var k = path.split('.');
  10. return k.reduce(function(memo, item){
  11. return memo.get(item);
  12. }, promise);
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement