How to use create-subscription - 4 common examples

To help you get started, weโ€™ve selected a few create-subscription 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 gnosis / dx-react / src / components / TestSubscription / index.tsx View on Github external
if (err) {
        console.log(`Watch error: ${err}`)
        cb({ error: err })
      } else {
        // Update balance
        const accData = await grabProviderState(fakeProvider as any)
        cb(accData)
      }
    })
  },
  unsubscribe() {
    // return filter.stopWatching()
  },
}

const Subscription: any = createSubscription({
  getCurrentValue(source: any) {
    // Return the current value of the subscription (source),
    // or `undefined` if the value can't be read synchronously (e.g. native Promises).
    return source.currenState
  },
  subscribe(eventDispatcher: any, callback: any) {
    // Subscribe (e.g. add an event listener) to the subscription (source).
    // Call callback(newValue) whenever a subscription changes.
    // Return an unsubscribe method,
    // Or a no-op if unsubscribe is not supported (e.g. native Promises).

    eventDispatcher.subscribe(callback)

    return () => eventDispatcher.unsubscribe()
  },
})
github reactjs / ru.reactjs.org / examples / update-on-async-rendering / adding-event-listeners-create-subscription.js View on Github external
import {createSubscription} from 'create-subscription';

const Subscription = createSubscription({
  getCurrentValue(sourceProp) {
    // Return the current value of the subscription (sourceProp).
    return sourceProp.value;
  },

  subscribe(sourceProp, callback) {
    function handleSubscriptionChange() {
      callback(sourceProp.value);
    }

    // Subscribe (e.g. add an event listener) to the subscription (sourceProp).
    // Call callback(newValue) whenever a subscription changes.
    sourceProp.subscribe(handleSubscriptionChange);

    // Return an unsubscribe method.
    return function unsubscribe() {
github pomber / hitchcock / packages / hitchcock / src / director.js View on Github external
import React from "react";
import glamorous from "glamorous";
import { cachePublisher as cache, WAITING, RUNNING, PAUSED, DONE } from "./spy";
import { createSubscription } from "create-subscription/cjs/create-subscription.production.min.js";
import Draggable from "react-draggable";
import ReactDOM from "react-dom";

const Subscription = createSubscription({
  getCurrentValue(source) {
    return source.getCurrentValue();
  },
  subscribe(source, callback) {
    const onChange = () => callback(source.getCurrentValue());
    source.subscribe(onChange);
    return function unsubscribe() {
      source.unsubscribe(onChange);
    };
  }
});

const clickable = {
  // cursor: "pointer",
  transition: "transform 70ms",
  ":hover": {
github mmiszy / react-with-observable / src / index.tsx View on Github external
private getSubscriptionComponent() {
    const SubscriptionComponent = createSubscription, T | undefined>({
      getCurrentValue(_observable) {
        return undefined;
      },
      subscribe(observable, callback) {
        const subscription = observable.subscribe(callback);
        return () => subscription.unsubscribe();
      },
    });

    return SubscriptionComponent;
  }
}

create-subscription

utility for subscribing to external data sources inside React components

MIT
Latest version published 2 years ago

Package Health Score

75 / 100
Full package analysis

Similar packages