# babel-plugin-s2s-redux-sagas

> generate redux sagas

Latest version **0.0.3** (published 2017-11-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-s2s-redux-sagas
pnpm add babel-plugin-s2s-redux-sagas
yarn add babel-plugin-s2s-redux-sagas
bun add babel-plugin-s2s-redux-sagas
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2017-11-16 |
| First published | 2017-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | progted |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-s2s-redux-sagas
- npm.io page: https://npm.io/package/babel-plugin-s2s-redux-sagas

## Dependencies (3)

- [s2s-utils](https://npm.io/package/s2s-utils.md) ^0.5.0
- [babel-types](https://npm.io/package/babel-types.md) ^6.26.0
- [babel-preset-es2015](https://npm.io/package/babel-preset-es2015.md) ^6.24.1

## Recent versions

- 0.0.3 (latest) — 2017-11-16

## README

# babel-plugin-s2s-redux-sagas

> generate redux sagas

## Install

```
$ yarn add --dev babel-plugin-s2s-redux-sagas
```

## Create redux-sagas template

You should create babel-plugin-s2s-redux-sagas template. \
In your node project, you create a folder named templates in the same direcotry as the package.json

`mkdir templates`

And create a saga.js

`touch templates/saga.js`

Write this code.This is a template code.

```js
import { put, call,takeLatest } from 'redux-saga/effects';
import * as actions from '../actions';
import * as api from '../api';

export default [];
```

## s2s.config.js

s2s-redux-sagas plugin watch the `src/sagas/*.js` files.

```js
module.exports = {
  watch: './**/*.js',
  plugins: [
    {
       test: /src\/sagas\/(?!.*index).*\.js/,
       plugin: ['s2s-redux-sagas']
    }
  ],
  templates: [
    {
      test: /src\/sagas\/.*\.js/, input: 'saga.js'
    }
  ]
}
```
## Start s2s

Start the s2s with yarn command

`yarn run s2s`

## Usage

#### When create a saga file

When you create a `src/sagas/*.js`, the below code is inserted automatically.

```js
import { put, call,takeLatest } from 'redux-saga/effects';
import * as actions from '../actions';
import * as api from '../api';

export default [];
```

#### In:

In the saga file, type action name with camelcase such as `searchPokemon` and save it.

```js
import { put, call,takeLatest } from 'redux-saga/effects';
import * as actions from '../actions';
import * as api from '../api';

searchPokemon

export default [];
```

It will be expanded like this.

#### Out:

```js
import { put, call,takeLatest } from 'redux-saga/effects';
import * as actions from '../actions';
import * as api from '../api';

export function* handleSearchPokemon(action) {
  try {
    const { data } = yield call(api.searchPokemon, action.payload);
    yield put(actions.searchPokemonSuccess(data));
  } catch (error) {
    yield put(actions.searchPokemonFailure(error));
  }
}

export default [
  takeLatest(actions.searchPokemon.toString(), handleSearchPokemon)
];
```

# Test

This plugin has two test files. \
First is babel plugin main test file named `test.js` on root directory. \
Next is a `test/index.js` that will be transformed by the plugin.

Run this command.

` npm run test`

Test will run and you can see what happen.

If you modify the target javascript source code, please change the `test/index.js`.

---
_Source: https://npm.io/package/babel-plugin-s2s-redux-sagas · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
