"init" command for flipper-pkg tool
Summary: Added command "init" to "flipper-pkg" which helps to quickly initialise Flipper desktop plugin. Reviewed By: passy Differential Revision: D21253819 fbshipit-source-id: 85a2fbde07ecb63737d180d2a7e5cc2846b4f533
This commit is contained in:
committed by
Facebook GitHub Bot
parent
21c574ac80
commit
d08dfee018
47
desktop/pkg/templates/plugin/src/index.tsx.template
Normal file
47
desktop/pkg/templates/plugin/src/index.tsx.template
Normal file
@@ -0,0 +1,47 @@
|
||||
import React from 'react';
|
||||
import {FlipperPlugin, FlexColumn, KeyboardActions} from 'flipper';
|
||||
|
||||
type State = {};
|
||||
|
||||
type Data = {};
|
||||
|
||||
type PersistedState = {
|
||||
data: Array<Data>;
|
||||
};
|
||||
|
||||
export default class extends FlipperPlugin<State, any, PersistedState> {
|
||||
static keyboardActions: KeyboardActions = ['clear'];
|
||||
|
||||
static defaultPersistedState: PersistedState = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
static persistedStateReducer = (
|
||||
persistedState: PersistedState,
|
||||
method: string,
|
||||
data: Data,
|
||||
): PersistedState => {
|
||||
return {
|
||||
...persistedState,
|
||||
data: persistedState.data.concat([data]),
|
||||
};
|
||||
};
|
||||
|
||||
state = {};
|
||||
|
||||
onKeyboardAction = (action: string) => {
|
||||
if (action === 'clear') {
|
||||
this.props.setPersistedState({data: []});
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<FlexColumn>
|
||||
{this.props.persistedState.data.map((d) => (
|
||||
<div>{d}</div>
|
||||
))}
|
||||
</FlexColumn>
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user