Flipper Common Utilities

0.273.0 · active · verified Sun Apr 19

flipper-common is a core utility package within the Facebook Flipper debugging platform, designed to provide shared functionalities and interfaces for `flipper-ui`, `flipper-server`, and Flipper plugins. It encapsulates common logic and types used across different components of the Flipper ecosystem, ensuring consistency and reducing code duplication. The package is currently at version 0.273.0 and maintains a rapid release cadence, often seeing multiple updates per month to align with the active development of the broader Flipper project. Its key differentiators lie in its deep integration within the Flipper architecture, serving as a foundational layer for building robust mobile (iOS/Android) and web/Node.js debugging plugins and server-side interactions, rather than being a general-purpose, standalone utility library.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize and use core utilities like `Logger` and `Id` within a simulated Flipper plugin context, leveraging TypeScript types such as `FlipperClient` for illustrative purposes.

import { Logger, Id, FlipperClient } from 'flipper-common';

interface MyPluginClient extends FlipperClient {
  sendEvent: (event: string, payload: any) => void;
}

class MyFlipperPlugin {
  id: Id;
  logger: Logger;
  client: MyPluginClient;

  constructor(client: MyPluginClient) {
    this.id = new Id();
    this.logger = new Logger('MyFlipperPlugin');
    this.client = client;

    this.logger.info(`Plugin initialized with ID: ${this.id.newID()}`);
  }

  initiateConnection() {
    this.client.sendEvent('plugin-connected', { pluginName: 'MyFlipperPlugin', version: '1.0.0' });
    this.logger.debug('Sent connection event to Flipper desktop.');
  }

  // Example of using another utility or type
  processData(data: any) {
    const transactionId = this.id.newID();
    this.logger.verbose(`Processing data with transaction ID: ${transactionId}`);
    // Imagine further processing or sending data back via client
    this.client.sendEvent('data-processed', { id: transactionId, result: data });
  }
}

// Simulate a Flipper client for demonstration
const mockFlipperClient: MyPluginClient = {
  sendEvent: (event, payload) => {
    console.log(`[Mock Flipper Client] Event: ${event}, Payload: ${JSON.stringify(payload)}`);
  },
  // In a real FlipperClient, there would be more methods like 'onMessage', 'call', etc.
  // These are omitted for a minimal runnable example.
};

const plugin = new MyFlipperPlugin(mockFlipperClient);
plugin.initiateConnection();
plugin.processData({ value: 123, status: 'complete' });

view raw JSON →