How to use the xstream.Stream.create function in xstream

To help you get started, we’ve selected a few xstream examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github italonascimento / lemni / packages / lemni-core / src / lemni.ts View on Github external
// Generic types can't be spread
      // https://github.com/Microsoft/TypeScript/issues/16780
      // https://github.com/Microsoft/TypeScript/issues/10727
      const { store, ...props } = this.props as any
      this.store = store as Store<s>
      this.componentProps = props as P

      const hasStore = Boolean(this.store)

      this.sources = {
        props: Stream.createWithMemory(),
        state: Stream.createWithMemory(),
        store: hasStore ? this.store.getStoreStream() : Stream.never(),
        lifecycle: {
          componentDidMount: Stream.create(),
          componentWillUnmount: Stream.create(),
          componentWillMount: Stream.create(),
          componentWillReceiveProps: Stream.create(),
          shouldComponentUpdate: Stream.create(),
          componentWillUpdate: Stream.create(),
          componentDidUpdate: Stream.create(),
        },
      }

      this.sinks = mainFn(this.sources)
      const {
        stateReducer = [],
        storeReducer = [],
        sideEffect = [],
        initialState = {} as L
      } = this.sinks
</s>
github iov-one / iov-core / packages / iov-multichain / src / signingservice.spec.ts View on Github external
): SimpleMessagingConnection {
  const producer: Producer = {
    start: listener =&gt; {
      // tslint:disable-next-line:no-object-mutation
      worker.onmessage = event =&gt; {
        listener.next(parseJsonRpcResponse(event.data));
      };
    },
    stop: () =&gt; {
      // tslint:disable-next-line:no-object-mutation
      worker.onmessage = null;
    },
  };

  return {
    responseStream: Stream.create(producer),
    sendRequest: request =&gt; worker.postMessage(request),
  };
}
github iov-one / iov-core / packages / iov-socket / src / streamingsocket.ts View on Github external
if (closeEvent.wasClean) {
            this.eventProducerListener.complete();
          } else {
            this.eventProducerListener.error("Socket was closed unclean");
          }
        }
      },
      timeout,
    );
    this.connected = this.socket.connected;

    const eventProducer: Producer = {
      start: listener =&gt; (this.eventProducerListener = listener),
      stop: () =&gt; (this.eventProducerListener = undefined),
    };
    this.events = Stream.create(eventProducer);
  }
github iov-one / iov-core / packages / iov-ethereum / src / ethereumconnection.ts View on Github external
}
            }
          };

          await poll();
          pollIntervalLogs = setInterval(poll, this.pollIntervalMs);
        },
        stop: () => {
          if (pollIntervalLogs) {
            clearInterval(pollIntervalLogs);
            pollIntervalLogs = undefined;
          }
        },
      };

      const mergedStream = Stream.merge(Stream.create(fromScraperProducer), Stream.create(fromLogsProducer));
      const deduplicatedStream = mergedStream.compose(dropDuplicates(ct => ct.transactionId));
      return deduplicatedStream;
    } else {
      throw new Error("Unsupported query.");
    }
  }
github iov-one / iov-core / packages / iov-lisk / src / liskconnection.ts View on Github external
listener.error(error);
          }
        };

        pollInternal = setInterval(poll, defaultPollInterval);
        await poll();
      },
      stop: () => {
        if (pollInternal) {
          clearInterval(pollInternal);
          pollInternal = undefined;
        }
      },
    };

    return Stream.create(producer);
  }
github iov-one / iov-core / packages / iov-socket / src / queueingstreamingsocket.ts View on Github external
public constructor(url: string, timeout = 10_000, reconnectedHandler?: () =&gt; void) {
    this.url = url;
    this.timeout = timeout;
    this.reconnectedHandler = reconnectedHandler;

    const eventProducer: Producer = {
      start: listener =&gt; (this.eventProducerListener = listener),
      stop: () =&gt; (this.eventProducerListener = undefined),
    };
    this.events = Stream.create(eventProducer);
    this.connectionStatusProducer = new DefaultValueProducer(ConnectionStatus.Unconnected);
    this.connectionStatus = new ValueAndUpdates(this.connectionStatusProducer);

    this.socket = new StreamingSocket(this.url, this.timeout);
    this.socket.events.subscribe({
      next: event =&gt; {
        if (!this.eventProducerListener) throw new Error("No event producer listener set");
        this.eventProducerListener.next(event);
      },
      error: () =&gt; this.connectionStatusProducer.update(ConnectionStatus.Disconnected),
    });
  }
github iov-one / iov-core / packages / iov-lisk / src / liskconnection.ts View on Github external
if (pollInternal) {
              clearTimeout(pollInternal);
              pollInternal = undefined;
            }
            listener.error(error);
          }
        }, defaultPollInterval);
      },
      stop: () => {
        if (pollInternal) {
          clearTimeout(pollInternal);
          pollInternal = undefined;
        }
      },
    };
    return Stream.create(producer);
  }
github iov-one / iov-core / packages / iov-socket / src / reconnectingsocket.ts View on Github external
public constructor(url: string, timeout = 10_000, reconnectedHandler?: () =&gt; void) {
    const eventProducer: Producer = {
      start: listener =&gt; (this.eventProducerListener = listener),
      stop: () =&gt; (this.eventProducerListener = undefined),
    };
    this.events = Stream.create(eventProducer);

    this.socket = new QueueingStreamingSocket(url, timeout, reconnectedHandler);
    this.socket.events.subscribe({
      next: event =&gt; {
        if (this.eventProducerListener) {
          this.eventProducerListener.next(event);
        }
      },
      error: error =&gt; {
        if (this.eventProducerListener) {
          this.eventProducerListener.error(error);
        }
      },
    });

    this.connectionStatus = this.socket.connectionStatus;
github iov-one / iov-core / packages / iov-stream / src / concat.ts View on Github external
}
            },
            error: error => {
              listener.error(error);
              reset();
            },
          }),
        );
      });
    },
    stop: () => {
      reset();
    },
  };

  return Stream.create(producer);
}
github cyclejs / cyclejs / dom / src / fromEvent.ts View on Github external
export function fromEvent(
  element: Element | Document,
  eventName: string,
  useCapture = false,
  preventDefault: PreventDefaultOpt = false,
  passive = false
): Stream {
  let next: ((e: Event) =&gt; void) | null = null;
  return Stream.create({
    start: function start(listener: Listener) {
      if (preventDefault) {
        next = function _next(event: Event) {
          preventDefaultConditional(event, preventDefault);
          listener.next(event);
        };
      } else {
        next = function _next(event: Event) {
          listener.next(event);
        };
      }
      element.addEventListener(eventName, next, {
        capture: useCapture,
        passive,
      });
    },