From 321a810505fd023390ef87432db830bce7761180 Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 8 Dec 2016 16:09:48 +0100 Subject: [PATCH] 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 ef08762ba252e4ac9088ebba22c04a8d4548189b. --- notNeededPackages.json | 6 ++ redux-thunk/index.d.ts | 23 ------ redux-thunk/package.json | 5 -- redux-thunk/redux-thunk-tests.ts | 118 ------------------------------- redux-thunk/tsconfig.json | 19 ----- 5 files changed, 6 insertions(+), 165 deletions(-) delete mode 100644 redux-thunk/index.d.ts delete mode 100644 redux-thunk/package.json delete mode 100644 redux-thunk/redux-thunk-tests.ts delete mode 100644 redux-thunk/tsconfig.json diff --git a/notNeededPackages.json b/notNeededPackages.json index d121004212..472a3881ca 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -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", diff --git a/redux-thunk/index.d.ts b/redux-thunk/index.d.ts deleted file mode 100644 index 358956eea8..0000000000 --- a/redux-thunk/index.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -// Type definitions for redux-thunk v2.1.0 -// Project: https://github.com/gaearon/redux-thunk -// Definitions by: Qubo , Kaur Kuut -// 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 = (dispatch: Dispatch, getState: () => S, extraArgument: E) => R; - - export interface Dispatch { - (asyncAction: ThunkAction): R; - } -} - diff --git a/redux-thunk/package.json b/redux-thunk/package.json deleted file mode 100644 index e52256ea90..0000000000 --- a/redux-thunk/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "redux": "^3.6.0" - } -} \ No newline at end of file diff --git a/redux-thunk/redux-thunk-tests.ts b/redux-thunk/redux-thunk-tests.ts deleted file mode 100644 index 902ea74979..0000000000 --- a/redux-thunk/redux-thunk-tests.ts +++ /dev/null @@ -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 = 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 { - // 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 { - 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 { - return function (dispatch: Dispatch, 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') - ) - ); - }; -} diff --git a/redux-thunk/tsconfig.json b/redux-thunk/tsconfig.json deleted file mode 100644 index f29efdaad3..0000000000 --- a/redux-thunk/tsconfig.json +++ /dev/null @@ -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" - ] -} \ No newline at end of file