Skip to content

Commit

Permalink
Rename package to typescript-fsa; remove redux dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
aikoven committed Mar 3, 2017
1 parent d3a7e97 commit 1bc5362
Show file tree
Hide file tree
Showing 17 changed files with 363 additions and 2,021 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Redux TypeScript Actions [![npm version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]
# TypeScript FSA [![npm version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]

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

```ts
Expand All @@ -16,15 +16,15 @@ interface Action<P> {
## Installation

```
npm install --save redux-typescript-actions
npm install --save typescript-fsa
```

## Usage

### Basic

```ts
import actionCreatorFactory from 'redux-typescript-actions';
import actionCreatorFactory from 'typescript-fsa';

const actionCreator = actionCreatorFactory();

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

```ts
import actionCreatorFactory from 'redux-typescript-actions';
import actionCreatorFactory from 'typescript-fsa';

const actionCreator = actionCreatorFactory();

Expand Down Expand Up @@ -86,7 +86,7 @@ convenient to keep actions near the component that dispatches them.
```ts
// MyComponent.actions.ts
import actionCreatorFactory from 'redux-typescript-actions';
import actionCreatorFactory from 'typescript-fsa';

const actionCreator = actionCreatorFactory('MyComponent');

Expand All @@ -97,11 +97,11 @@ console.log(action);
// {type: 'MyComponent/SOMETHING_HAPPENED', payload: {foo: 'bar'}}
```
### Reducers
### Redux
```ts
// actions.ts
import actionCreatorFactory from 'redux-typescript-actions';
import actionCreatorFactory from 'typescript-fsa';

const actionCreator = actionCreatorFactory();

Expand All @@ -110,13 +110,13 @@ export const somethingHappened =


// reducer.ts
import {Action as ReduxAction} from 'redux';
import {isType, Action} from 'redux-typescript-actions';
import {Action} from 'redux';
import {isType} from 'typescript-fsa';
import {somethingHappened} from './actions';

type State = {bar: string};

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

Expand Down Expand Up @@ -154,7 +154,7 @@ if (isType(action, somethingHappened)) {
}
```
[npm-image]: https://badge.fury.io/js/redux-typescript-actions.svg
[npm-url]: https://badge.fury.io/js/redux-typescript-actions
[travis-image]: https://travis-ci.org/aikoven/redux-typescript-actions.svg?branch=master
[travis-url]: https://travis-ci.org/aikoven/redux-typescript-actions
[npm-image]: https://badge.fury.io/js/typescript-fsa.svg
[npm-url]: https://badge.fury.io/js/typescript-fsa
[travis-image]: https://travis-ci.org/aikoven/typescript-fsa.svg?branch=master
[travis-url]: https://travis-ci.org/aikoven/typescript-fsa
37 changes: 0 additions & 37 deletions es/index.d.ts

This file was deleted.

37 changes: 0 additions & 37 deletions es/index.js

This file was deleted.

15 changes: 0 additions & 15 deletions es/sagas.d.ts

This file was deleted.

42 changes: 0 additions & 42 deletions es/sagas.js

This file was deleted.

26 changes: 14 additions & 12 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Action as ReduxAction } from "redux";
export interface Action<P> extends ReduxAction {
export interface AnyAction {
type: any;
}
export interface Action<P> extends AnyAction {
type: string;
payload: P;
error?: boolean;
meta?: Object;
meta?: Object | null;
}
export interface Success<P, S> {
params: P;
Expand All @@ -13,13 +15,13 @@ export interface Failure<P, E> {
params: P;
error: E;
}
export declare function isType<P>(action: ReduxAction, actionCreator: ActionCreator<P>): action is Action<P>;
export declare function isType<P>(action: AnyAction, actionCreator: ActionCreator<P>): action is Action<P>;
export interface ActionCreator<P> {
type: string;
(payload: P, meta?: Object): Action<P>;
(payload: P, meta?: Object | null): Action<P>;
}
export interface EmptyActionCreator extends ActionCreator<undefined> {
(payload?: undefined, meta?: Object): Action<undefined>;
(payload?: undefined, meta?: Object | null): Action<undefined>;
}
export interface AsyncActionCreators<P, S, E> {
type: string;
Expand All @@ -28,10 +30,10 @@ export interface AsyncActionCreators<P, S, E> {
failed: ActionCreator<Failure<P, E>>;
}
export interface ActionCreatorFactory {
(type: string, commonMeta?: Object, error?: boolean): EmptyActionCreator;
<P>(type: string, commonMeta?: Object, isError?: boolean): ActionCreator<P>;
<P>(type: string, commonMeta?: Object, isError?: (payload: P) => boolean): ActionCreator<P>;
async<P, S>(type: string, commonMeta?: Object): AsyncActionCreators<P, S, any>;
async<P, S, E>(type: string, commonMeta?: Object): AsyncActionCreators<P, S, E>;
(type: string, commonMeta?: Object | null, error?: boolean): EmptyActionCreator;
<P>(type: string, commonMeta?: Object | null, isError?: boolean): ActionCreator<P>;
<P>(type: string, commonMeta?: Object | null, isError?: (payload: P) => boolean): ActionCreator<P>;
async<P, S>(type: string, commonMeta?: Object | null): AsyncActionCreators<P, S, any>;
async<P, S, E>(type: string, commonMeta?: Object | null): AsyncActionCreators<P, S, E>;
}
export default function actionCreatorFactory(prefix?: string, defaultIsError?: (payload: any) => boolean): ActionCreatorFactory;
export default function actionCreatorFactory(prefix?: string | null, defaultIsError?: (payload: any) => boolean): ActionCreatorFactory;
38 changes: 16 additions & 22 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isType = isType;
exports.default = actionCreatorFactory;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function isType(action, actionCreator) {
return action.type === actionCreator.type;
}
function actionCreatorFactory(prefix) {
var defaultIsError = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (p) {
return p instanceof Error;
};

exports.isType = isType;
function actionCreatorFactory(prefix, defaultIsError) {
if (defaultIsError === void 0) { defaultIsError = function (p) { return p instanceof Error; }; }
var actionTypes = {};
var base = prefix ? prefix + '/' : "";
function actionCreator(type, commonMeta) {
var isError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultIsError;

var base = prefix ? prefix + "/" : "";
function actionCreator(type, commonMeta, isError) {
if (isError === void 0) { isError = defaultIsError; }
var fullType = base + type;
if (process.env.NODE_ENV !== 'production') {
if (actionTypes[fullType]) throw new Error('Duplicate action type: ' + fullType);
if (actionTypes[fullType])
throw new Error("Duplicate action type: " + fullType);
actionTypes[fullType] = true;
}
return Object.assign(function (payload, meta) {
var action = {
type: fullType,
payload: payload
payload: payload,
};
if (commonMeta || meta) {
action.meta = Object.assign({}, commonMeta, meta);
Expand All @@ -40,10 +33,11 @@ function actionCreatorFactory(prefix) {
function asyncActionCreators(type, commonMeta) {
return {
type: base + type,
started: actionCreator(type + '_STARTED', commonMeta, false),
done: actionCreator(type + '_DONE', commonMeta, false),
failed: actionCreator(type + '_FAILED', commonMeta, true)
started: actionCreator(type + "_STARTED", commonMeta, false),
done: actionCreator(type + "_DONE", commonMeta, false),
failed: actionCreator(type + "_FAILED", commonMeta, true),
};
}
return Object.assign(actionCreator, { async: asyncActionCreators });
}
}
exports.default = actionCreatorFactory;
15 changes: 0 additions & 15 deletions lib/sagas.d.ts

This file was deleted.

Loading

0 comments on commit 1bc5362

Please sign in to comment.