Skip to content

Commit

Permalink
Renames addPlugin to use. (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
skellock committed Aug 23, 2016
1 parent 2ce4a76 commit 7302cd5
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion packages/demo-react-native/App/Config/ReactotronConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Reactotron
onConnect: () => console.log('connected'),
onDisconnect: () => console.log('disconnected')
})
.addPlugin(decorate(console, 'tron'))
.use(decorate(console, 'tron'))
.connect()
4 changes: 2 additions & 2 deletions packages/reactotron-core-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ Sent from the client to server when it's time to report some performance details

# Plugins

Reactotron is extensible via plugins. You add plugins by calling the `addPlugin`
Reactotron is extensible via plugins. You add plugins by calling the `use`
function on the the client.

A plugin is a function with 1 parameter: a configuration object. It returns an
Expand Down Expand Up @@ -432,7 +432,7 @@ Here's what a plugin can do.
// Every entry in here will become a method on the Reactotron client object.
// Collisions are handled on a first-come first-serve basis.
//
// These functions are reserved (sorry): connect, configure, send, addPlugin,
// These functions are reserved (sorry): connect, configure, send, use,
// options, connected, plugins, and socket.
//
// Sorry.
Expand Down
6 changes: 3 additions & 3 deletions packages/reactotron-core-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const CorePlugins = [
// these are not for you.
const isReservedFeature = R.contains(R.__, [
'options', 'connected', 'socket', 'plugins',
'configure', 'connect', 'send', 'addPlugin',
'configure', 'connect', 'send', 'use',
'startTimer'
])

Expand All @@ -50,7 +50,7 @@ export class Client {

// if we have plugins, let's add them here
if (R.isArrayLike(this.options.plugins)) {
R.forEach(this.addPlugin.bind(this), this.options.plugins)
R.forEach(this.use.bind(this), this.options.plugins)
}

return this
Expand Down Expand Up @@ -110,7 +110,7 @@ export class Client {
/**
* Adds a plugin to the system
*/
addPlugin (pluginCreator) {
use (pluginCreator) {
// we're supposed to be given a function
if (typeof pluginCreator !== 'function') throw new Error('plugins must be a function')

Expand Down
8 changes: 4 additions & 4 deletions packages/reactotron-core-client/test/api-response-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('stateActionComplete', t => {
name = y.name
action = y.action
}
client.addPlugin(plugin)
client.use(plugin)
t.is(client.plugins.length, 1)
t.is(typeof client.stateActionComplete, 'function')
client.stateActionComplete('name', { action: 123 })
Expand All @@ -34,7 +34,7 @@ test('stateValuesResponse', t => {
value = y.value
valid = y.valid
}
client.addPlugin(plugin)
client.use(plugin)
t.is(client.plugins.length, 1)
t.is(typeof client.stateValuesResponse, 'function')
client.stateValuesResponse('user.password', 'password', false)
Expand All @@ -56,7 +56,7 @@ test('stateKeysResponse', t => {
keys = y.keys
valid = y.valid
}
client.addPlugin(plugin)
client.use(plugin)
t.is(client.plugins.length, 1)
t.is(typeof client.stateKeysResponse, 'function')
client.stateKeysResponse('user', ['name', 'password'], false)
Expand All @@ -74,7 +74,7 @@ test('stateValuesChange', t => {
type = x
changes = y.changes
}
client.addPlugin(plugin)
client.use(plugin)
t.is(client.plugins.length, 1)
t.is(typeof client.stateValuesChange, 'function')
client.stateValuesChange([{ path: 'a', value: 1 }, { path: 'b', value: 2 }])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('adds benchmarks to a report', async t => {
}

// register
client.addPlugin(plugin)
client.use(plugin)

t.is(client.plugins.length, 1)
t.is(typeof client.benchmark, 'function')
Expand Down
12 changes: 6 additions & 6 deletions packages/reactotron-core-client/test/plugin-decorator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ test('attaches with a default name', t => {
const client = createClient({ io })
const victim = {}
const plugin = decorate(victim)
client.addPlugin(plugin)
client.use(plugin)
t.is(victim.reactotron, client)
})

test('attaches with a custom name', t => {
const client = createClient({ io })
const victim = {}
const plugin = decorate(victim, 'lol')
client.addPlugin(plugin)
client.use(plugin)
t.is(victim.lol, client)
})

test('victim must be an object', t => {
const client = createClient({ io })
t.throws(() => client.addPlugin(decorate(null)))
t.throws(() => client.addPlugin(decorate(1)))
t.throws(() => client.addPlugin(decorate('')))
t.throws(() => client.addPlugin(decorate(undefined)))
t.throws(() => client.use(decorate(null)))
t.throws(() => client.use(decorate(1)))
t.throws(() => client.use(decorate('')))
t.throws(() => client.use(decorate(undefined)))
})
12 changes: 6 additions & 6 deletions packages/reactotron-core-client/test/plugin-features-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import R from 'ramda'

test('features must be an object if they appear', t => {
const client = createClient({ io })
t.throws(() => client.addPlugin(config => ({ features: 1 })))
t.throws(() => client.use(config => ({ features: 1 })))
})

test('some names are not allowed', t => {
Expand All @@ -14,11 +14,11 @@ test('some names are not allowed', t => {

const badPlugins = R.map(
name => createPlugin({ [name]: R.identity }),
['options', 'connected', 'socket', 'plugins', 'configure', 'connect', 'send', 'addPlugin', 'startTimer']
['options', 'connected', 'socket', 'plugins', 'configure', 'connect', 'send', 'use', 'startTimer']
)

R.forEach(plugin => {
t.throws(() => { client.addPlugin(plugin) })
t.throws(() => { client.use(plugin) })
}, badPlugins)
})

Expand All @@ -30,16 +30,16 @@ test('features can be added and called', t => {
}
return { features }
}
client.addPlugin(plugin)
client.use(plugin)
t.is(typeof client.magic, 'function')
t.is(client.magic(), 42)
})

test('you can overwrite other feature names', t => {
const client = createClient({ io })
const createPlugin = number => config => ({ features: { hello: () => number } })
client.addPlugin(createPlugin(69))
client.use(createPlugin(69))
t.is(client.hello(), 69)
client.addPlugin(createPlugin(9001))
client.use(createPlugin(9001))
t.is(client.hello(), 9001)
})
24 changes: 12 additions & 12 deletions packages/reactotron-core-client/test/plugin-interface-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ test('client accepts plugins', t => {

test('plugins are functions', t => {
const client = createClient({ io })
t.throws(() => client.addPlugin())
t.throws(() => client.addPlugin(null))
t.throws(() => client.addPlugin(''))
t.throws(() => client.addPlugin(1))
t.throws(() => client.use())
t.throws(() => client.use(null))
t.throws(() => client.use(''))
t.throws(() => client.use(1))
})

test('plugins are invoke and return an object', t => {
const client = createClient({ io })
t.throws(() => client.addPlugin(() => null))
t.throws(() => client.addPlugin(() => 1))
t.throws(() => client.addPlugin(() => ''))
t.throws(() => client.addPlugin(() => undefined))
client.addPlugin(() => ({}))
client.addPlugin(() => () => true)
t.throws(() => client.use(() => null))
t.throws(() => client.use(() => 1))
t.throws(() => client.use(() => ''))
t.throws(() => client.use(() => undefined))
client.use(() => ({}))
client.use(() => () => true)
})

test('plugins can literally do nothing', t => {
const client = createClient({ io })
const empty = config => ({})
client.addPlugin(empty)
client.use(empty)
t.is(client.plugins.length, 1)
})

test.cb('initialized with the config object', t => {
const client = createClient({ io })
client.addPlugin(config => {
client.use(config => {
t.is(typeof config, 'object')
t.is(config.ref, client)
t.is(typeof config.send, 'function')
Expand Down
2 changes: 1 addition & 1 deletion packages/reactotron-core-client/test/plugin-logger-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test('the 4 functions send the right data', t => {
const client = createClient({ io: socketClient })
const results = []
client.send = (type, payload) => { results.push({type, payload}) }
client.addPlugin(plugin)
client.use(plugin)
t.is(client.plugins.length, 1)
t.is(typeof client.log, 'function')
t.is(typeof client.debug, 'function')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test.cb('plugins support send', t => {

// create the client, add the plugin, and connect
createClient({ io: socketClient, port: port })
.addPlugin(plugin)
.use(plugin)
.connect()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test.cb('plugins support onConnect', t => {

// create a client & add the plugin
createClient({ io: socketClient, port })
.addPlugin(plugin)
.use(plugin)
.connect()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test.cb('plugins support onDisconnect', t => {
})

createClient({ io: socketClient, port })
.addPlugin(plugin)
.use(plugin)
.connect()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test.cb('plugins support onPlugin', t => {
})

// add the plugin
client.addPlugin(plugin)
client.use(plugin)

// kick it off
client.connect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('apiResponse', t => {
response = y.response
duration = y.duration
}
client.addPlugin(plugin)
client.use(plugin)
t.is(client.plugins.length, 1)
t.is(typeof client.apiResponse, 'function')
client.apiResponse(
Expand Down
2 changes: 1 addition & 1 deletion packages/reactotron-react-native/test/interface-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('it\'s an object', t => {
test('spot check some of the functions', t => {
t.is(typeof reactotron.configure, 'function')
t.is(typeof reactotron.connect, 'function')
t.is(typeof reactotron.addPlugin, 'function')
t.is(typeof reactotron.use, 'function')
})

test('has the right name', t => {
Expand Down
4 changes: 2 additions & 2 deletions packages/reactotron-redux/src/store-enhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const DEFAULTS = {
*/
const createReactotronStoreEnhancer = (reactotron, enhancerOptions = {}) => {
// verify reactotron
if (!(R.is(Object, reactotron) && typeof reactotron.addPlugin === 'function')) {
if (!(R.is(Object, reactotron) && typeof reactotron.use === 'function')) {
throw new Error('invalid reactotron passed')
}

Expand All @@ -25,7 +25,7 @@ const createReactotronStoreEnhancer = (reactotron, enhancerOptions = {}) => {
// the store to create
const store = createStore(reducer, initialState, enhancer)
const plugin = createPlugin(store)
reactotron.addPlugin(plugin)
reactotron.use(plugin)

// swizzle the current dispatch
const originalDispatch = store.dispatch
Expand Down

0 comments on commit 7302cd5

Please sign in to comment.