"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
25
desktop/pkg/templates/plugin/package.json.template
Normal file
25
desktop/pkg/templates/plugin/package.json.template
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"$schema": "https://fbflipper.com/schemas/plugin-package/v2.json",
|
||||
"name": "flipper-plugin-{{package_name_suffix}}",
|
||||
"id": "{{id}}",
|
||||
"version": "1.0.0",
|
||||
"main": "dist/bundle.js",
|
||||
"flipperBundlerEntry": "src/index.tsx",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"flipper-plugin"
|
||||
],
|
||||
"icon": "apps",
|
||||
"title": "{{title}}",
|
||||
"scripts": {
|
||||
"lint": "flipper-pkg lint",
|
||||
"prepack": "flipper-pkg lint && flipper-pkg bundle"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"flipper": "latest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"flipper": "latest",
|
||||
"flipper-pkg": "latest"
|
||||
}
|
||||
}
|
||||
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