Skip to content

Commit

Permalink
fix(actionCreator): Renamed ActionInstance for ActionDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
iskandersierra committed Oct 22, 2016
1 parent fcf4a15 commit 601bbac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rxstore",
"version": "1.2.0",
"version": "1.2.1",
"description": "Redux-like store implemented with RxJS",
"main": "dist/main.js",
"typings": "dist/main.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/actionCreator.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import {
Action, Dispatcher, Reducer, ActionCreator,
EmptyReducer, EmptyActionInstance, TypedReducer, TypedActionInstance,
EmptyReducer, EmptyActionDescription, TypedReducer, TypedActionDescription,
} from "./interfaces";
import "object-assign";
import objectAssign = require("object-assign");

export function actionCreator<TState>(nameSpace: string): ActionCreator<TState> {
const untyped = (type: string, reducer?: EmptyReducer<TState>)
: EmptyActionInstance<TState> => {
: EmptyActionDescription<TState> => {
const scopedName = nameSpace + type;
const create = (): Action => ({ type: scopedName });
const dispatchOn = (disp: Dispatcher) => disp(create());
return { kind: "empty", type: scopedName, create, dispatchOn, reducer };
};
const of = <T>(type: string, reducer?: TypedReducer<TState, T>)
: TypedActionInstance<TState, T> => {
: TypedActionDescription<TState, T> => {
const scopedName = nameSpace + type;
const create = (payload: T): Action => ({ type: scopedName, payload });
const dispatchOn = (payload: T, disp: Dispatcher) => disp(create(payload));
Expand Down
13 changes: 7 additions & 6 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,21 @@ export type EffectsFactory<TStore> =

export type StoreMiddleware<TStore> = (store: TStore) => TStore;

export type EmptyReducer<TState> = (state: TState) => TState;
export type EmptyReducer<TState> =
(state: TState) => TState;

export type TypedReducer<TState, TPayload> =
(state: TState, payload: TPayload) => TState;

export interface EmptyActionInstance<TState> {
export interface EmptyActionDescription<TState> {
kind: "empty";
type: string;
create: () => Action;
dispatchOn: (dispatch: Dispatcher) => void;
reducer: EmptyReducer<TState> | undefined;
}

export interface TypedActionInstance<TState, TPayload> {
export interface TypedActionDescription<TState, TPayload> {
kind: "typed";
type: string;
create: (payload: TPayload) => Action;
Expand All @@ -73,11 +74,11 @@ export interface TypedActionInstance<TState, TPayload> {
}

export interface ActionCreator<TState> {
(type: string, reducer?: EmptyReducer<TState>): EmptyActionInstance<TState>;
(type: string, reducer?: EmptyReducer<TState>): EmptyActionDescription<TState>;

of<T>(type: string, reducer?: TypedReducer<TState, T>): TypedActionInstance<TState, T>;
of<T>(type: string, reducer?: TypedReducer<TState, T>): TypedActionDescription<TState, T>;
}

export interface ActionInstanceMapping<TState> {
[type: string]: EmptyActionInstance<TState> | TypedActionInstance<TState, any>;
[type: string]: EmptyActionDescription<TState> | TypedActionDescription<TState, any>;
}

0 comments on commit 601bbac

Please sign in to comment.