Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. // ---------------------------------------------------------------------------------------------------------------------
  2. // PromiseProxy - A proxy object that wraps a promise, and exposes `pending`, `result` and `error` properties. This is
  3. // most useful when setting results of promises on the scope directly, so you can work with them in your templates.
  4. //
  5. // @module promise-proxy.js
  6. // ---------------------------------------------------------------------------------------------------------------------
  7.  
  8. function PromiseProxyFactory(promise)
  9. {
  10. var proxy = {
  11. pending: true,
  12. promise: promise
  13. };
  14.  
  15. promise.then(
  16. function(result)
  17. {
  18. proxy.pending = false;
  19. proxy.result = result;
  20. },
  21. function(error)
  22. {
  23. proxy.pending = false;
  24. proxy.error = error;
  25. });
  26.  
  27. return proxy;
  28. } // end PromiseProxyFactory
  29.  
  30. // ---------------------------------------------------------------------------------------------------------------------
  31.  
  32. angular.module('promise-proxy', []).value('promise-proxy', PromiseProxyFactory);
  33.  
  34. // ---------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement