How to use the create-subscription.createSubscription function in create-subscription

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 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 3 years ago

Package Health Score

75 / 100
Full package analysis

Similar packages