babel-plugin-s2s-action-types-ts
v2.1.1
Published
generate action types
Downloads
6
Readme
babel-plugin-s2s-action-types-ts
plugin for https://github.com/akameco/s2s
Install
$ npm install --save-dev babel-plugin-s2s-action-types-ts
Example
Basic
IN:
export type Action = Foo | Bar;
OUT:
export type Action = Foo | Bar;
export interface Foo {
type: Actions.Foo;
}
export interface Bar {
type: Actions.Bar;
payload: string;
}
/***** Do not edit below this line *****/
export const enum Actions {
Foo = "container/example/Foo",
Bar = "container/example/Bar",
}
Request/Success/Failure pattern
IN:
export type Action = FetchRequest;
OUT:
export type Action = FetchRequest | FetchSuccess | FetchFailure;
export interface FetchRequest {
type: Actions.FetchRequest;
}
export interface FetchSuccess {
type: Actions.FetchSuccess;
}
export interface FetchFailure {
type: Actions.FetchFailure;
}
/***** Do not edit below this line *****/
export const enum Actions {
FetchRequest = "examples/request/FetchRequest",
FetchSuccess = "examples/request/FetchSuccess",
FetchFailure = "examples/request/FetchFailure",
}
Usage
module.exports = {
watch: './**/*.ts',
plugins: [
{
test: /actionTypes.ts$/,
plugin: ['s2s-action-types-ts', {
usePrefix: true,
removePrefix: 'src/',
}],
},
],
}
usePrefix
type: boolean
required: false
removePrefix
type: string
required: false
outputh path.