apollo-declare
ctrip-apollo(the Ctrip's apollo client) with pre-declared configuration keys.
Install
$ npm i apollo-declare
Usage
const declare = const host = 'http://localhost:8070'const appId = '100004458'const namespace = 'default' // Emits when the value of a config key changes
Declare two keys in different namespaces
Use the first available value among a config set
If we have two namespaces, 'default'
and 'common'
.
In namespace 'default'
, there is no config key named 'dynamodb.region'
. While in namespace 'common'
, the value of 'dynamodb.region'
is 'ap-northeast-10'
.
// Inside a async functionconst client = await client console// ap-northeast-10
declare(options): ApolloClient
- options
DeclareOptions
ApolloOptions
is the options of ctrip-apollo
Returns ApolloClient
the apollo client. ApolloClient
is a subclass of EventEmitter
await client.ready(): this
Prepare and finish the initial fetching.
All methods except for client.on(type, handler)
should be called after await client.ready()
client.get(key): string
Get the value of config key
client.each(callback): void
- callback
Function(value: string, key: string)
Executes the provided function callback
once for each defined key.
Event: 'change'
- key
string
config key - newValue
string
the new value of the key - oldValue
string
the old value of the key
Emits when the value of a config key changes
client