From 80db3f96af5e93374b818193007e9cee563e6b99 Mon Sep 17 00:00:00 2001 From: wxnet2013 Date: Wed, 10 Oct 2018 00:26:08 +0800 Subject: [PATCH] fix: add ts types --- index.d.ts | 5 +++++ src/rxloop.js | 6 +++--- src/utils.js | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index e11545e..a62db43 100644 --- a/index.d.ts +++ b/index.d.ts @@ -25,10 +25,15 @@ export interface Model { epics?: EpicsMapObject, } +export interface Unsubscribe { + (): void +} + export interface RxLoopInstance { model: (model: Model) => void, stream: (modelName: String) => Observable, dispatch: (action: Action) => void, + subscribe: (listener: () => void) => Unsubscribe, getState: (modelName: String) => any, next: (action: Action) => void, start: () => void, diff --git a/src/rxloop.js b/src/rxloop.js index 69d0adc..3fe9262 100644 --- a/src/rxloop.js +++ b/src/rxloop.js @@ -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 = {} ) { @@ -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', @@ -231,7 +231,7 @@ export function rxloop( config = {} ) { ); } - function createReducer(action = {}, reducer = () => {}) { + function createReducer(action = {}, reducer = noop) { return (state) => reducer(state, action); } diff --git a/src/utils.js b/src/utils.js index d8ad3e9..b6f77ba 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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 = () => {};