Files
flipper/docs/extending/send-data.mdx
John Knox 2a5d1d8ff9 Fix website syntax highlighting
Summary:
We have a bunch of code blocks using languages that aren't rendered by default, so adding syntax highlighting for those languages.

Also, some uses are using the wrong "name" for the language, so I've fixed them.

Reviewed By: mweststrate

Differential Revision: D21974341

fbshipit-source-id: 17146ea5ae4979241c51b3707035470e9742a104
2020-06-10 08:44:51 -07:00

40 lines
1.4 KiB
Plaintext

---
id: send-data
title: Providing Data to Plugins
---
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.
<!--DOCUSAURUS_CODE_TABS-->
<!--Android-->
```java
final FlipperClient client = AndroidFlipperClient.getInstance(context);
if (client != null) {
final MyFlipperPlugin plugin = client.getPluginByClass(MyFlipperPlugin.class);
plugin.sendData(myData);
}
```
<!--iOS-->
```objective-c
FlipperClient *client = [FlipperClient sharedClient];
MyFlipperPlugin *myPlugin = [client pluginWithIdentifier:@"MyFlipperPlugin"];
[myPlugin sendData:myData];
```
<!--C++-->
```cpp
auto& client = FlipperClient::instance();
auto myPlugin = client.getPlugin<MyFlipperPlugin>("MyFlipperPlugin");
if (myPlugin) {
myPlugin->sendData(myData);
}
```
<!--END_DOCUSAURUS_CODE_TABS-->
Here, `sendData` is an example of a method that might be implemented by the Flipper plugin.