pairs.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /** PURE_IMPORTS_START _Observable,_Subscription PURE_IMPORTS_END */
  2. import { Observable } from '../Observable';
  3. import { Subscription } from '../Subscription';
  4. export function pairs(obj, scheduler) {
  5. if (!scheduler) {
  6. return new Observable(function (subscriber) {
  7. var keys = Object.keys(obj);
  8. for (var i = 0; i < keys.length && !subscriber.closed; i++) {
  9. var key = keys[i];
  10. if (obj.hasOwnProperty(key)) {
  11. subscriber.next([key, obj[key]]);
  12. }
  13. }
  14. subscriber.complete();
  15. });
  16. }
  17. else {
  18. return new Observable(function (subscriber) {
  19. var keys = Object.keys(obj);
  20. var subscription = new Subscription();
  21. subscription.add(scheduler.schedule(dispatch, 0, { keys: keys, index: 0, subscriber: subscriber, subscription: subscription, obj: obj }));
  22. return subscription;
  23. });
  24. }
  25. }
  26. export function dispatch(state) {
  27. var keys = state.keys, index = state.index, subscriber = state.subscriber, subscription = state.subscription, obj = state.obj;
  28. if (!subscriber.closed) {
  29. if (index < keys.length) {
  30. var key = keys[index];
  31. subscriber.next([key, obj[key]]);
  32. subscription.add(this.schedule({ keys: keys, index: index + 1, subscriber: subscriber, subscription: subscription, obj: obj }));
  33. }
  34. else {
  35. subscriber.complete();
  36. }
  37. }
  38. }
  39. //# sourceMappingURL=pairs.js.map