UNPKG

@connectv/core

Version:

agent-based reactive programming library for typescript/javascript

46 lines 1.54 kB
import { Observable } from 'rxjs'; import { map as _map, mergeMap, share } from 'rxjs/operators'; import { EmissionError } from '../shared/errors/emission-error'; import { Pipe } from './pipe'; /** * * Represents [map](https://connective.dev/docs/map) pins. * */ export class Map extends Pipe { constructor(_func) { super((_func.length <= 1) ? ([_map(emission => { try { return emission.fork(_func(emission.value)); } catch (error) { throw new EmissionError(error, emission); } })]) : ([ mergeMap(emission => new Observable(subscriber => { _func(emission.value, (res) => { subscriber.next(emission.fork(res)); subscriber.complete(); }, (error) => { subscriber.error(new EmissionError(error, emission)); }, emission.context); })), share() ])); this.map = _func; } } /** * * Creates a [map](https://connective.dev/docs/map) pin using given transformation. * A map pin will transform incoming values based on given transformation. * [Checkout the docs](https://connective.dev/docs/map) for examples and further information. * * @param map * */ export function map(map) { return new Map(map); } export default map; //# sourceMappingURL=map.js.map