Files
flipper/src/reducers/pluginStates.js
Pritesh Nandgaonkar af317eed2b Export and import all the nodes
Summary:
This diff does the following

- Support to export the entire view hierarchy for iOS
- Android is not supported yet
- This diff adds a call `getAllNodes` to the client side of iOS, which returns the entire view hierarchy
- Currently the search doesn't work on the imported layout plugin data. Also the imported layout plugin data doesn't expand the way it does when component is mounted, reason being the client passed to the plugin is not functional for the archived case

I will work on fixing the last points in the next diffs stacked on the current one.

For Android:
- Currently the export function will export whatever is currently displayed on the Flipper app, not the entire view hierarchy

Support for Android will also come up in later diffs.

Reviewed By: jknoxville

Differential Revision: D14209157

fbshipit-source-id: 3ad3e39edfd994913dc19cc239bfbbe011a9757c
2019-02-28 09:40:50 -08:00

70 lines
1.7 KiB
JavaScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
export type State = {
[pluginKey: string]: Object,
};
export const pluginKey = (serial: string, pluginName: string): string => {
return `${serial}#${pluginName}`;
};
export type Action =
| {
type: 'SET_PLUGIN_STATE',
payload: {
pluginKey: string,
state: Object,
},
}
| {
type: 'CLEAR_PLUGIN_STATE',
payload: {id: string, devicePlugins: Set<string>},
};
const INITIAL_STATE: State = {};
export default function reducer(
state: State = INITIAL_STATE,
action: Action,
): State {
if (action.type === 'SET_PLUGIN_STATE') {
const newPluginState = action.payload.state;
if (newPluginState && newPluginState !== state) {
return {
...state,
[action.payload.pluginKey]: {
...state[action.payload.pluginKey],
...newPluginState,
},
};
}
return {...state};
} else if (action.type === 'CLEAR_PLUGIN_STATE') {
const {payload} = action;
return Object.keys(state).reduce((newState, pluginKey) => {
// Only add the pluginState, if its from a plugin other than the one that
// was removed. pluginKeys are in the form of ${clientID}#${pluginID}.
const pluginId = pluginKey.split('#').pop();
if (pluginId !== payload.id || payload.devicePlugins.has(pluginId)) {
newState[pluginKey] = state[pluginKey];
}
return newState;
}, {});
} else {
return state;
}
}
export const setPluginState = (payload: {
pluginKey: string,
state: Object,
}): Action => ({
type: 'SET_PLUGIN_STATE',
payload,
});