Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/layflags/action-types
Conveniently create action types with multi-level namespace support.
https://github.com/layflags/action-types
Last synced: 27 days ago
JSON representation
Conveniently create action types with multi-level namespace support.
- Host: GitHub
- URL: https://github.com/layflags/action-types
- Owner: layflags
- License: mit
- Created: 2016-06-11T21:06:57.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T22:40:10.000Z (almost 2 years ago)
- Last Synced: 2024-04-24T19:02:22.476Z (7 months ago)
- Language: JavaScript
- Size: 165 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# action-types
[![es6](https://camo.githubusercontent.com/d25414161ebfbbdd0f69a4a3e6a188a76ae2e82a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f65732d362d627269676874677265656e2e737667)](https://babeljs.io/docs/usage/polyfill/)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
[![CircleCI](https://circleci.com/gh/layflags/action-types.svg?style=svg)](https://circleci.com/gh/layflags/action-types)Conveniently create action types with multi-level namespace support.
**A note about compatibility**
The [npm package](https://www.npmjs.com/package/action-types) should be used in
an **ES6 environment**. Even though the published code has ES5 syntax it uses
some ES6 features, so you have to make sure to use ES5 and ES6 polyfills if you
are in an ancient environment.## Install
```sh
npm install action-types
```## Usage
```javascript
import { ActionType, createActionTypes } from './action-types'createActionTypes({
START_APP: ActionType,
user: {
ADD: ActionType,
REMOVE: ActionType,
current: {
SET: ActionType,
CHANGE: ActionType
}
}
})// results in:
{
START_APP: 'START_APP',
user: {
ADD: 'user.ADD',
REMOVE: 'user.REMOVE',
CHANGE: 'user.CHANGE',
current: {
SET: 'user.current.SET',
CHANGE: 'user.current.CHANGE'
}
}
}
```### With initial namespace
```javascript
import { ActionType, createActionTypes } from './action-types'createActionTypes({
ADD: ActionType,
REMOVE: ActionType
}, {
namespace: 'user'
})// results in:
{
ADD: 'user.ADD',
REMOVE: 'user.REMOVE'
}
```### With custom namespace separator
```javascript
import { ActionType, createActionTypes } from './action-types'createActionTypes({
user: {
ADD: ActionType,
REMOVE: ActionType
}
}, {
separator: '::'
})// results in:
{
user: {
ADD: 'user::ADD',
REMOVE: 'user::REMOVE'
}
}
```## Test
```sh
npm test
```## License
[MIT](LICENSE)