From f5982a3a1f75b76eb98162e94a5d7600096d5c74 Mon Sep 17 00:00:00 2001 From: andyshuxin Date: Wed, 6 Jul 2016 12:23:18 +0800 Subject: [PATCH 1/6] Define Redux UI --- redux-ui/redux-ui.d.ts | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 redux-ui/redux-ui.d.ts diff --git a/redux-ui/redux-ui.d.ts b/redux-ui/redux-ui.d.ts new file mode 100644 index 0000000000..8af92fbefd --- /dev/null +++ b/redux-ui/redux-ui.d.ts @@ -0,0 +1,43 @@ +declare module "redux-ui" { + export interface uiParams { + // 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 { + // 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 default function ui(params: uiParams): (component: T) => T +} From 21b03eed577621eb2f1e05e8eb2c45cb80c05c06 Mon Sep 17 00:00:00 2001 From: andyshuxin Date: Wed, 6 Jul 2016 13:44:56 +0800 Subject: [PATCH 2/6] Add test file for redux-ui --- redux-ui/redux-ui-tests.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 redux-ui/redux-ui-tests.ts diff --git a/redux-ui/redux-ui-tests.ts b/redux-ui/redux-ui-tests.ts new file mode 100644 index 0000000000..6d1954886d --- /dev/null +++ b/redux-ui/redux-ui-tests.ts @@ -0,0 +1,31 @@ +/// +/// + +import * as React from 'react' +import ui, { ReduxUIProps } from 'redux-ui' + +type UIShape = { + s: string +} + +@ui({ + key: 'Root', + persist: true, + state: { + s: '', + }, + mergeProps: () => ({}), + options: {} +}) +class Root extends React.Component, {}> { + render() { + console.info( + this.props.ui.s, + this.props.uiKey + ) + this.props.updateUI('s', 'a') + this.props.updateUI({s: 'a'}) + this.props.resetUI() + return null + } +} From 8bde611d8f26ca20c0618cab12f3edb8a6180671 Mon Sep 17 00:00:00 2001 From: andyshuxin Date: Wed, 6 Jul 2016 14:11:58 +0800 Subject: [PATCH 3/6] Add definition and test for reducer --- redux-ui/redux-ui-tests.ts | 10 +++++++--- redux-ui/redux-ui.d.ts | 22 +++++++++++++--------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/redux-ui/redux-ui-tests.ts b/redux-ui/redux-ui-tests.ts index 6d1954886d..c039fcf349 100644 --- a/redux-ui/redux-ui-tests.ts +++ b/redux-ui/redux-ui-tests.ts @@ -2,7 +2,7 @@ /// 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, {}> { - render() { + componentWillMount() { console.info( this.props.ui.s, this.props.uiKey @@ -26,6 +26,10 @@ class Root extends React.Component, {}> { this.props.updateUI('s', 'a') this.props.updateUI({s: 'a'}) this.props.resetUI() - return null } } + +Redux.combineReducers({ + ui: reducer, +}) + diff --git a/redux-ui/redux-ui.d.ts b/redux-ui/redux-ui.d.ts index 8af92fbefd..61110ed245 100644 --- a/redux-ui/redux-ui.d.ts +++ b/redux-ui/redux-ui.d.ts @@ -1,43 +1,47 @@ +/// + declare module "redux-ui" { export interface uiParams { // 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 { // 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 + export default function ui(params: uiParams): (component: T) => T } From c73f47708bcb095e79c9dac1ba26353c674713a9 Mon Sep 17 00:00:00 2001 From: andyshuxin Date: Wed, 6 Jul 2016 14:20:02 +0800 Subject: [PATCH 4/6] Import explicitly from Redux --- redux-ui/redux-ui.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/redux-ui/redux-ui.d.ts b/redux-ui/redux-ui.d.ts index 61110ed245..bc35729be5 100644 --- a/redux-ui/redux-ui.d.ts +++ b/redux-ui/redux-ui.d.ts @@ -1,6 +1,9 @@ /// declare module "redux-ui" { + + import * as Redux from 'redux' + export interface uiParams { // optional key which is used to determine the UI path in which state will // be stored. if omitted this is randomly generated. From 97dca788c62a5428186215b2d835ccd763d73262 Mon Sep 17 00:00:00 2001 From: andyshuxin Date: Thu, 7 Jul 2016 17:39:58 +0800 Subject: [PATCH 5/6] Add semicolons --- redux-ui/redux-ui-tests.ts | 14 +++++++------- redux-ui/redux-ui.d.ts | 26 +++++++++++++------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/redux-ui/redux-ui-tests.ts b/redux-ui/redux-ui-tests.ts index c039fcf349..5576a19b9d 100644 --- a/redux-ui/redux-ui-tests.ts +++ b/redux-ui/redux-ui-tests.ts @@ -5,8 +5,8 @@ import * as React from 'react' import ui, { ReduxUIProps, reducer } from 'redux-ui' type UIShape = { - s: string -} + s: string; +}; @ui({ key: 'Root', @@ -22,14 +22,14 @@ class Root extends React.Component, {}> { console.info( this.props.ui.s, this.props.uiKey - ) - this.props.updateUI('s', 'a') - this.props.updateUI({s: 'a'}) - this.props.resetUI() + ); + this.props.updateUI('s', 'a'); + this.props.updateUI({s: 'a'}); + this.props.resetUI(); } } Redux.combineReducers({ ui: reducer, -}) +}); diff --git a/redux-ui/redux-ui.d.ts b/redux-ui/redux-ui.d.ts index bc35729be5..303c8f0cf6 100644 --- a/redux-ui/redux-ui.d.ts +++ b/redux-ui/redux-ui.d.ts @@ -2,49 +2,49 @@ declare module "redux-ui" { - import * as Redux from 'redux' + import * as Redux from 'redux'; export interface uiParams { // optional key which is used to determine the UI path in which state will // be stored. if omitted this is randomly generated. - key?: string + 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 + persist?: boolean; // **required**: UI state for the component - state: UIStateShape + state: UIStateShape; // optional mergeProps passed to react-redux' @connect - mergeProps?: (stateProps: any, dispatchProps: any, ownProps: any) => any + mergeProps?: (stateProps: any, dispatchProps: any, ownProps: any) => any; // optional `options` passed to react-redux @connect options?: { pure?: boolean; withRef?: boolean; - } + }; } export interface ReduxUIProps { // The key passed to the decorator from the decorator // (eg. 'some-decorator' with `@ui('some-decorator')` - uiKey: string + uiKey: string; // The UI state for the component's `uiKey` - ui: UIStateShape + 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 + updateUI(obj: UIStateShape): void; + updateUI(key: string, value: any): void; // A function which resets the state within `uiKey` to its default - resetUI(): void + resetUI(): void; } - export const reducer: Redux.Reducer + export const reducer: Redux.Reducer; - export default function ui(params: uiParams): (component: T) => T + export default function ui(params: uiParams): (component: T) => T; } From 76f957c28e502060d55c558eacefc2fc9827e35c Mon Sep 17 00:00:00 2001 From: andyshuxin Date: Fri, 8 Jul 2016 17:11:34 +0800 Subject: [PATCH 6/6] Add header --- redux-ui/redux-ui.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/redux-ui/redux-ui.d.ts b/redux-ui/redux-ui.d.ts index 303c8f0cf6..7ba61a3f8a 100644 --- a/redux-ui/redux-ui.d.ts +++ b/redux-ui/redux-ui.d.ts @@ -1,3 +1,8 @@ +// Type definitions for redux-ui 0.0.15 +// Project: https://github.com/tonyhb/redux-ui +// Definitions by: Andy Shu Xin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + /// declare module "redux-ui" {