addint definitions for @tinajs/tina-redux (#27231)

This commit is contained in:
Jiayu Liu
2018-07-31 02:20:51 +08:00
committed by Sheetal Nandi
parent 16b85f0e2f
commit 057310a95d
6 changed files with 105 additions and 0 deletions

1
.github/CODEOWNERS vendored
View File

@@ -4293,6 +4293,7 @@
/types/timer-machine/ @dolanmiu
/types/timezone-js/ @bonnici
/types/tinajs__tina/ @Jimexist
/types/tinajs__tina-redux/ @Jimexist
/types/tinder/ @pingec
/types/tiny-slider-react/ @screendriver
/types/tinycolor2/ @M-Zuber @geertjansen @nvh

23
types/tinajs__tina-redux/index.d.ts vendored Normal file
View File

@@ -0,0 +1,23 @@
// Type definitions for @tinajs/tina-redux 1.4
// Project: https://github.com/tinajs/tina-redux
// Definitions by: Jiayu Liu <https://github.com/Jimexist>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/tinajs__tina-redux
// TypeScript Version: 2.3
import { Store, Dispatch } from "redux";
type MapStateToProps = (state: any) => any;
type mapDispatchToProps = (dispatch: Dispatch) => any;
interface HOC {
onLoad: () => void;
onUnload: () => void;
methods: object;
}
declare class TinaRedux {
constructor(reduxStore: Store);
connect(mapState?: MapStateToProps, mapDispatch?: mapDispatchToProps): HOC;
}
export = TinaRedux;

View File

@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"redux": "^4.0.0"
}
}

View File

@@ -0,0 +1,51 @@
import { createStore, combineReducers, Action } from "redux";
import TinaRedux from "@tinajs/tina-redux";
interface Todo {
id: number;
text: string;
completed: boolean;
}
interface TodoAction extends Action, Todo {}
const intialState: Todo[] = [
{ id: 1, text: "Star Tina.js", completed: false },
{ id: 2, text: "Star Tina-Redux", completed: true },
{ id: 3, text: "Build a mini-program with Tina.js", completed: false },
{ id: 4, text: "Add to Showcase of Tina.js", completed: false }
];
const todos = (state = intialState, action: TodoAction) => {
switch (action.type) {
case "ADD_TODO":
return [
...state,
{
id: action.id,
text: action.text,
completed: false
}
];
case "TOGGLE_TODO":
return state.map(
todo =>
todo.id === action.id
? { ...todo, completed: !todo.completed }
: todo
);
case "CLEAR_COMPLETED_TODOS":
return state.filter(todo => !todo.completed);
default:
return state;
}
};
const todoApp = combineReducers({
todos
});
const reduxStore = createStore(todoApp);
const store = new TinaRedux(reduxStore);
export default store;

View File

@@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@tinajs/tina": ["tinajs__tina"],
"@tinajs/tina-redux": ["tinajs__tina-redux"]
}
},
"files": ["index.d.ts", "tinajs__tina-redux-tests.ts"]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}