From 23afff9e2b9044687a8f6855ac8312f745138894 Mon Sep 17 00:00:00 2001 From: Rakha Kanz Kautsar Date: Wed, 2 Sep 2020 07:20:21 -0700 Subject: [PATCH] flipper-js-client-sdk: fix undefined this on connectPlugin and disconnectPlugin (#1506) Summary: `this` is not defined for `connectPlugin` and `disconnectPlugin` because `Array.prototype.map` [replace `this` to `undefined` if not specified](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map): > If a thisArg parameter is provided, it will be used as callback's this value. Otherwise, the value undefined will be used as its this value. The this value ultimately observable by callback is determined according to the usual rules for determining the this seen by a function. ![image](https://user-images.githubusercontent.com/1536976/91691584-72b24c80-eb9a-11ea-88f1-984f2be8ab4a.png) ## Changelog flipper-js-client-sdk: Fix undefined this due to array map Pull Request resolved: https://github.com/facebook/flipper/pull/1506 Test Plan: Tried creating custom client and connecting to websocket server Reviewed By: mweststrate Differential Revision: D23473033 Pulled By: nikoant fbshipit-source-id: bbfd9117da8aa8c7b491e219f98d17ccea48c0fd --- flipper-js-client-sdk/src/api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flipper-js-client-sdk/src/api.ts b/flipper-js-client-sdk/src/api.ts index 8afb5fe52..1fd5f7e98 100644 --- a/flipper-js-client-sdk/src/api.ts +++ b/flipper-js-client-sdk/src/api.ts @@ -123,12 +123,12 @@ export abstract class FlipperClient { this._isConnected = true; Array.from(this.plugins.values()) .filter((plugin) => plugin.runInBackground()) - .map(this.connectPlugin); + .map(this.connectPlugin, this); } onDisconnect() { this._isConnected = false; - Array.from(this.plugins.values()).map(this.disconnectPlugin); + Array.from(this.plugins.values()).map(this.disconnectPlugin, this); } abstract start(appName: string): void;