mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-27 06:22:55 +08:00
Add definition and test for reducer
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
/// <reference path="../react/react.d.ts"/>
|
||||
|
||||
import * as React from 'react'
|
||||
import ui, { ReduxUIProps } from 'redux-ui'
|
||||
import ui, { ReduxUIProps, reducer } from 'redux-ui'
|
||||
|
||||
type UIShape = {
|
||||
s: string
|
||||
@@ -18,7 +18,7 @@ type UIShape = {
|
||||
options: {}
|
||||
})
|
||||
class Root extends React.Component<ReduxUIProps<UIShape>, {}> {
|
||||
render() {
|
||||
componentWillMount() {
|
||||
console.info(
|
||||
this.props.ui.s,
|
||||
this.props.uiKey
|
||||
@@ -26,6 +26,10 @@ class Root extends React.Component<ReduxUIProps<UIShape>, {}> {
|
||||
this.props.updateUI('s', 'a')
|
||||
this.props.updateUI({s: 'a'})
|
||||
this.props.resetUI()
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
Redux.combineReducers({
|
||||
ui: reducer,
|
||||
})
|
||||
|
||||
|
||||
22
redux-ui/redux-ui.d.ts
vendored
22
redux-ui/redux-ui.d.ts
vendored
@@ -1,43 +1,47 @@
|
||||
/// <reference path="../redux/redux.d.ts"/>
|
||||
|
||||
declare module "redux-ui" {
|
||||
export interface uiParams<UIStateShape> {
|
||||
// optional key which is used to determine the UI path in which state will
|
||||
// be stored. if omitted this is randomly generated.
|
||||
key?: string
|
||||
|
||||
|
||||
// optional persist, defaults to false. if set to true persist will keep UI
|
||||
// state for this component after it unmounts. if set to false the UI state
|
||||
// will be deleted and recreated when the component remounts
|
||||
persist?: boolean
|
||||
|
||||
|
||||
// **required**: UI state for the component
|
||||
state: UIStateShape
|
||||
|
||||
|
||||
// optional mergeProps passed to react-redux' @connect
|
||||
mergeProps?: (stateProps: any, dispatchProps: any, ownProps: any) => any
|
||||
|
||||
|
||||
// optional `options` passed to react-redux @connect
|
||||
options?: {
|
||||
pure?: boolean;
|
||||
withRef?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export interface ReduxUIProps<UIStateShape> {
|
||||
// The key passed to the decorator from the decorator
|
||||
// (eg. 'some-decorator' with `@ui('some-decorator')`
|
||||
uiKey: string
|
||||
|
||||
|
||||
// The UI state for the component's `uiKey`
|
||||
ui: UIStateShape
|
||||
|
||||
|
||||
// A function accepting either a name/value pair or object which updates
|
||||
// state within `uiKey`
|
||||
updateUI(obj: UIStateShape): void
|
||||
updateUI(key: string, value: any): void
|
||||
|
||||
|
||||
// A function which resets the state within `uiKey` to its default
|
||||
resetUI(): void
|
||||
}
|
||||
|
||||
|
||||
export const reducer: Redux.Reducer<any>
|
||||
|
||||
export default function ui<UIStateShape>(params: uiParams<UIStateShape>): <T>(component: T) => T
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user