reactotron-core-client

  • Version 2.9.6
  • Published
  • 106 kB
  • 1 dependency
  • MIT license

Install

npm i reactotron-core-client
yarn add reactotron-core-client
pnpm add reactotron-core-client

Overview

Grants Reactotron clients the ability to talk to a Reactotron server.

Index

Variables

variable corePlugins

const corePlugins: (
| ((reactotron: ReactotronCore) => {
features: {
log: (...args: any[]) => void;
logImportant: (...args: any[]) => void;
debug: (message: any, important?: any) => void;
warn: (message: any) => void;
error: (message: any, stack: any) => void;
};
})
| ((reactotron: ReactotronCore) => {
features: {
image: (payload: import('./plugins/image').ImagePayload) => void;
};
})
| ((reactotron: ReactotronCore) => {
features: {
benchmark: (title: string) => {
step: (stepTitle: string) => void;
stop: (stopTitle: string) => void;
last: (stopTitle: string) => void;
};
};
})
| ((reactotron: ReactotronCore) => {
features: {
stateActionComplete: (
name: string,
action: Record<string, any>,
important?: any
) => void;
stateValuesResponse: (path: string, value: any, valid?: any) => void;
stateKeysResponse: (
path: string,
keys: string[],
valid?: boolean
) => void;
stateValuesChange: (
changes: { path: string; value: any }[]
) => false | void;
stateBackupResponse: (state: Record<string, any>) => void;
};
})
| ((reactotron: ReactotronCore) => {
features: {
apiResponse: (
request: { status: number },
response: any,
duration: number
) => void;
};
})
| ((reactotron: ReactotronCore) => { features: { clear: () => void } })
| ((reactotron: ReactotronCore) => {
onCommand: ({ type, payload }: Command<CommandTypeKey, any>) => void;
features: {
repl: (
name: string,
value: import('./plugins/repl').AcceptableRepls
) => void;
};
})
)[];

    Functions

    function assertHasLoggerPlugin

    assertHasLoggerPlugin: (
    reactotron: ReactotronCore
    ) => asserts reactotron is ReactotronCore & {
    log: (...args: any[]) => void;
    logImportant: (...args: any[]) => void;
    debug: (message: any, important?: any) => void;
    warn: (message: any) => void;
    error: (message: any, stack: any) => void;
    };

      function assertHasStateResponsePlugin

      assertHasStateResponsePlugin: (
      reactotron: ReactotronCore
      ) => asserts reactotron is ReactotronCore & {
      stateActionComplete: (
      name: StateActionCompletePayload,
      action: StateActionCompletePayload,
      important?: any
      ) => void;
      stateValuesResponse: (
      path: StateValuesResponsePayload,
      value: StateValuesResponsePayload,
      valid?: StateValuesResponsePayload
      ) => void;
      stateKeysResponse: (
      path: StateKeysResponsePayload,
      keys: StateKeysResponsePayload,
      valid?: StateKeysResponsePayload
      ) => void;
      stateValuesChange: (changes: StateValuesChangePayload) => false | void;
      stateBackupResponse: (state: StateBackupResponsePayload) => void;
      };

        function createClient

        createClient: <Client extends ReactotronCore = ReactotronCore>(
        options?: ClientOptions<Client>
        ) => Client;

          function hasStateResponsePlugin

          hasStateResponsePlugin: (
          reactotron: ReactotronCore
          ) => reactotron is ReactotronCore & {
          stateActionComplete: (
          name: StateActionCompletePayload,
          action: StateActionCompletePayload,
          important?: any
          ) => void;
          stateValuesResponse: (
          path: StateValuesResponsePayload,
          value: StateValuesResponsePayload,
          valid?: StateValuesResponsePayload
          ) => void;
          stateKeysResponse: (
          path: StateKeysResponsePayload,
          keys: StateKeysResponsePayload,
          valid?: StateKeysResponsePayload
          ) => void;
          stateValuesChange: (changes: StateValuesChangePayload) => false | void;
          stateBackupResponse: (state: StateBackupResponsePayload) => void;
          };

            Classes

            class ReactotronImpl

            class ReactotronImpl
            implements
            Omit<
            ReactotronCore,
            'options' | 'plugins' | 'configure' | 'connect' | 'use'
            > {}

              property connected

              connected: boolean;
              • Are we connected to a server?

              property customCommandLatestId

              customCommandLatestId: number;
              • The current ID for custom commands

              property customCommands

              customCommands: CustomCommand<CustomCommandArg[]>[];
              • The registered custom commands

              property isReady

              isReady: boolean;
              • Are we ready to start communicating?

              property lastMessageDate

              lastMessageDate: Date;
              • The last time we sent a message.

              property options

              options: ClientOptions<ReactotronCore>;

                property plugins

                plugins: Plugin<this>[];
                • Available plugins.

                property send

                send: <Type extends CommandTypeKey, Payload extends any>(
                type: Type,
                payload?: Payload,
                important?: boolean
                ) => void;
                • Sends a command to the server

                property sendQueue

                sendQueue: string[];
                • Messages that need to be sent.

                property socket

                socket: WebSocket;
                • The socket we're using.

                property startTimer

                startTimer: () => () => number;
                • Starts a timer and returns a function you can call to stop it and return the elapsed time.

                method close

                close: () => void;

                  method configure

                  configure: (
                  options: ClientOptions<this>
                  ) => ClientOptions<this>['plugins'] extends PluginCreator<this>[]
                  ? this & InferFeaturesFromPlugins<this, ClientOptions<this>['plugins']>
                  : this;
                  • Set the configuration options.

                  method connect

                  connect: () => this;
                  • Connect to the Reactotron server.

                  method display

                  display: (config: DisplayConfig) => void;
                  • Sends a custom command to the server to displays nicely.

                  method onCustomCommand

                  onCustomCommand: (
                  config: CustomCommand | string,
                  optHandler?: () => void
                  ) => () => void;

                    method reportError

                    reportError: (this: any, error: Error) => void;
                    • Client libraries can hijack this to report errors.

                    method use

                    use: (
                    pluginCreator: PluginCreator<this>
                    ) => this & PluginFeatures<this, typeof pluginCreator>;
                    • Adds a plugin to the system

                    Interfaces

                    interface ClientOptions

                    interface ClientOptions<Client> extends Omit<LifeCycleMethods, 'onCommand'> {}
                    • Configuration options for the Reactotron Client.

                    property client

                    client?: Record<string, string | number | boolean>;
                    • A way for the client libraries to identify themselves.

                    property createSocket

                    createSocket?:
                    | ((path: string) => BrowserWebSocket)
                    | ((path: string) => NodeWebSocket)
                    | null;
                    • A function which returns a websocket.

                      This is over-engineered because we need the ability to create different types of websockets for React Native, React, and NodeJS. :|

                    property environment

                    environment?: string;
                    • The NODE_ENV environment, if any.

                    property getClientId

                    getClientId?: (name: string) => Promise<string>;
                    • Get the client id provided by the server

                    property host

                    host?: string | null;
                    • The hostname or ip address of the server. Default: localhost.

                    property name

                    name?: string;
                    • The name of this client. Usually the app name.

                    property onCommand

                    onCommand?: ((command: any) => void) | null;
                    • Fires when the server sends a command.

                    property onConnect

                    onConnect?: () => void;
                    • Fires when we connect to the server.

                    property onDisconnect

                    onDisconnect?: () => void;
                    • Fires when we disconnect from the server.

                    property plugins

                    plugins?: PluginCreator<Client>[];
                    • A list of plugins.

                    property port

                    port?: number | null;
                    • The port to connect to the server on. Default: 9090.

                    property proxyHack

                    proxyHack?: boolean;

                      property safeRecursion

                      safeRecursion?: boolean;
                      • Performs safety checks when serializing. Default: true.

                        Will do things like: - remap falsy values to transport-friendly version - remove any circular dependencies - remap functions to something that shows their name

                        Hooray for JavaScript!

                      property secure

                      secure?: boolean;
                      • Will we be connecting via SSL?

                      property setClientId

                      setClientId?: (clientId: string) => Promise<void>;
                      • Save the client id provided by the server

                      interface CustomCommand

                      interface CustomCommand<Args extends CustomCommandArg[] = CustomCommandArg[]> {}

                        property args

                        args?: Args;

                          property command

                          command: string;

                            property description

                            description?: string;

                              property handler

                              handler: (args?: CustomCommandArgs<Args>) => void;

                                property id

                                id?: number;

                                  property title

                                  title?: string;

                                    interface CustomCommandArg

                                    interface CustomCommandArg {}

                                      property name

                                      name: string;

                                        property type

                                        type: ArgType;

                                          interface LifeCycleMethods

                                          interface LifeCycleMethods {}

                                            property onCommand

                                            onCommand?: (command: Command) => void;

                                              property onConnect

                                              onConnect?: () => void;

                                                property onDisconnect

                                                onDisconnect?: () => void;

                                                  interface Plugin

                                                  interface Plugin<Client> extends LifeCycleMethods {}

                                                    property features

                                                    features?: {
                                                    [key: string]: AnyFunction;
                                                    };

                                                      property onPlugin

                                                      onPlugin?: (client: Client) => void;

                                                        interface Reactotron

                                                        interface Reactotron extends ReactotronCore, CorePluginFeatures {}

                                                          interface ReactotronCore

                                                          interface ReactotronCore {}

                                                            property close

                                                            close: () => void;

                                                              property configure

                                                              configure: (
                                                              options: ClientOptions<this>
                                                              ) => ClientOptions<this>['plugins'] extends PluginCreator<this>[]
                                                              ? this & InferFeaturesFromPlugins<this, ClientOptions<this>['plugins']>
                                                              : this;
                                                              • Set the configuration options.

                                                              property connect

                                                              connect: () => this;

                                                                property display

                                                                display: (config: DisplayConfig) => void;

                                                                  property onCustomCommand

                                                                  onCustomCommand: <
                                                                  Args extends CustomCommandArg[] = Exclude<CustomCommand['args'], undefined>
                                                                  >(
                                                                  config: CustomCommand<Args>
                                                                  ) => () => void | ((config: string, optHandler?: () => void) => () => void);

                                                                    property options

                                                                    options: ClientOptions<this>;

                                                                      property plugins

                                                                      plugins: Plugin<this>[];

                                                                        property send

                                                                        send: <Type extends CommandTypeKey, Payload extends Command<Type>['payload']>(
                                                                        type: Type,
                                                                        payload?: Payload,
                                                                        important?: boolean
                                                                        ) => void;

                                                                          property startTimer

                                                                          startTimer: () => () => number;

                                                                            property use

                                                                            use: <P extends PluginCreator<this>>(
                                                                            pluginCreator: P
                                                                            ) => this & InferFeaturesFromPlugin<this, P>;

                                                                              Enums

                                                                              enum ArgType

                                                                              enum ArgType {
                                                                              String = 'string',
                                                                              }

                                                                                member String

                                                                                String = 'string'

                                                                                  Type Aliases

                                                                                  type CustomCommandArgs

                                                                                  type CustomCommandArgs<Args extends CustomCommandArg[]> = UnionToIntersection<
                                                                                  Args extends Array<infer U>
                                                                                  ? U extends CustomCommandArg
                                                                                  ? {
                                                                                  [K in U as U['name']]: ArgTypeMap[U['type']];
                                                                                  }
                                                                                  : never
                                                                                  : never
                                                                                  >;

                                                                                    type InferFeatures

                                                                                    type InferFeatures<
                                                                                    Client = ReactotronCore,
                                                                                    PC extends PluginCreator<Client> = PluginCreator<Client>
                                                                                    > = PC extends (client: Client) => {
                                                                                    features: infer U;
                                                                                    }
                                                                                    ? U
                                                                                    : never;

                                                                                      type InferFeaturesFromPlugins

                                                                                      type InferFeaturesFromPlugins<
                                                                                      Client,
                                                                                      Plugins extends PluginCreator<Client>[]
                                                                                      > = UnionToIntersection<PluginFeatures<Client, Plugins[number]>>;

                                                                                        type InferPluginsFromCreators

                                                                                        type InferPluginsFromCreators<
                                                                                        Client,
                                                                                        PC extends PluginCreator<Client>[]
                                                                                        > = PC extends Array<infer P extends PluginCreator<Client>>
                                                                                        ? ReturnType<P>[]
                                                                                        : never;

                                                                                          type LoggerPlugin

                                                                                          type LoggerPlugin = ReturnType<typeof logger>;

                                                                                            type PluginCreator

                                                                                            type PluginCreator<Client> = (client: Client) => Plugin<Client>;

                                                                                              type StateResponsePlugin

                                                                                              type StateResponsePlugin = ReturnType<typeof stateResponse>;

                                                                                                Package Files (5)

                                                                                                Dependencies (1)

                                                                                                Dev Dependencies (34)

                                                                                                Peer Dependencies (0)

                                                                                                No peer dependencies.

                                                                                                Badge

                                                                                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/reactotron-core-client.

                                                                                                • Markdown
                                                                                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/reactotron-core-client)
                                                                                                • HTML
                                                                                                  <a href="https://www.jsdocs.io/package/reactotron-core-client"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>