added deeplink support to sandy device plugins
Summary: Make sure device plugins can be deeplinked as well. (note that the duplication between `Plugin` and `DevicePlugin` is cleaned up again in D22727089, first wanted to make it work and tested, then clean) DeepLink no longer have to be strings, per popular requests, as that makes direct linking between plugins easier (online links from the outside world have to arrive as strings) Reviewed By: jknoxville, nikoant Differential Revision: D22727091 fbshipit-source-id: 523c90b1e1fbf3700fdb4f62699dd57070cbc980
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b621dcf754
commit
f8ff6dc393
@@ -61,7 +61,10 @@ export interface DevicePluginClient {
|
||||
*/
|
||||
onDeactivate(cb: () => void): void;
|
||||
|
||||
// TODO: support onDeeplink!
|
||||
/**
|
||||
* Triggered when this plugin is opened through a deeplink
|
||||
*/
|
||||
onDeepLink(cb: (deepLink: unknown) => void): void;
|
||||
}
|
||||
|
||||
export interface RealFlipperDevice {
|
||||
@@ -91,6 +94,8 @@ export class SandyDevicePluginInstance {
|
||||
initialStates?: Record<string, any>;
|
||||
// all the atoms that should be serialized when making an export / import
|
||||
rootStates: Record<string, Atom<any>> = {};
|
||||
// last seen deeplink
|
||||
lastDeeplink?: any;
|
||||
|
||||
constructor(
|
||||
realDevice: RealFlipperDevice,
|
||||
@@ -120,6 +125,9 @@ export class SandyDevicePluginInstance {
|
||||
onDeactivate: (cb) => {
|
||||
this.events.on('deactivate', cb);
|
||||
},
|
||||
onDeepLink: (callback) => {
|
||||
this.events.on('deeplink', callback);
|
||||
},
|
||||
};
|
||||
setCurrentPluginInstance(this);
|
||||
this.initialStates = initialStates;
|
||||
@@ -143,8 +151,8 @@ export class SandyDevicePluginInstance {
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
this.assertNotDestroyed();
|
||||
if (this.activated) {
|
||||
if (!this.destroyed && this.activated) {
|
||||
this.lastDeeplink = undefined;
|
||||
this.activated = false;
|
||||
this.events.emit('deactivate');
|
||||
}
|
||||
@@ -161,6 +169,14 @@ export class SandyDevicePluginInstance {
|
||||
return '[SandyDevicePluginInstance]';
|
||||
}
|
||||
|
||||
triggerDeepLink(deepLink: unknown) {
|
||||
this.assertNotDestroyed();
|
||||
if (deepLink !== this.lastDeeplink) {
|
||||
this.lastDeeplink = deepLink;
|
||||
this.events.emit('deeplink', deepLink);
|
||||
}
|
||||
}
|
||||
|
||||
exportState() {
|
||||
return Object.fromEntries(
|
||||
Object.entries(this.rootStates).map(([key, atom]) => [key, atom.get()]),
|
||||
|
||||
Reference in New Issue
Block a user