mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +00:00
Remove redux-thunk (external) (#13162)
* Added export, tests to chart.js
fixes #12525
* Remove redux-thunk typing (external)
* Revert "Added export, tests to chart.js"
This reverts commit ef08762ba2.
This commit is contained in:
@@ -83,6 +83,12 @@
|
||||
"sourceRepoURL": "https://github.com/reactjs/redux",
|
||||
"asOfVersion": "3.6.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "Redux Thunk",
|
||||
"typingsPackageName": "redux-thunk",
|
||||
"sourceRepoURL": "https://github.com/gaearon/redux-thunk",
|
||||
"asOfVersion": "2.1.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "Normalizr",
|
||||
"typingsPackageName": "normalizr",
|
||||
|
||||
Vendored
-23
@@ -1,23 +0,0 @@
|
||||
// Type definitions for redux-thunk v2.1.0
|
||||
// Project: https://github.com/gaearon/redux-thunk
|
||||
// Definitions by: Qubo <https://github.com/tkqubo>, Kaur Kuut <https://github.com/xStrom>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import * as Redux from "redux";
|
||||
import { Middleware } from "redux";
|
||||
|
||||
export as namespace ReduxThunk;
|
||||
|
||||
declare const thunk: Middleware & {
|
||||
withExtraArgument(extraArgument: any): Middleware;
|
||||
};
|
||||
export default thunk;
|
||||
|
||||
declare module 'redux' {
|
||||
export type ThunkAction<R, S, E> = (dispatch: Dispatch<S>, getState: () => S, extraArgument: E) => R;
|
||||
|
||||
export interface Dispatch<S> {
|
||||
<R, E>(asyncAction: ThunkAction<R, S, E>): R;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"redux": "^3.6.0"
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
import { createStore, applyMiddleware, Store, Dispatch, ThunkAction } from 'redux';
|
||||
import thunk from 'redux-thunk';
|
||||
|
||||
declare var rootReducer: (state: any, action: any) => any;
|
||||
declare var fetch: any;
|
||||
|
||||
// create a store that has redux-thunk middleware enabled
|
||||
const createStoreWithMiddleware = applyMiddleware(
|
||||
thunk
|
||||
)(createStore);
|
||||
|
||||
const store: Store<any> = createStoreWithMiddleware(rootReducer);
|
||||
|
||||
function fetchSecretSauce() {
|
||||
return fetch('https://www.google.com/search?q=secret+sauce');
|
||||
}
|
||||
|
||||
// These are the normal action creators you have seen so far.
|
||||
// The actions they return can be dispatched without any middleware.
|
||||
// However, they only express “facts” and not the “async flow”.
|
||||
|
||||
function makeASandwich(forPerson: any, secretSauce?: any): any {
|
||||
return {
|
||||
type: 'MAKE_SANDWICH',
|
||||
forPerson,
|
||||
secretSauce
|
||||
};
|
||||
}
|
||||
|
||||
function apologize(fromPerson: any, toPerson?: any, error?: any): any {
|
||||
return {
|
||||
type: 'APOLOGIZE',
|
||||
fromPerson,
|
||||
toPerson,
|
||||
error
|
||||
};
|
||||
}
|
||||
|
||||
function withdrawMoney(amount: number): any {
|
||||
return {
|
||||
type: 'WITHDRAW',
|
||||
amount
|
||||
};
|
||||
}
|
||||
|
||||
// Even without middleware, you can dispatch an action:
|
||||
store.dispatch(withdrawMoney(100));
|
||||
|
||||
// But what do you do when you need to start an asynchronous action,
|
||||
// such as an API call, or a router transition?
|
||||
|
||||
// Meet thunks.
|
||||
// A thunk is a function that returns a function.
|
||||
// This is a thunk.
|
||||
|
||||
function makeASandwichWithSecretSauce(forPerson: any): ThunkAction<any, any, any> {
|
||||
// Invert control!
|
||||
// Return a function that accepts `dispatch` so we can dispatch later.
|
||||
// Thunk middleware knows how to turn thunk async actions into actions.
|
||||
|
||||
return function (dispatch: Dispatch<any>): any {
|
||||
return fetchSecretSauce().then(
|
||||
(sauce: any) => dispatch(makeASandwich(forPerson, sauce)),
|
||||
(error: any) => dispatch(apologize('The Sandwich Shop', forPerson, error))
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
// Thunk middleware lets me dispatch thunk async actions
|
||||
// as if they were actions!
|
||||
|
||||
store.dispatch(
|
||||
makeASandwichWithSecretSauce('Me')
|
||||
);
|
||||
|
||||
// It even takes care to return the thunk’s return value
|
||||
// from the dispatch, so I can chain Promises as long as I return them.
|
||||
|
||||
store.dispatch(
|
||||
makeASandwichWithSecretSauce('My wife')
|
||||
).then(() => {
|
||||
console.log('Done!');
|
||||
});
|
||||
|
||||
// In fact I can write action creators that dispatch
|
||||
// actions and async actions from other action creators,
|
||||
// and I can build my control flow with Promises.
|
||||
|
||||
function makeSandwichesForEverybody(): ThunkAction<any, any, any> {
|
||||
return function (dispatch: Dispatch<any>, getState: () => any): any {
|
||||
if (!getState().sandwiches.isShopOpen) {
|
||||
|
||||
// You don’t have to return Promises, but it’s a handy convention
|
||||
// so the caller can always call .then() on async dispatch result.
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
// We can dispatch both plain object actions and other thunks,
|
||||
// which lets us compose the asynchronous actions in a single flow.
|
||||
|
||||
return dispatch(
|
||||
makeASandwichWithSecretSauce('My Grandma')
|
||||
).then(() =>
|
||||
Promise.all([
|
||||
dispatch(makeASandwichWithSecretSauce('Me')),
|
||||
dispatch(makeASandwichWithSecretSauce('My wife'))
|
||||
])
|
||||
).then(() =>
|
||||
dispatch(makeASandwichWithSecretSauce('Our kids'))
|
||||
).then(() =>
|
||||
dispatch(getState().myMoney > 42 ?
|
||||
withdrawMoney(42) :
|
||||
apologize('Me', 'The Sandwich Shop')
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"redux-thunk-tests.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user