Skip to content

Commit

Permalink
Merge ca14f43 into 58c27b6
Browse files Browse the repository at this point in the history
  • Loading branch information
nikogu committed Oct 10, 2016
2 parents 58c27b6 + ca14f43 commit b634b9d
Show file tree
Hide file tree
Showing 17 changed files with 3,093 additions and 1 deletion.
4 changes: 4 additions & 0 deletions examples/count-ts/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mock
proxy.config.js
webpack.config.js

21 changes: 21 additions & 0 deletions examples/count-ts/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "eslint-config-airbnb",
"rules": {
"no-useless-computed-key": 0,
"strict": 0,
"func-names": 0,
"space-before-function-paren": [0, "always"],

// Disable until Flow supports let and const
"no-var": 0,
"vars-on-top": 0,

// Disable comma-dangle unless need to support it
"comma-dangle": 0,
"consistent-return": 1,
"no-return-assign": 0,
"no-extend-native": 1
},
"parser": "babel-eslint"
}

36 changes: 36 additions & 0 deletions examples/count-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"private": true,
"entry": {
"index": "./src/index.tsx"
},
"dependencies": {
"dva": "^1.0.0",
"react": "^15.1.0",
"react-dom": "^15.1.0"
},
"devDependencies": {
"atool-build": "^0.7.6",
"babel-eslint": "^6.0.4",
"babel-plugin-antd": "^0.4.0",
"babel-plugin-dva-hmr": "^0.1.0",
"babel-plugin-transform-runtime": "^6.9.0",
"babel-runtime": "^6.9.2",
"dora": "0.3.x",
"dora-plugin-proxy": "^0.7.0",
"dora-plugin-webpack": "0.6.x",
"dora-plugin-webpack-hmr": "^0.1.0",
"eslint": "^2.13.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.8.1",
"eslint-plugin-jsx-a11y": "^1.4.2",
"eslint-plugin-react": "^5.1.1",
"glob": "^7.0.5",
"mockjs": "^1.0.1-beta2",
"redbox-react": "^1.2.10"
},
"scripts": {
"start": "dora --plugins \"proxy,webpack,webpack-hmr\"",
"lint": "eslint --fix --ext .js,.jsx .",
"build": "atool-build"
}
}
16 changes: 16 additions & 0 deletions examples/count-ts/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo</title>
<link rel="stylesheet" href="index.css" />
</head>
<body>

<div id="root"></div>

<script src="common.js"></script>
<script src="index.js"></script>

</body>
</html>
6 changes: 6 additions & 0 deletions examples/count-ts/src/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

:global {
html, body, #root {
height: 100%;
}
}
60 changes: 60 additions & 0 deletions examples/count-ts/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import './index.html';
import './index.less';
import * as React from "react";
import * as ReactDOM from "react-dom";

import dva from 'dva';
import { connect } from 'dva';
import { Router, Route } from 'dva/router';
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(state) { return state + 1; },
minus(state) { return state - 1; },
},
effects: {
*addDelay(action, { call, put }) {
yield call(delay, 1000);
yield put({ type: 'add' });
},
},
subscriptions: {
// Monitor keyboard input
keyboard({ dispatch }) {
return key('ctrl+up', () => { dispatch({ type: 'addDelay'}); });
},
},
});

// 3. View
const App = connect(({ count }) => ({
count
}))(function (props) {
return (
<div>
<h2>{ props.count }</h2>
<button key="add" onClick={() => { props.dispatch({type: 'count/add'})}}>+</button>
<button key="minus" onClick={() => { props.dispatch({type: 'count/minus'})}}>-</button>
</div>
);
});

// 4. Router
app.router(({ history }) =>
<Router history={history}>
<Route path="/" component={App}/>
</Router>
);

// 5. Start
app.start('#root');
6 changes: 6 additions & 0 deletions examples/count-ts/typings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"globalDependencies": {
"react": "registry:dt/react#0.14.0+20160817201227",
"react-dom": "registry:dt/react-dom#0.14.0+20160412154040"
}
}
143 changes: 143 additions & 0 deletions examples/count-ts/typings/globals/dva/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// Type definitions for dva 1.0.0
// Project: dva
// Definitions by: dva <https://github.com/dvajs/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<Function> = <Function>(signature: {dispatch?:Function, history:Function})=>void;

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

declare namespace 'dva' {

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

/**
*
* Register an object of hooks on the application.
* Support these hooks:
* onError(fn): called when an effect or subscription emit an error
* onAction(array|fn): called when an action is dispatched, used for registering redux middleware, support Array for convenience
* onStateChange(fn): called after a reducer changes the state
* onReducer(fn): used for apply reducer enhancer
* onEffect(fn): used for wrapping effect to add custom behavior, e.g. dva-loading for automatical loading state
* onHmr(fn): used for hot module replacement
* extraReducers(object): used for adding extra reducers, e.g. redux-form needs extra form reducer
*
*/
use: (hooks:{
onError(fn:Function),
onAction(actions:Function | Array),
onStateChange(fn:Function),
onReducer(fn:Function),
onEffect(fn:Function),
onHmr(fn:Function),
extraReducers(reducer:Object)
})=>void,

/**
*
* Start the application. selector is optional. If no selector arguments, it will return a function that return JSX elements.
*
*/
start: (selector?:HTMLElement | String)=>void,

/*
*
* Create a new model. Takes the following arguments:
* namespace: namespace the model
* state: initial value
* reducers: synchronous operations that modify state. Triggered by actions. Signature of (state, action) => state, same as Redux.
* effects: asynchronous operations that don't modify state directly. Triggered by actions, can call actions. Signature of (action, { put, call, select }),
* subscriptions: asynchronous read-only operations that don't modify state directly. Can call actions. Signature of ({ dispatch, history }).
*
* put(action) in effects, and dispatch(action) in subscriptions
*
* Send a new action to the models. put in effects is the same as dispatch in subscriptions.
*
*/
model: (model:{
namespace: string,
state: any,
reducers?: Reducers,
effects?: Effects,
subscriptions?: Subscriptions,
})=>void,

/**
*
* Config router. Takes a function with arguments { history }, and expects router config. It use the same api as react-router, return jsx elements or JavaScript Object for dynamic routing.
*
*/
router: (router:JSX.Element|Function)=>JSX.Element,
};

/**
*
* To Connect Models on Components
*
* @refer
* https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options
*
*/
export function connect(mapStateToProps?:Object, mapDispatchToProps?:Object, mergeProps?:Object, options?:Object):Function;
}

/**
* https://github.com/reactjs/react-router
*/
declare module 'dva/router' {
import React = __React;
interface RouterProps {
history?: Object
}
export class Router extends React.Component<RouterProps, {}> {
render():JSX.Element
}
interface RouteProps {
path?: string,
component?: React.ReactNode
}
export class Route extends React.Component<RouteProps, {}> {
render():JSX.Element
}

/**
* https://github.com/reactjs/react-router-redux
*/
interface RouterRedux {
routerStateReducer: Function,
ReduxRouter: Function,
reduxReactRouter: Function,
isActive: Function,
historyAPI: Function,
push: Function,
replace: Function,
setState: Function,
go: Function,
goBack: Function,
goForward: Function,
}
}

/**
* https://github.com/fis-components/whatwg-fetch
*/
declare module 'dva/fetch' {
export default Function;
}
4 changes: 4 additions & 0 deletions examples/count-ts/typings/globals/dva/typings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"resolution": "main",
"tree": {}
}
70 changes: 70 additions & 0 deletions examples/count-ts/typings/globals/react-dom/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Generated by typings
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/b9642fb8ac07f7164dc643ddd1fa99b58ae9be8b/react/react-dom.d.ts
declare namespace __React {
namespace __DOM {
function findDOMNode<E extends Element>(instance: ReactInstance): E;
function findDOMNode(instance: ReactInstance): Element;

function render<P extends DOMAttributes, T extends Element>(
element: DOMElement<P, T>,
container: Element,
callback?: (element: T) => any): T;
function render<P>(
element: SFCElement<P>,
container: Element,
callback?: () => any): void;
function render<P, T extends Component<P, ComponentState>>(
element: CElement<P, T>,
container: Element,
callback?: (component: T) => any): T;
function render<P>(
element: ReactElement<P>,
container: Element,
callback?: (component?: Component<P, ComponentState> | Element) => any): Component<P, ComponentState> | Element | void;

function unmountComponentAtNode(container: Element): boolean;

var version: string;

function unstable_batchedUpdates<A, B>(callback: (a: A, b: B) => any, a: A, b: B): void;
function unstable_batchedUpdates<A>(callback: (a: A) => any, a: A): void;
function unstable_batchedUpdates(callback: () => any): void;

function unstable_renderSubtreeIntoContainer<P extends DOMAttributes, T extends Element>(
parentComponent: Component<any, any>,
element: DOMElement<P, T>,
container: Element,
callback?: (element: T) => any): T;
function unstable_renderSubtreeIntoContainer<P, T extends Component<P, ComponentState>>(
parentComponent: Component<any, any>,
element: CElement<P, T>,
container: Element,
callback?: (component: T) => any): T;
function render<P>(
parentComponent: Component<any, any>,
element: SFCElement<P>,
container: Element,
callback?: () => any): void;
function unstable_renderSubtreeIntoContainer<P>(
parentComponent: Component<any, any>,
element: ReactElement<P>,
container: Element,
callback?: (component?: Component<P, ComponentState> | Element) => any): Component<P, ComponentState> | Element | void;
}

namespace __DOMServer {
function renderToString(element: ReactElement<any>): string;
function renderToStaticMarkup(element: ReactElement<any>): string;
var version: string;
}
}

declare module "react-dom" {
import DOM = __React.__DOM;
export = DOM;
}

declare module "react-dom/server" {
import DOMServer = __React.__DOMServer;
export = DOMServer;
}
8 changes: 8 additions & 0 deletions examples/count-ts/typings/globals/react-dom/typings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"resolution": "main",
"tree": {
"src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/b9642fb8ac07f7164dc643ddd1fa99b58ae9be8b/react/react-dom.d.ts",
"raw": "registry:dt/react-dom#0.14.0+20160412154040",
"typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/b9642fb8ac07f7164dc643ddd1fa99b58ae9be8b/react/react-dom.d.ts"
}
}
Loading

0 comments on commit b634b9d

Please sign in to comment.