Skip to content
This repository was archived by the owner on Jan 26, 2021. It is now read-only.

Commit 6422e49

Browse files
committed
Reuse Subscriber flow type definition in more places
1 parent 8dc3a52 commit 6422e49

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/LocalSubscriptions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ var Id = require('./Id');
2828
var ObjectStore = require('./ObjectStore');
2929
var Parse = require('./StubParse');
3030

31+
import type { Subscriber } from './Subscription';
32+
3133
/**
3234
* Local Subscriptions allow applications to subscribe to local objects, such
3335
* as the current user. React components can watch these for changes and
@@ -38,9 +40,7 @@ var currentUser = {
3840
subscribers: {},
3941
observerCount: 0,
4042

41-
subscribe: function(
42-
callbacks:{ onNext: (value: any) => void; onError?: (error: any) => void }
43-
): { dispose: () => void } {
43+
subscribe: function(callbacks: Subscriber): { dispose: () => void } {
4444
var observerId = 'o' + this.observerCount++;
4545
this.subscribers[observerId] = callbacks;
4646
var id;

src/Subscription.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type ParseObject = {
3030
id: Id
3131
};
3232

33-
type Subscriber = {
33+
export type Subscriber = {
3434
onNext: (value: any) => void;
3535
onError?: (error: any) => void;
3636
};

src/SubscriptionManager.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ var keysFromHash = QueryTools.keysFromHash;
3030
var queryHash = QueryTools.queryHash;
3131
var Subscription = require('./Subscription');
3232

33+
import type { Subscriber } from './Subscription';
34+
3335
// Mapping of query hashes to subscriptions
3436
var subscriptions = {};
3537
// Tree of the attributes queries depend on, leading to their hashes
@@ -42,7 +44,7 @@ var queryFamilies = {};
4244
*/
4345
function subscribeToQuery(
4446
query: any,
45-
callbacks: { onNext: (value: any) => void; onError?: (error: any) => void }
47+
callbacks: Subscriber
4648
): { refresh: () => void; dispose: () => void } {
4749
var hash = queryHash(query);
4850
var subscription = subscriptions[hash];

0 commit comments

Comments
 (0)