DefinitelyTyped/types/create-subscription/index.d.ts
Nathan Shively-Sanders f0ce987bc1 Update project urls to match NPM url
Note that this *trivially* updates project urls by adding the NPM url to
the end, even when the urls are almost identical or the DT one is
outdated. I'll clean up the urls in a later commit.

This PR is unfinished! Please do not merge it yet.
2019-02-11 17:10:55 -08:00

38 lines
1.5 KiB
TypeScript

// Type definitions for create-subscription 16.4
// Project: https://github.com/facebook/react/tree/master/packages/create-subscription, https://github.com/facebook/react
// Definitions by: Asana <https://github.com/Asana>
// Vincent Siao <https://github.com/vsiao>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from "react";
export type Unsubscribe = () => any;
export interface SubscriptionConfig<S, T> {
/**
* Synchronously gets the value for the subscribed property.
* Return undefined if the subscribable value is undefined,
* Or does not support synchronous reading (e.g. native Promise).
*/
getCurrentValue: (source: S) => T;
/**
* Set up a subscription for the subscribable value in props, and return an unsubscribe function.
* Return false to indicate the property cannot be unsubscribed from (e.g. native Promises).
* Due to the variety of change event types, subscribers should provide their own handlers.
* Those handlers should not attempt to update state though;
* They should call the callback() instead when a subscription changes.
*/
subscribe: (source: S, callback: (newValue: T) => void) => Unsubscribe;
}
export interface SubscriptionProps<S, T> {
children: (value: T) => React.ReactNode;
source: S;
}
export interface Subscription<S, T> extends React.ComponentClass<SubscriptionProps<S, T>> {}
export function createSubscription<S, T>(config: SubscriptionConfig<S, T>): Subscription<S, T>;