# create-store-helper

> store.js

Latest version **0.0.5** (published 2019-01-14) · 0 weekly downloads

## Install

```sh
npm install create-store-helper
pnpm add create-store-helper
yarn add create-store-helper
bun add create-store-helper
```

## Health

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

Positive: has types; no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2019-01-14 |
| First published | 2019-01-14 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 23.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ymblender |

## Links

- npm: https://www.npmjs.com/package/create-store-helper
- Repository: https://github.com/your-name/create-store-helper
- Homepage: https://github.com/your-name/create-store-helper#readme
- Issues: https://github.com/your-name/create-store-helper/issues
- npm.io page: https://npm.io/package/create-store-helper

## Dependencies (4)

- [redux](https://npm.io/package/redux.md) ^4.0.1
- [redux-saga](https://npm.io/package/redux-saga.md) ^0.16.2
- [react-redux](https://npm.io/package/react-redux.md) ^6.0.0
- [redux-thunk](https://npm.io/package/redux-thunk.md) ^2.3.0

## Recent versions

- 0.0.5 (latest) — 2019-01-14
- 0.0.3 — 2019-01-14
- 0.0.2 — 2019-01-14

## README

# create store helper

store.js

```js
import * as sagas from 'src/actions/sagas';
import { Map } from 'immutable';
import { createStoreWithSaga, autoLocalStorage } from 'src/purefunctions/index.lib';

const store = createStoreWithSaga(sagas);

// 初始化 state
const initState = Map({ user: {} });
store.dispatch({ type: 'init-state', reducer: () => initState });

// 监听本地对象
autoLocalStorage(store, 'test-a', ['aaa']);

export default store;
```

action.js

```js
/**
 * 设置用户的照片集
 * @param  {Array} photos
 */
export function actionOfSetUserPhotos(photos) {
  return {
    type: 'actionOfLoadPhotos',
    reducer(state) {
      state = state.setIn(['user', 'photosError'], false);
      return state.setIn(['user', 'photos'], photos);
    },
  };
}

/** 设置用户的照片集 */
export function actionOfSetUserPhotosError() {
  return {
    type: 'actionOfLoadPhotos',
    reducer(state) {
      return state.updateIn(['user', 'photosError'], true);
    },
  };
}

```

saga.js

```js
import axios from 'axios';
import * as actions from 'src/actions/actions';

/** 获取照片信息 */
export function sagaOfUserGetPhotos() {
  return {
    type: 'sagaOfUserGetPhotos',
    saga({ call, put }) {
      return function*() {
        try {
          const res = yield call(axios.get, ['https://pixabay.com/api/?key=8089180-a586bdfbeea5884bd5e24a138']);
          if (res && res.data) {
            yield put(actions.actionOfSetUserPhotos(res.data));
          }
        } catch (error) {
          // yield put({ type: types.errorFetchFainl, payload: error });
          yield put(actions.actionOfSetUserPhotosError());
        }
      };
    },
  };
}
```

---
_Source: https://npm.io/package/create-store-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
