Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Plugin Documentation #746

Open
skellock opened this issue Jul 12, 2018 · 0 comments

Comments

2 participants
@skellock
Copy link
Contributor

commented Jul 12, 2018

The plugin documentation is pretty bad. Let's fix that.

A Basic Plugin

A Reactotron plugin is a function that returns an object.

// a plugin is a function that takes the reactotron instance
const myPlugin = reactotron => {
  // and returns an object
  return {}
}

// You install it into reactotron when your app starts up.
Reactotron.use(myPlugin)

The plugin does nothing.

Adding features

Let's make a plugin which adds a new feature.

const myPlugin = reactotron => {
  return {
    // this time our object has features key
    features: { 
      // every key you put here will be available on the Reactotron later to use
      sayHello: () => reactotron.log("Hello!")
    }
  }
}

// install the plugin
Reactotron.use(myPlugin)

// later on... somewhere in your app.
Reactotron.sayHello()

Plugins with Configuration

Often plugins have their own configuration:

const myPlugin = (prefix, suffix) => reactotron -> ({
  features: {
    sayHello: name => reactotron.log(prefix + " " + name + " " + suffix)
  }
})

// install
Reactotron.use(myPlugin("omg", "!!!!!"))

// later on... use
Reactotron.sayHello("Steve") // prints "omg Steve !!!!!"

Events

In addition to the features key, there's onConnect, onDisconnect and onCommand:

const myPlugin = () => reactotron -> ({
  onConnect: connection =>  reactotron.log("omg haiii", connection),
  onDisconnect: connection => reactotron.log("laterzzzz", connection),
  onCommand: command => reactotron.log("the reactotron app just sent", command)
})

You know, more stuff like this.

@skellock skellock added the docs 📚 label Jul 12, 2018

@skellock skellock self-assigned this Jul 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.