Socket
Socket
Sign inDemoInstall

redux-fluent

Package Overview
Dependencies
6
Maintainers
2
Versions
74
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.9.2 to 0.9.3

CHANGELOG.md

11

index.js

@@ -0,8 +1,7 @@

// eslint-disable-next-line spaced-comment
/// <reference path="./index.d.ts" />
'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./build/redux-fluent.production.js');
} else {
module.exports = require('./build/redux-fluent.development.js');
}
// eslint-disable-next-line import/no-dynamic-require
module.exports = require(
`./dist/redux-fluent.${process.env.NODE_ENV === 'production' ? 'production' : 'development'}.js`,
);
{
"name": "redux-fluent",
"license": "MIT",
"version": "0.9.2",
"version": "0.9.3",
"homepage": "https://github.com/Code-Y/redux-fluent#readme",
"description": "Tiny and eloquent way to manage a redux-like state manager",
"author": "Code-Y (https://github.com/Code-Y)",
"private": false,
"description": "Enjoy Redux - Less Boilerplate / Go Functional",
"author": "Code-Y",
"sideEffects": false,
"main": "index.js",
"types": "index.d.ts",
"contributors": [
"Luca Pau <luca.pau82@gmail.com> (https://github.com/Lughino)",
"Giuseppe Mandato <gius.mand.developer@gmail.com> (https://github.com/hitmands)"
"types": "redux-fluent.d.ts",
"files": [
"/dist",
"/node_modules",
"CHANGELOG.md",
"LICENSE",
"index.js"
],
"keywords": [
"redux",
"ngrx-store",
"state-management",
"typings"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"lint": "eslint *.js src/**/*.ts",
"build": "webpack --config webpack.config.js",
"test": "jest --coverage",
"build": "npm run webpack -- --env.name production",
"webpack": "webpack --config webpack.config.js",
"cz": "git-cz"
"release": "standard-version -m \"chore(release): %s [skip ci]\""
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"repository": {

@@ -37,33 +36,53 @@ "type": "git",

},
"contributors": [
"Giuseppe Mandato (https://github.com/hitmands)",
"Luca Pau (https://github.com/Lughino)"
],
"keywords": [
"redux",
"functional programming",
"ramda",
"typings"
],
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"flux-standard-action": "^2.0.3",
"redux": "^4.0.1"
},
"devDependencies": {
"@types/jest": "^21.1.9",
"babel-core": "^6.26.0",
"babel-env": "^2.4.1",
"babel-eslint": "^8.1.2",
"babel-jest": "^22.0.4",
"babel-loader": "^7.1.2",
"codeclimate-test-reporter": "^0.5.0",
"commitizen": "^2.9.6",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^4.14.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-loader": "^1.9.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jest": "^21.5.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.5.1",
"jest": "^21.2.1",
"webpack": "^3.10.0"
},
"jest": {
"transform": {
"^.+\\.jsx?$": "babel-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?)$",
"moduleFileExtensions": [
"js",
"jsx",
"json"
]
"@commitlint/cli": "^7.5.2",
"@commitlint/config-conventional": "^7.5.0",
"@commitlint/travis-cli": "^7.5.2",
"@types/chai": "^4.1.6",
"@types/jest": "^24.0.11",
"@types/node": "^12.0.0",
"@types/ramda": "^0.26.1",
"@types/sinon": "^7.0.10",
"@types/sinon-chai": "^3.2.0",
"@typescript-eslint/eslint-plugin": "^1.4.2",
"@typescript-eslint/parser": "^1.5.0",
"awesome-typescript-loader": "^5.2.1",
"chai": "^4.1.2",
"eslint": "^5.14.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-loader": "^2.1.1",
"eslint-plugin-chai-friendly": "^0.4.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^22.3.0",
"flux-standard-action": "^2.0.3",
"husky": "^2.0.0",
"jest": "^24.3.1",
"ramda": "^0.26.1",
"redux": "^4.0.1",
"sinon": "^7.2.7",
"sinon-chai": "^3.2.0",
"standard-version": "^6.0.1",
"ts-jest": "^24.0.0",
"typescript": "^3.1.3",
"webpack": "^4.19.1",
"webpack-cli": "^3.1.0",
"webpack-node-externals": "^1.7.2"
}
}

@@ -1,6 +0,202 @@

# redux-fluent
# <a href='https://github.com/Code-Y/redux-fluent'><img src='https://raw.githubusercontent.com/Code-Y/redux-fluent/master/redux-fluent-logo.png' height='60' alt='Redux Fluent' aria-label='https://github.com/Code-Y/redux-fluent' /></a> redux-fluent
[![Build Status](https://travis-ci.org/Code-Y/redux-fluent.svg?branch=master)](https://travis-ci.org/Code-Y/redux-fluent)
[![Code Climate](https://codeclimate.com/github/Code-Y/redux-fluent/badges/gpa.svg)](https://codeclimate.com/github/Code-Y/redux-fluent)
[![Test Coverage](https://api.codeclimate.com/v1/badges/02e8b0d9ba383c19ae50/test_coverage)](https://codeclimate.com/github/Code-Y/redux-fluent/test_coverage)
[![npm version](https://img.shields.io/npm/v/redux-fluent.svg)](https://www.npmjs.com/package/redux-fluent)
[![License](https://img.shields.io/npm/l/redux-fluent.svg)](https://github.com/Code-Y/redux-fluent/blob/master/LICENSE)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![npm downloads](https://img.shields.io/npm/dm/redux-fluent.svg)](https://www.npmjs.com/package/redux-fluent)
[![Maintainability](https://api.codeclimate.com/v1/badges/2e98502fb6072892995d/maintainability)](https://codeclimate.com/github/Code-Y/redux-fluent/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/2e98502fb6072892995d/test_coverage)](https://codeclimate.com/github/Code-Y/redux-fluent/test_coverage)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/832b72aed6d24f65a88c54b6b6c467f3)](https://app.codacy.com/app/hitmands/redux-fluent)
[![Greenkeeper badge](https://badges.greenkeeper.io/Code-Y/redux-fluent.svg)](https://greenkeeper.io/)
Tiny and eloquent way to manage a redux-like state manager
Tiny and eloquent way of bringing redux to the next level (*~3K*, typings included).
~~[Try it out on RunKit](https://runkit.com/hitmands/redux-fluent-playground)~~ (*coming soon*)
## Motivations and Design Goals
**[Redux](https://redux.js.org/)** is **great**, every recent web application has most likely been built on top of it, **and we can really make it better!**
- **Flux Standard Actions** as a first class concept. FSA is a pretty common standard and we committed on following it to ensure interoperability.
- **λ Go Functional**, Everything is a function and reducers are built by function composition rather than piling up *if* and *switch-case* statements: [*Let's introduce Redux Fluent Reducers*](#createreducer).
- **Type Safety** means great developer experience. That's what we had in mind while designing redux-fluent. *[Watch it yourself!](#typescript-definitions)*
- **Reducers at scale**, due to being handling multiple actions, reducers tend to grow and become difficult to maintain: [*Let's introduce Redux Fluent Action Handlers*](#oftype).
- **Less boilerplate**, Flux architecture is usually verbose and some of their concepts, such as `Action`, `Action Type` and `Action Creator` could all be implemented in a single entity: [*Let's introduce Redux Fluent Actions*](#createaction).
## Installation
```
yarn add redux-fluent redux flux-standard-action
```
## Getting Started
```javascript
/** todos.actions.js **/
import { createAction } from 'redux-fluent';
export const addTodo = createAction('todos | add');
```
```javascript
/** todos.reducer.js **/
import { createReducer, ofType } from 'redux-fluent';
import * as actions from './todos.actions.js';
const addTodo = (state, { payload }) => state.concat(payload);
export const todos = createReducer('todos')
.actions(
ofType(actions.addTodo).map(addTodo),
/* and so on */
)
.default(() => []);
```
```javascript
/** application.js **/
import { createStore } from 'redux';
import { combineReducers } from 'redux-fluent';
import * as actions from './todos.actions.js';
import { todos } from './todos.reducer.js';
const rootReducer = combineReducers(todos, ...);
const store = createStore(rootReducer);
console.log(store.getState()); // { todos: [] }
store.dispatch(actions.addTodo({ title: 'Listen for some music' }));
console.log(store.getState()); // { todos: [{ title: 'Listen for some music' }] }
```
## Documentation
- [`createReducer()`](#createreducer)
- [`createAction()`](#createaction)
- [`ofType()`](#oftype)
- [`withConfig()`](#withconfig)
- [`combineReducers()`](#combinereducers)
- [`createReducersMapObject()`](#createreducersmapobject)
### `createReducer()`
`createReducer` is a function combinator whose purpose is to output a [redux reducer](https://redux.js.org/basics/reducers) by combining action handlers and `getDefaultState` together.
```typescript
import { createReducer } from 'redux-fluent';
const reducer = createReducer(name)
.actions(
...handlers: (state, action, config?) => state,
)
.default(
getDefaultState: (state: void, action, config?) => state,
);
```
### `createAction()`
`createAction` is a factory function whose purpose is to output an [action creator](https://redux.js.org/basics/actions#action-creators) responsible of shaping your actions. The resulting function holds a field `type` giving you access to the action type.
```typescript
import { createAction } from 'redux-fluent';
createAction(
type: string,
payloadCreator?: (rawPayload, rawMeta, type) => payload,
metaCreator?: (rawPayload, rawMeta, type) => meta,
);
/**
* Action Creator
*
* @param {*|Error} payload
* @param {*} meta
* @returns RFA<'todos | add', *|Error, *> - Flux Standard Action
*/
const addTodo = createAction('todos | add');
console.log(addTodo.type); // 'todos | add'
console.log(addTodo({ id: 1, title: 'have a break' })); // { type: 'todos | add', payload: { id: 1, title: 'have a break' } }
```
### `ofType()`
As we just said, a reducer is nothing more than a function combinator, it does not contain any business logic. The job of actually mutating the state is left to the Action Handlers. By embracing the [Single Responsibility Principle](https://en.wikipedia.org/wiki/Single_responsibility_principle), we can build simple, easy to test, dedicated functions that do only one thing.
```typescript
import { ofType } from 'redux-fluent';
ofType(action: ReduxFluentActionCreator).map((state: any, action: RFA) => state);
ofType(type: string).map((state: any, action: AnyAction) => state);
ofType(action: { type: string }).map((state: any, action: AnyAction) => state);
// write your action handlers by only focusing on the actual task,
// let `ofType` take care of the orchestration (i.e. intercepting actions).
ofType('todos | add').map(
(state, action) => state.concat(action.payload),
);
```
### `withConfig()`
Redux Fluent also comes with some additional features to help you write code at scale. Functions that only rely on their arguments are easy to test and reuse, so you can provide an additional argument `config: any` to enable dependency injection (multiple `config` are shallowly merged).
```typescript
import * as R from 'ramda';
import { withConfig, createReducer, ofType } from 'redux-fluent';
withConfig(config: any);
const todos = createReducer('todos')
.actions(
ofType('todos | doSomething').map(
(state, action, { doSomething }) => doSomething(state, action),
),
ofType('todos | doSomethingElse').map(
(state, action, { doSomethingElse }) => doSomethingElse(state, action),
),
)
.default(() => []);
export default R.pipe(
withConfig({ doSomething: R.tap(console.log) }),
withConfig({ doSomethingElse: R.tap(console.log) }),
)(todos);
```
### `combineReducers()`
This api is not strictly needed, you can still use [`redux#combineReducers`](https://redux.js.org/api/combinereducers). With Redux Fluent, by the way, both namespace and reducer are defined in the same place so that you don't need to take care of the shape when combining them.
```typescript
import { createStore } from 'redux';
import { combineReducers } from 'redux-fluent';
import { todosReducer, notesReducer, otherReducer } from './reducers';
combineReducers(...reducers: ReduxFluentReducer[]);
const rootReducer = combineReducers(todosReducer, notesReducer, otherReducer, ...);
const store = createStore(rootReducer);
```
### `createReducersMapObject()`
This api lets you combine your reducers with [`redux#combineReducers`](https://redux.js.org/api/combinereducers), and can be useful when mixing redux fluent reducers with any other reducer.
```typescript
import { createStore, combineReducers } from 'redux';
import { createReducersMapObject } from 'redux-fluent';
import { todosReducer, notesReducer, otherReducer } from './reducers';
createReducersMapObject(...reducers: ReduxFluentReducer[]);
const reducersMapObject = createReducersMapObject(todosReducer, notesReducer, otherReducer, ...);
const rootReducer = combineReducers({
...reducersMapObject,
anyOtherReducer: (state, action) => 'any other state',
});
const store = createStore(rootReducer);
```
### Typescript Definitions
<img src='https://raw.githubusercontent.com/Code-Y/redux-fluent/master/redux-fluent-typescript-definitions.gif' height='356' alt='Redux Fluent' aria-label='Use redux-fluent for a typesafe developer experience' />
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc