Skip to content

Commit

Permalink
增加effects, subscriptions, reducers的interface
Browse files Browse the repository at this point in the history
  • Loading branch information
nikogu committed Oct 10, 2016
1 parent 9084fe7 commit 4668681
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 26 deletions.
19 changes: 15 additions & 4 deletions examples/count-ts/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,27 @@ import { RouterRedux } from 'dva/router';
// 1. Initialize
const app = dva();

const delay = ()=>{};
const key = (x,y)=>{};

// 2. Model
app.model({
namespace: 'count',
state: 0,
reducers: {
add (count) {
return count + 1
add(state) { return state + 1; },
minus(state) { return state - 1; },
},
effects: {
*addDelay(action, { call, put }) {
yield call(delay, 1000);
yield put({ type: 'add' });
},
minus(count) {
return count - 1
},
subscriptions: {
// Monitor keyboard input
keyboard({ dispatch }) {
return key('ctrl+up', () => { dispatch({ type: 'addDelay'}); });
},
},
});
Expand Down
40 changes: 29 additions & 11 deletions examples/count-ts/typings/globals/dva/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,28 @@
// Project: dva
// Definitions by: dva <https://github.com/dvajs/dva>

declare namespace 'dva' {
/*
* @refer https://github.com/reactjs/redux/blob/master/index.d.ts
* @template S State object type.
*/
export interface Action {
type: any;
}
export type Reducer<S> = <A extends Action>(state: S, action: A) => S;
export type Effect<S> = <A extends Action>(action: A, saga:{ call?:Function, put?:Function, select?:Function }) => S;
export type Subscription<any> = <any>(signature: {dispatch?:Function, history:Function})=>void;

interface Reducers {
Reducer: Reducer
}
interface Effects {
Effect: Effect
}
interface Subscriptions {
Subscription: Subscription
}

/** connecting Container Components */
export function connect(maps:Object):Function;
declare namespace 'dva' {

export default function dva(opts?:Object):{

Expand Down Expand Up @@ -54,11 +72,11 @@ declare namespace 'dva' {
*
*/
model: (model:{
namespace: String,
state: Object,
reducers?: Object,
effects?: Object,
subscriptions?: Object,
namespace: string,
state: any,
reducers?: Reducers,
effects?: Effects,
subscriptions?: Subscriptions,
})=>void,

/**
Expand All @@ -73,11 +91,11 @@ declare namespace 'dva' {
*
* To Connect Models on Components
*
* @example
* `export default connect(state => state)(Components)`
* @refer
* https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options
*
*/
export function connect(map:Function):Function;
export function connect(mapStateToProps?:Object, mapDispatchToProps?:Object, mergeProps?:Object, options?:Object):Function;
}

/**
Expand Down
40 changes: 29 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,28 @@
// Project: dva
// Definitions by: dva <https://github.com/dvajs/dva>

declare namespace 'dva' {
/*
* @refer https://github.com/reactjs/redux/blob/master/index.d.ts
* @template S State object type.
*/
export interface Action {
type: any;
}
export type Reducer<S> = <A extends Action>(state: S, action: A) => S;
export type Effect<S> = <A extends Action>(action: A, saga:{ call?:Function, put?:Function, select?:Function }) => S;
export type Subscription<any> = <any>(signature: {dispatch?:Function, history:Function})=>void;

interface Reducers {
Reducer: Reducer
}
interface Effects {
Effect: Effect
}
interface Subscriptions {
Subscription: Subscription
}

/** connecting Container Components */
export function connect(maps:Object):Function;
declare namespace 'dva' {

export default function dva(opts?:Object):{

Expand Down Expand Up @@ -54,11 +72,11 @@ declare namespace 'dva' {
*
*/
model: (model:{
namespace: String,
state: Object,
reducers?: Object,
effects?: Object,
subscriptions?: Object,
namespace: string,
state: any,
reducers?: Reducers,
effects?: Effects,
subscriptions?: Subscriptions,
})=>void,

/**
Expand All @@ -73,11 +91,11 @@ declare namespace 'dva' {
*
* To Connect Models on Components
*
* @example
* `export default connect(state => state)(Components)`
* @refer
* https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options
*
*/
export function connect(map:Function):Function;
export function connect(mapStateToProps?:Object, mapDispatchToProps?:Object, mergeProps?:Object, options?:Object):Function;
}

/**
Expand Down

0 comments on commit 4668681

Please sign in to comment.