Combine the two pages describing sending data
Summary: send data was documented twice, in the general client API, and in the internal docs where it was specifically combined with obtaining a plugin instance. However, that is a proper public API as well, so combined those two. Reviewed By: nikoant Differential Revision: D25588059 fbshipit-source-id: 7135a74b64a87d0c8c3f8f20f7f260469f52d41c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
dc50fb3f63
commit
a9ad932955
@@ -236,6 +236,50 @@ addPlugin({
|
|||||||
</TabItem>
|
</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
|
### Using the FlipperClient singleton to send data
|
||||||
|
|
||||||
|
It is often useful to get an instance of a Flipper plugin to send data to it. Flipper makes this simple with built-in support.
|
||||||
|
|
||||||
|
Plugins should be treated as singleton instances as there can only be one `FlipperClient` and each `FlipperClient` can only have one instance of a certain plugin. The Flipper API makes this simple by offering a way to get the current client and query it for plugins.
|
||||||
|
|
||||||
|
Plugins are identified by the string that their identifier method returns, in this example, "MyFlipperPlugin". Note that null checks may be required as plugins may not be initialized, for example in production builds.
|
||||||
|
|
||||||
|
<Tabs defaultValue="android" values={[{label: 'Android', value: 'android'}, { label: 'iOS', value: 'ios'}, { label: 'C++', value: 'cpp'}]}>
|
||||||
|
<TabItem value="android">
|
||||||
|
|
||||||
|
```java
|
||||||
|
final FlipperClient client = AndroidFlipperClient.getInstance(context);
|
||||||
|
if (client != null) {
|
||||||
|
final MyFlipperPlugin plugin = client.getPluginByClass(MyFlipperPlugin.class);
|
||||||
|
plugin.sendData(myData);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</TabItem>
|
||||||
|
<TabItem value="ios">
|
||||||
|
|
||||||
|
```objective-c
|
||||||
|
FlipperClient *client = [FlipperClient sharedClient];
|
||||||
|
MyFlipperPlugin *myPlugin = [client pluginWithIdentifier:@"MyFlipperPlugin"];
|
||||||
|
[myPlugin sendData:myData];
|
||||||
|
```
|
||||||
|
|
||||||
|
</TabItem>
|
||||||
|
<TabItem value="cpp">
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
auto& client = FlipperClient::instance();
|
||||||
|
auto myPlugin = client.getPlugin<MyFlipperPlugin>("MyFlipperPlugin");
|
||||||
|
if (myPlugin) {
|
||||||
|
myPlugin->sendData(myData);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
|
||||||
|
Here, `sendData` is an example of a method that might be implemented by the Flipper plugin.
|
||||||
|
|
||||||
## Background Plugins
|
## Background Plugins
|
||||||
|
|
||||||
In some cases you may want to provide data to Flipper even when your plugin is not currently active. Returning true in `runInBackground()` will result in `onConnect` being called as soon as Flipper connects, and allow you to use the connection at any time. See the [Client Plugin Lifecycle](client-plugin-lifecycle) for more details.
|
In some cases you may want to provide data to Flipper even when your plugin is not currently active. Returning true in `runInBackground()` will result in `onConnect` being called as soon as Flipper connects, and allow you to use the connection at any time. See the [Client Plugin Lifecycle](client-plugin-lifecycle) for more details.
|
||||||
|
|||||||
@@ -3,47 +3,6 @@ id: send-data
|
|||||||
title: Providing Data to Plugins
|
title: Providing Data to Plugins
|
||||||
---
|
---
|
||||||
|
|
||||||
import Tabs from '@theme/Tabs';
|
import {Redirect} from '@docusaurus/router';
|
||||||
import TabItem from '@theme/TabItem';
|
|
||||||
|
|
||||||
It is often useful to get an instance of a Flipper plugin to send data to it. Flipper makes this simple with built-in support.
|
<Redirect to="/docs/extending/create-plugin#using-the-flipperclient-singleton-to-send-data" />
|
||||||
|
|
||||||
Plugins should be treated as singleton instances as there can only be one `FlipperClient` and each `FlipperClient` can only have one instance of a certain plugin. The Flipper API makes this simple by offering a way to get the current client and query it for plugins.
|
|
||||||
|
|
||||||
Plugins are identified by the string that their identifier method returns, in this example, "MyFlipperPlugin". Note that null checks may be required as plugins may not be initialized, for example in production builds.
|
|
||||||
|
|
||||||
<Tabs defaultValue="android" values={[{label: 'Android', value: 'android'}, { label: 'iOS', value: 'ios'}, { label: 'C++', value: 'cpp'}]}>
|
|
||||||
<TabItem value="android">
|
|
||||||
|
|
||||||
```java
|
|
||||||
final FlipperClient client = AndroidFlipperClient.getInstance(context);
|
|
||||||
if (client != null) {
|
|
||||||
final MyFlipperPlugin plugin = client.getPluginByClass(MyFlipperPlugin.class);
|
|
||||||
plugin.sendData(myData);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
</TabItem>
|
|
||||||
<TabItem value="ios">
|
|
||||||
|
|
||||||
```objective-c
|
|
||||||
FlipperClient *client = [FlipperClient sharedClient];
|
|
||||||
MyFlipperPlugin *myPlugin = [client pluginWithIdentifier:@"MyFlipperPlugin"];
|
|
||||||
[myPlugin sendData:myData];
|
|
||||||
```
|
|
||||||
|
|
||||||
</TabItem>
|
|
||||||
<TabItem value="cpp">
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
auto& client = FlipperClient::instance();
|
|
||||||
auto myPlugin = client.getPlugin<MyFlipperPlugin>("MyFlipperPlugin");
|
|
||||||
if (myPlugin) {
|
|
||||||
myPlugin->sendData(myData);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
</TabItem>
|
|
||||||
</Tabs>
|
|
||||||
|
|
||||||
|
|
||||||
Here, `sendData` is an example of a method that might be implemented by the Flipper plugin.
|
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
'Client plugin APIs': [
|
'Client plugin APIs': [
|
||||||
'extending/create-plugin',
|
'extending/create-plugin',
|
||||||
'extending/send-data',
|
|
||||||
'extending/error-handling',
|
'extending/error-handling',
|
||||||
'extending/testing',
|
'extending/testing',
|
||||||
'extending/arch',
|
'extending/arch',
|
||||||
|
|||||||
Reference in New Issue
Block a user