This commit is contained in:
Salakar 2018-08-25 19:21:07 +01:00
parent 23d2a80273
commit a040485193
6 changed files with 32 additions and 18 deletions

View File

@ -5,7 +5,7 @@ module.exports = {
{
files: '*.json',
options: {
printWidth: 400,
printWidth: 100,
},
},
],

4
src/index.d.ts vendored
View File

@ -1142,7 +1142,9 @@ declare module 'react-native-firebase' {
}
type BackgroundFetchResultValue = string;
type CompletionHandler = (backgroundFetchResult: BackgroundFetchResultValue) => void;
type CompletionHandler = (
backgroundFetchResult: BackgroundFetchResultValue
) => void;
interface Notifications {
android: AndroidNotifications;

View File

@ -20,7 +20,6 @@ import type EventSubscriptionVendor from './EventSubscriptionVendor';
* EmitterSubscription represents a subscription with listener and context data.
*/
class EmitterSubscription extends EventSubscription {
emitter: EventEmitter;
listener: Function;
context: ?Object;

View File

@ -32,7 +32,6 @@ const invariant = require('fbjs/lib/invariant');
* more advanced emitter may use an EventHolder and EventFactory.
*/
class EventEmitter {
_subscriber: EventSubscriptionVendor;
_currentSubscription: ?EmitterSubscription;
@ -61,12 +60,14 @@ class EventEmitter {
* listener
*/
addListener(
eventType: string, listener: Function, context: ?Object): EmitterSubscription {
eventType: string,
listener: Function,
context: ?Object
): EmitterSubscription {
return (this._subscriber.addSubscription(
eventType,
new EmitterSubscription(this, this._subscriber, listener, context)
) : any);
): any);
}
/**
@ -79,7 +80,11 @@ class EventEmitter {
* @param {*} context - Optional context object to use when invoking the
* listener
*/
once(eventType: string, listener: Function, context: ?Object): EmitterSubscription {
once(
eventType: string,
listener: Function,
context: ?Object
): EmitterSubscription {
return this.addListener(eventType, (...args) => {
this.removeCurrentListener();
listener.apply(context, args);
@ -146,10 +151,13 @@ class EventEmitter {
* @returns {array}
*/
listeners(eventType: string): [EmitterSubscription] {
const subscriptions: ?[EmitterSubscription] = (this._subscriber.getSubscriptionsForType(eventType): any);
const subscriptions: ?[
EmitterSubscription,
] = (this._subscriber.getSubscriptionsForType(eventType): any);
return subscriptions
? subscriptions.filter(emptyFunction.thatReturnsTrue).map(
function(subscription) {
? subscriptions
.filter(emptyFunction.thatReturnsTrue)
.map(function(subscription) {
return subscription.listener;
})
: [];
@ -170,7 +178,9 @@ class EventEmitter {
* emitter.emit('someEvent', 'abc'); // logs 'abc'
*/
emit(eventType: string) {
const subscriptions: ?[EmitterSubscription] = (this._subscriber.getSubscriptionsForType(eventType): any);
const subscriptions: ?[
EmitterSubscription,
] = (this._subscriber.getSubscriptionsForType(eventType): any);
if (subscriptions) {
for (let i = 0, l = subscriptions.length; i < l; i++) {
const subscription = subscriptions[i];
@ -202,7 +212,9 @@ class EventEmitter {
*
*/
removeListener(eventType: string, listener) {
const subscriptions: ?[EmitterSubscription] = (this._subscriber.getSubscriptionsForType(eventType): any);
const subscriptions: ?[
EmitterSubscription,
] = (this._subscriber.getSubscriptionsForType(eventType): any);
if (subscriptions) {
for (let i = 0, l = subscriptions.length; i < l; i++) {
const subscription = subscriptions[i];

View File

@ -18,7 +18,6 @@ import type EventSubscriptionVendor from './EventSubscriptionVendor';
* remove its own subscription.
*/
class EventSubscription {
eventType: string;
key: number;
subscriber: EventSubscriptionVendor;

View File

@ -20,7 +20,6 @@ import type EventSubscription from './EventSubscription';
* subscribed to a particular event type.
*/
class EventSubscriptionVendor {
_subscriptionsForType: Object;
_currentSubscription: ?EventSubscription;
@ -36,10 +35,13 @@ class EventSubscriptionVendor {
* @param {EventSubscription} subscription
*/
addSubscription(
eventType: string, subscription: EventSubscription): EventSubscription {
eventType: string,
subscription: EventSubscription
): EventSubscription {
invariant(
subscription.subscriber === this,
'The subscriber of the subscription is incorrectly set.');
'The subscriber of the subscription is incorrectly set.'
);
if (!this._subscriptionsForType[eventType]) {
this._subscriptionsForType[eventType] = [];
}
@ -93,7 +95,7 @@ class EventSubscriptionVendor {
* @returns {?array}
*/
getSubscriptionsForType(eventType: string): ?[EventSubscription] {
return this._subscriptionsForType[eventType];
return this._subscriptionsForType[eventType];
}
}