Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

map.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Subscriber } from '../Subscriber';
  2. export function map(project, thisArg) {
  3. return function mapOperation(source) {
  4. if (typeof project !== 'function') {
  5. throw new TypeError('argument is not a function. Are you looking for `mapTo()`?');
  6. }
  7. return source.lift(new MapOperator(project, thisArg));
  8. };
  9. }
  10. export class MapOperator {
  11. constructor(project, thisArg) {
  12. this.project = project;
  13. this.thisArg = thisArg;
  14. }
  15. call(subscriber, source) {
  16. return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg));
  17. }
  18. }
  19. class MapSubscriber extends Subscriber {
  20. constructor(destination, project, thisArg) {
  21. super(destination);
  22. this.project = project;
  23. this.count = 0;
  24. this.thisArg = thisArg || this;
  25. }
  26. _next(value) {
  27. let result;
  28. try {
  29. result = this.project.call(this.thisArg, value, this.count++);
  30. }
  31. catch (err) {
  32. this.destination.error(err);
  33. return;
  34. }
  35. this.destination.next(result);
  36. }
  37. }
  38. //# sourceMappingURL=map.js.map