Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

pairs.js 1.3KB

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