Add isMethodSupported to client
Summary: Allows plugins to check if extension commands or new features are enabled in the current app, by calling `this.client.supportsMethod('xxx')`.
Reviewed By: passy
Differential Revision: D14225961
fbshipit-source-id: c9f7f5b3091209f0ce9705d9d3a0ec173edf3e25
This commit is contained in:
committed by
Facebook Github Bot
parent
6dc2215753
commit
0445a05e5b
@@ -469,4 +469,13 @@ export default class Client extends EventEmitter {
|
|||||||
}
|
}
|
||||||
return this.rawSend('execute', {api, method, params});
|
return this.rawSend('execute', {api, method, params});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
supportsMethod(api: string, method: string): Promise<boolean> {
|
||||||
|
if (this.sdkVersion < 2) {
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
|
return this.rawCall('isMethodSupported', {api, method}).then(
|
||||||
|
response => response.isSupported,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export type PluginClient = {|
|
|||||||
send: (method: string, params?: Object) => void,
|
send: (method: string, params?: Object) => void,
|
||||||
call: (method: string, params?: Object) => Promise<any>,
|
call: (method: string, params?: Object) => Promise<any>,
|
||||||
subscribe: (method: string, callback: (params: any) => void) => void,
|
subscribe: (method: string, callback: (params: any) => void) => void,
|
||||||
|
supportsMethod: (method: string) => Promise<boolean>,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
type PluginTarget = BaseDevice | Client;
|
type PluginTarget = BaseDevice | Client;
|
||||||
@@ -168,6 +169,7 @@ export class FlipperPlugin<S = *, A = *, P = *> extends FlipperBasePlugin<
|
|||||||
});
|
});
|
||||||
this.realClient.subscribe(id, method, callback);
|
this.realClient.subscribe(id, method, callback);
|
||||||
},
|
},
|
||||||
|
supportsMethod: method => this.realClient.supportsMethod(id, method),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user