From ad091274e3dc5b01247e34a4a869dbbe4fd2e202 Mon Sep 17 00:00:00 2001 From: Andy Edwards Date: Tue, 19 Jun 2018 13:37:51 -0500 Subject: [PATCH] fix: index flow type exports --- src/actions.js | 2 +- src/featureReducersReducer.js | 2 +- src/featureStatesReducer.js | 4 +- src/featuresReducer.js | 4 +- src/index.js | 34 +++++++++++++++ src/index.js.flow | 81 ----------------------------------- src/loadFeatureMiddleware.js | 4 +- 7 files changed, 39 insertions(+), 92 deletions(-) delete mode 100644 src/index.js.flow diff --git a/src/actions.js b/src/actions.js index 8c96aab..15bdb2e 100644 --- a/src/actions.js +++ b/src/actions.js @@ -1,6 +1,6 @@ /* @flow */ -import type {Feature, FeatureState, FeatureAction} from './index.js.flow' +import type {Feature, FeatureState, FeatureAction} from './index' export const ACTION_TYPE_PREFIX = '@@redux-features/' export const ADD_FEATURE = ACTION_TYPE_PREFIX + 'ADD_FEATURE' diff --git a/src/featureReducersReducer.js b/src/featureReducersReducer.js index 2875075..2b532be 100644 --- a/src/featureReducersReducer.js +++ b/src/featureReducersReducer.js @@ -1,7 +1,7 @@ // @flow import type {Reducer} from 'redux' -import type {Features, ComposeReducers} from './index.js.flow' +import type {Features, ComposeReducers} from './index' import {createSelector} from 'reselect' import {defaultComposeReducers} from './defaults' diff --git a/src/featureStatesReducer.js b/src/featureStatesReducer.js index 8d6d5b9..3288f4e 100644 --- a/src/featureStatesReducer.js +++ b/src/featureStatesReducer.js @@ -3,7 +3,7 @@ import {ADD_FEATURE, LOAD_FEATURE, INSTALL_FEATURE, REPLACE_FEATURE, SET_FEATURE_STATE, LOAD_INITIAL_FEATURES} from './actions' import { mapValues } from "lodash" import type {Reducer} from 'redux' -import type {FeatureStates, FeatureAction, CreateReducer} from './index.js.flow' +import type {FeatureStates, FeatureAction, CreateReducer} from './index' import {defaultCreateReducer} from './defaults' @@ -22,5 +22,3 @@ export default function featureStatesReducer( [LOAD_INITIAL_FEATURES]: state => mapValues(state, fs => fs === 'LOADED' ? 'LOADING' : fs) }) } - - diff --git a/src/featuresReducer.js b/src/featuresReducer.js index 89536f8..ad71f0f 100644 --- a/src/featuresReducer.js +++ b/src/featuresReducer.js @@ -1,7 +1,7 @@ // @flow import type {Reducer} from 'redux' -import type {Features, FeatureAction, CreateReducer} from './index.js.flow' +import type {Features, FeatureAction, CreateReducer} from './index' import {ADD_FEATURE, INSTALL_FEATURE, REPLACE_FEATURE} from './actions' import {defaultCreateReducer} from './defaults' @@ -19,5 +19,3 @@ export default function featuresReducer}>( [REPLACE_FEATURE]: (state, {payload, meta: {id}}) => state[id] ? {...state, [id]: payload} : state, }) } - - diff --git a/src/index.js b/src/index.js index e265c82..71cff43 100644 --- a/src/index.js +++ b/src/index.js @@ -24,3 +24,37 @@ export { addFeature, loadFeature, installFeature, replaceFeature, setFeatureState, loadInitialFeatures, } +import type {MiddlewareAPI, Reducer, Middleware, ActionCreator} from 'redux' + +/* + + S = State + A = Action + + */ + +export type ActionCreators = { [key: K]: ActionCreator } + +export type CreateReducer = + (}>(initialState: S, reducers: {[actionType: string]: Reducer}) => Reducer) & + (}>(reducers: {[actionType: string]: Reducer}) => Reducer) +export type ComposeReducers = (...reducers: Array>) => Reducer +export type ComposeMiddleware = (...middlewares: Array>) => Middleware + +export type FeatureState = 'NOT_LOADED' | 'LOADING' | 'LOADED' | Error +export type FeatureStates = {[featureId: string]: FeatureState} + +export type Feature = { + init?: (store: MiddlewareAPI) => any, + load?: (store: MiddlewareAPI) => Promise>, + dependencies?: Array, + middleware?: Middleware, + reducer?: Reducer, +} +export type Features = {[featureId: string]: Feature} + +export type FeatureAction = { + type: string, + payload?: any, + meta?: {id: string}, +} diff --git a/src/index.js.flow b/src/index.js.flow deleted file mode 100644 index 8e92bd3..0000000 --- a/src/index.js.flow +++ /dev/null @@ -1,81 +0,0 @@ -// @flow - -import type {Dispatch, MiddlewareAPI, Store, Reducer, Middleware, ActionCreator} from 'redux' - -/* - - S = State - A = Action - - */ - -export type ActionCreators = { [key: K]: ActionCreator } - -export type CreateReducer = - (}>(initialState: S, reducers: {[actionType: string]: Reducer}) => Reducer) & - (}>(reducers: {[actionType: string]: Reducer}) => Reducer) -export type ComposeReducers = (...reducers: Array>) => Reducer -export type ComposeMiddleware = (...middlewares: Array>) => Middleware - -export type FeatureState = 'NOT_LOADED' | 'LOADING' | 'LOADED' | Error -export type FeatureStates = {[featureId: string]: FeatureState} - -export type Feature = { - init?: (store: MiddlewareAPI) => any, - load?: (store: MiddlewareAPI) => Promise>, - dependencies?: Array, - middleware?: Middleware, - reducer?: Reducer, -} -export type Features = {[featureId: string]: Feature} - -declare export var ACTION_TYPE_PREFIX: string -declare export var ADD_FEATURE: string -declare export var LOAD_FEATURE: string -declare export var INSTALL_FEATURE: string -declare export var REPLACE_FEATURE: string -declare export var SET_FEATURE_STATUS: string - -export type FeatureAction = { - type: string, - payload?: any, - meta?: {id: string}, -} - -declare export function addFeature(id: string, feature: Feature): FeatureAction -declare export function replaceFeature(id: string, feature: Feature): FeatureAction -declare export function loadFeature(id: string): FeatureAction -declare export function installFeature(id: string, feature: Feature): FeatureAction -declare export function setFeatureState(id: string, payload: FeatureState): FeatureAction -declare export function loadInitialFeatures(): FeatureAction - -declare export function featuresReducer( - config?: {createReducer?: CreateReducer, FeatureAction>} -): Reducer, FeatureAction> - -declare export function featureStatesReducer( - config?: {createReducer?: CreateReducer} -): Reducer - -declare export function featureReducersReducer( - config?: { - getFeatures?: (state: S) => ?Features, - composeReducers?: ComposeReducers, - } -): Reducer - -declare export function loadFeatureMiddleware, +meta?: Object}>( - config?: { - getFeatures?: (state: S) => ?Features, - getFeatureStates?: (state: S) => ?FeatureStates, - } -): Middleware - -declare export function featureMiddlewaresMiddleware( - config?: { - getFeatures?: (state: S) => ?Features, - composeMiddleware?: ComposeMiddleware, - } -): Middleware - -declare export function composeReducers(...reducers: Array>): Reducer \ No newline at end of file diff --git a/src/loadFeatureMiddleware.js b/src/loadFeatureMiddleware.js index 3ab8dad..abeaae6 100644 --- a/src/loadFeatureMiddleware.js +++ b/src/loadFeatureMiddleware.js @@ -1,6 +1,6 @@ // @flow -import type {Feature, Features, FeatureStates, FeatureAction} from './index.js.flow' +import type {Feature, Features, FeatureStates, FeatureAction} from './index' import type {Middleware, MiddlewareAPI, Dispatch} from 'redux' import {ADD_FEATURE, LOAD_FEATURE, installFeature, setFeatureState, LOAD_INITIAL_FEATURES, loadFeature} from './actions' import {defaultCreateMiddleware} from './defaults' @@ -77,5 +77,3 @@ export default function loadFeatureMiddleware}>( }, }) } - -