# redux-packaged

> Tool to make redux be packaged

Latest version **1.1.5** (published 2019-03-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install redux-packaged
pnpm add redux-packaged
yarn add redux-packaged
bun add redux-packaged
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2019-03-26 |
| First published | 2018-11-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 11 |
| Unpacked size | 80.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Zaku |
| Maintainers | tomle.zaku |
| Keywords | redux, tool |

## Links

- npm: https://www.npmjs.com/package/redux-packaged
- Repository: https://github.com/tomzaku/redux-packaged
- Homepage: https://github.com/tomzaku/redux-packaged#readme
- Issues: https://github.com/tomzaku/redux-packaged/issues
- npm.io page: https://npm.io/package/redux-packaged

## Dependencies (11)

- [ramda](https://npm.io/package/ramda.md) ^0.25.0
- [redux](https://npm.io/package/redux.md) ^4.0.1
- [rimraf](https://npm.io/package/rimraf.md) ^2.6.2
- [js-tokens](https://npm.io/package/js-tokens.md) ^4.0.0
- [redux-saga](https://npm.io/package/redux-saga.md) ^0.16.2
- [typescript](https://npm.io/package/typescript.md) ^3.3.3333
- [npm-run-all](https://npm.io/package/npm-run-all.md) ^4.1.3
- [@types/ramda](https://npm.io/package/@types/ramda.md) types/npm-ramda#dist
- [loose-envify](https://npm.io/package/loose-envify.md) ^1.4.0
- [typesafe-actions](https://npm.io/package/typesafe-actions.md) ^2.0.4
- [symbol-observable](https://npm.io/package/symbol-observable.md) ^1.2.0

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.1.5 (latest) — 2019-03-26
- 1.1.4 — 2019-03-26
- 1.1.3 — 2019-03-26
- 1.1.2 — 2019-03-14
- 1.1.1 — 2019-03-14
- 1.1.0 — 2019-03-13
- 1.0.23 — 2019-01-24
- 1.0.22 — 2019-01-16
- 1.0.21 — 2019-01-15
- 1.0.20 — 2018-12-07
- 1.0.19 — 2018-12-06
- 1.0.16 — 2018-12-04
- 1.0.15 — 2018-12-04
- 1.0.13 — 2018-11-22
- 1.0.14 — 2018-11-21
- … 9 more at https://npm.io/package/redux-packaged/versions

## README

# redux-packaged

## Problems about management redux module

If you familar with 'CBA'(Component Base Architecture), you will need your module standalone. 

For example:

First your state look like this:

``` js
{
	foo: todoState
}
```

And what happen if you update your state like this:

``` js
{
	foo: {
		bar: {
			baz: todoState
		}
	}
}
```

You have to change a lot from selector and make you feel tired.

So what about you wrap your redux's module.

## Description

`Redux-packaged` collect some util to packaged your redux module.

## Example

See at `test/basic-sample`

```tsx
import action from './action'
import actionType from './actionType'
import reducer from './reducer'
import reduxUtil from '../../src'
import { combineReducers } from 'redux'

// Now be wrapped
const makeTodoRedux = reduxUtil.make({
	makeActionType: actionType.make,
	makeAction: action.make,
	makeReducer: reducer.make,
	makeSeletor: reducer
})


// Let's use
const todoRedux = makeTodoRedux({
	// local is depend on your rootReducer setup in this case is ['foo', 'bar']
	'local': ['foo', 'bar'],
})

// Setup
const rootReducer = combineReducers({
	'foo': combineReducers({
		'bar': todoRedux.reducer
	})
})

type RootState = ReturnType<typeof rootReducer>
let state: RootState
// state.foo.bar.list.all // It's work


// Call Action
todoRedux.actionCollection.add('Let us review your code')
todoRedux.actionCollection.remove('1')

// How about get data
todoRedux.selector

```

## Full example

`action.ts`

```tsx
import { action, ActionType } from 'typesafe-actions'
import { ActionTypeTodo } from './actionType'
import { IReduxModule } from '../../src'


export type ActionCollectionTodo = ReturnType<typeof make>
export type ActionTodo = ActionType<ActionCollectionTodo>

const make = (reduxModule: IReduxModule<ActionTypeTodo, {}>) => {
	const { actionType } = reduxModule
	const add = (title: string, status = 'idle') => action(actionType.ADD, { title, status, date: new Date(), id: Number(new Date()).toString()})
	const remove = (id: string) => action(actionType.REMOVE, { id })
	return {
		add,
		remove,
	}
}

export default {
	make
}
```

`actionType.ts`
```tsx
import reduxUtil, { ReturnActionType } from '../../src'

const make = reduxUtil.actionType.make([
	'ADD',
	'REMOVE'
])

export type ActionTypeTodo = ReturnActionType<typeof make>

export default {
	make
}
```
`reducer.ts`
```tsx
import { ActionTodo } from './action'
import { ActionTypeTodo } from './actionType'
import { IReduxModuleAction } from '../../src'
import { merge, omit } from 'ramda'


export type Status = 'inProcessing' | 'done' | 'idle'
export interface Todo {
	id: string,
	date: string,
	title: string,
	status: Status
}
export interface TodoState {
	resource: {
		[id: string]: Todo
	},
	list: {
		all: string[]
	},
}

const make = (reduxModule: IReduxModuleAction<ActionTypeTodo, {}, ActionTodo>) =>
	(state: TodoState, action: ActionTodo) => {
		const { actionType } = reduxModule
		switch (action.type) {
			case actionType.ADD: {
				const resourceUpdate = merge({[action.payload.id]: action.payload})(state.resource)
				return {
					...state,
					resource: resourceUpdate
				}
			}
			case actionType.REMOVE: {
				const resourceUpdate = omit(action.payload.id)(state.resource)
				return {
					...state,
					resource: resourceUpdate
				}
			}
			default: {
				return state
			}
		}
	}

export default {
	make
}
```

## Contributes

Help me to build this awesome package

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