Skip to content

Commit

Permalink
fix: add ts types
Browse files Browse the repository at this point in the history
  • Loading branch information
wxnet2013 committed Oct 9, 2018
1 parent 732b3ca commit 80db3f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ export interface Model {
epics?: EpicsMapObject,
}

export interface Unsubscribe {
(): void
}

export interface RxLoopInstance {
model: (model: Model) => void,
stream: (modelName: String) => Observable<any>,
dispatch: (action: Action) => void,
subscribe: (listener: () => void) => Unsubscribe,
getState: (modelName: String) => any,
next: (action: Action) => void,
start: () => void,
Expand Down
6 changes: 3 additions & 3 deletions src/rxloop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Subject, BehaviorSubject, throwError, combineLatest } from "rxjs";
import { filter, scan, map, publishReplay, refCount, catchError } from "rxjs/operators";
import invariant from 'invariant';
import checkModel from './check-model';
import { isFunction } from './utils';
import { isFunction, noop } from './utils';
import initPlugins from './plugins';

export function rxloop( config = {} ) {
Expand Down Expand Up @@ -187,7 +187,7 @@ export function rxloop( config = {} ) {
return _state;
}

function subscribe(listener = () => {}) {
function subscribe(listener = noop) {
invariant(
isFunction(listener),
'Expected the listener to be a function',
Expand Down Expand Up @@ -231,7 +231,7 @@ export function rxloop( config = {} ) {
);
}

function createReducer(action = {}, reducer = () => {}) {
function createReducer(action = {}, reducer = noop) {
return (state) => reducer(state, action);
}

Expand Down
1 change: 1 addition & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as isPlainObject } from 'is-plain-object';
export const isFunction = o => Object.prototype.toString.call(o) === '[object Function]';
export const isAllFunction = o => Object.keys(o).every(key => isFunction(o[key]));
export const noop = () => {};

0 comments on commit 80db3f9

Please sign in to comment.