Skip to content

Commit 1bc5362

Browse files
committed
Rename package to typescript-fsa; remove redux dependency
1 parent d3a7e97 commit 1bc5362

17 files changed

+363
-2021
lines changed

.babelrc

-3
This file was deleted.

README.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Redux TypeScript Actions [![npm version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]
1+
# TypeScript FSA [![npm version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]
22

33
A simple Action Creator library for TypeScript. Its goal is to provide simple
4-
yet type-safe experience with Redux actions.
4+
yet type-safe experience with Flux actions.
55
Created actions are FSA-compliant:
66

77
```ts
@@ -16,15 +16,15 @@ interface Action<P> {
1616
## Installation
1717

1818
```
19-
npm install --save redux-typescript-actions
19+
npm install --save typescript-fsa
2020
```
2121

2222
## Usage
2323

2424
### Basic
2525

2626
```ts
27-
import actionCreatorFactory from 'redux-typescript-actions';
27+
import actionCreatorFactory from 'typescript-fsa';
2828

2929
const actionCreator = actionCreatorFactory();
3030

@@ -45,7 +45,7 @@ Async Action Creators are objects with properties `started`, `done` and
4545
`failed` whose values are action creators.
4646

4747
```ts
48-
import actionCreatorFactory from 'redux-typescript-actions';
48+
import actionCreatorFactory from 'typescript-fsa';
4949

5050
const actionCreator = actionCreatorFactory();
5151

@@ -86,7 +86,7 @@ convenient to keep actions near the component that dispatches them.
8686
8787
```ts
8888
// MyComponent.actions.ts
89-
import actionCreatorFactory from 'redux-typescript-actions';
89+
import actionCreatorFactory from 'typescript-fsa';
9090

9191
const actionCreator = actionCreatorFactory('MyComponent');
9292

@@ -97,11 +97,11 @@ console.log(action);
9797
// {type: 'MyComponent/SOMETHING_HAPPENED', payload: {foo: 'bar'}}
9898
```
9999
100-
### Reducers
100+
### Redux
101101
102102
```ts
103103
// actions.ts
104-
import actionCreatorFactory from 'redux-typescript-actions';
104+
import actionCreatorFactory from 'typescript-fsa';
105105

106106
const actionCreator = actionCreatorFactory();
107107

@@ -110,13 +110,13 @@ export const somethingHappened =
110110

111111

112112
// reducer.ts
113-
import {Action as ReduxAction} from 'redux';
114-
import {isType, Action} from 'redux-typescript-actions';
113+
import {Action} from 'redux';
114+
import {isType} from 'typescript-fsa';
115115
import {somethingHappened} from './actions';
116116

117117
type State = {bar: string};
118118

119-
const reducer = (state: State, action: ReduxAction): State => {
119+
const reducer = (state: State, action: Action): State => {
120120
if (isType(action, somethingHappened)) {
121121
// action.payload is inferred as {foo: string};
122122

@@ -154,7 +154,7 @@ if (isType(action, somethingHappened)) {
154154
}
155155
```
156156
157-
[npm-image]: https://badge.fury.io/js/redux-typescript-actions.svg
158-
[npm-url]: https://badge.fury.io/js/redux-typescript-actions
159-
[travis-image]: https://travis-ci.org/aikoven/redux-typescript-actions.svg?branch=master
160-
[travis-url]: https://travis-ci.org/aikoven/redux-typescript-actions
157+
[npm-image]: https://badge.fury.io/js/typescript-fsa.svg
158+
[npm-url]: https://badge.fury.io/js/typescript-fsa
159+
[travis-image]: https://travis-ci.org/aikoven/typescript-fsa.svg?branch=master
160+
[travis-url]: https://travis-ci.org/aikoven/typescript-fsa

es/index.d.ts

-37
This file was deleted.

es/index.js

-37
This file was deleted.

es/sagas.d.ts

-15
This file was deleted.

es/sagas.js

-42
This file was deleted.

lib/index.d.ts

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { Action as ReduxAction } from "redux";
2-
export interface Action<P> extends ReduxAction {
1+
export interface AnyAction {
2+
type: any;
3+
}
4+
export interface Action<P> extends AnyAction {
35
type: string;
46
payload: P;
57
error?: boolean;
6-
meta?: Object;
8+
meta?: Object | null;
79
}
810
export interface Success<P, S> {
911
params: P;
@@ -13,13 +15,13 @@ export interface Failure<P, E> {
1315
params: P;
1416
error: E;
1517
}
16-
export declare function isType<P>(action: ReduxAction, actionCreator: ActionCreator<P>): action is Action<P>;
18+
export declare function isType<P>(action: AnyAction, actionCreator: ActionCreator<P>): action is Action<P>;
1719
export interface ActionCreator<P> {
1820
type: string;
19-
(payload: P, meta?: Object): Action<P>;
21+
(payload: P, meta?: Object | null): Action<P>;
2022
}
2123
export interface EmptyActionCreator extends ActionCreator<undefined> {
22-
(payload?: undefined, meta?: Object): Action<undefined>;
24+
(payload?: undefined, meta?: Object | null): Action<undefined>;
2325
}
2426
export interface AsyncActionCreators<P, S, E> {
2527
type: string;
@@ -28,10 +30,10 @@ export interface AsyncActionCreators<P, S, E> {
2830
failed: ActionCreator<Failure<P, E>>;
2931
}
3032
export interface ActionCreatorFactory {
31-
(type: string, commonMeta?: Object, error?: boolean): EmptyActionCreator;
32-
<P>(type: string, commonMeta?: Object, isError?: boolean): ActionCreator<P>;
33-
<P>(type: string, commonMeta?: Object, isError?: (payload: P) => boolean): ActionCreator<P>;
34-
async<P, S>(type: string, commonMeta?: Object): AsyncActionCreators<P, S, any>;
35-
async<P, S, E>(type: string, commonMeta?: Object): AsyncActionCreators<P, S, E>;
33+
(type: string, commonMeta?: Object | null, error?: boolean): EmptyActionCreator;
34+
<P>(type: string, commonMeta?: Object | null, isError?: boolean): ActionCreator<P>;
35+
<P>(type: string, commonMeta?: Object | null, isError?: (payload: P) => boolean): ActionCreator<P>;
36+
async<P, S>(type: string, commonMeta?: Object | null): AsyncActionCreators<P, S, any>;
37+
async<P, S, E>(type: string, commonMeta?: Object | null): AsyncActionCreators<P, S, E>;
3638
}
37-
export default function actionCreatorFactory(prefix?: string, defaultIsError?: (payload: any) => boolean): ActionCreatorFactory;
39+
export default function actionCreatorFactory(prefix?: string | null, defaultIsError?: (payload: any) => boolean): ActionCreatorFactory;

lib/index.js

+16-22
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
1-
'use strict';
2-
3-
Object.defineProperty(exports, "__esModule", {
4-
value: true
5-
});
6-
exports.isType = isType;
7-
exports.default = actionCreatorFactory;
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
83
function isType(action, actionCreator) {
94
return action.type === actionCreator.type;
105
}
11-
function actionCreatorFactory(prefix) {
12-
var defaultIsError = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (p) {
13-
return p instanceof Error;
14-
};
15-
6+
exports.isType = isType;
7+
function actionCreatorFactory(prefix, defaultIsError) {
8+
if (defaultIsError === void 0) { defaultIsError = function (p) { return p instanceof Error; }; }
169
var actionTypes = {};
17-
var base = prefix ? prefix + '/' : "";
18-
function actionCreator(type, commonMeta) {
19-
var isError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultIsError;
20-
10+
var base = prefix ? prefix + "/" : "";
11+
function actionCreator(type, commonMeta, isError) {
12+
if (isError === void 0) { isError = defaultIsError; }
2113
var fullType = base + type;
2214
if (process.env.NODE_ENV !== 'production') {
23-
if (actionTypes[fullType]) throw new Error('Duplicate action type: ' + fullType);
15+
if (actionTypes[fullType])
16+
throw new Error("Duplicate action type: " + fullType);
2417
actionTypes[fullType] = true;
2518
}
2619
return Object.assign(function (payload, meta) {
2720
var action = {
2821
type: fullType,
29-
payload: payload
22+
payload: payload,
3023
};
3124
if (commonMeta || meta) {
3225
action.meta = Object.assign({}, commonMeta, meta);
@@ -40,10 +33,11 @@ function actionCreatorFactory(prefix) {
4033
function asyncActionCreators(type, commonMeta) {
4134
return {
4235
type: base + type,
43-
started: actionCreator(type + '_STARTED', commonMeta, false),
44-
done: actionCreator(type + '_DONE', commonMeta, false),
45-
failed: actionCreator(type + '_FAILED', commonMeta, true)
36+
started: actionCreator(type + "_STARTED", commonMeta, false),
37+
done: actionCreator(type + "_DONE", commonMeta, false),
38+
failed: actionCreator(type + "_FAILED", commonMeta, true),
4639
};
4740
}
4841
return Object.assign(actionCreator, { async: asyncActionCreators });
49-
}
42+
}
43+
exports.default = actionCreatorFactory;

lib/sagas.d.ts

-15
This file was deleted.

0 commit comments

Comments
 (0)