re-reduced
Advanced tools
Comparing version 0.4.1 to 0.5.0
export interface Tree<Leaf> { | ||
[k: string]: Leaf | Tree<Leaf>; | ||
} | ||
export interface TraverseQuery<V, R> { | ||
transformKey?: (key: string, value: V) => string; | ||
transformValue?: (value: V, key: string) => R; | ||
export interface TraverseQuery<TLeft, TRight> { | ||
transformKey?: (key: string, value: TLeft) => string; | ||
transformValue?: (value: TLeft, key: string) => TRight; | ||
} | ||
export declare const mapObjectValues: <V, R>(fn: (k: string, v: V) => { | ||
[k: string]: R; | ||
}) => (obj: Tree<V>) => Tree<R>; | ||
export declare const transformTree: <V, R>(query: TraverseQuery<V, R>) => (obj: Tree<V | Tree<V>>) => Tree<R>; | ||
export declare const mapObjectValues: <TLeft, TRight>(fn: (k: string, v: TLeft) => { | ||
[k: string]: TRight; | ||
}) => (obj: Tree<TLeft>) => Tree<TRight>; | ||
export declare const transformTree: <TLeft, TRight>(query: TraverseQuery<TLeft, TRight>) => (obj: Tree<TLeft | Tree<TLeft>>) => Tree<TRight | Tree<TRight>>; |
@@ -5,13 +5,13 @@ "use strict"; | ||
exports.transformTree = (query) => { | ||
const transformKey = query.transformKey || ((k, v) => k); | ||
const transformValue = query.transformValue || ((v, k) => k); | ||
function mapper(k, v) { | ||
if (typeof v === "object") { | ||
// @ts-ignore | ||
return { [k]: exports.transformTree(query)(v) }; | ||
const transformKey = query.transformKey || ((k, _) => k); | ||
const transformValue = query.transformValue || ((v, _) => v); | ||
function mapper(key, value) { | ||
if (typeof value === "object") { | ||
return { | ||
[key]: exports.transformTree(query)(value) | ||
}; | ||
} | ||
// @ts-ignore | ||
return { [transformKey(k, v)]: transformValue(v, k) }; | ||
return { [transformKey(key, value)]: transformValue(value, key) }; | ||
} | ||
return exports.mapObjectValues(mapper); | ||
}; |
import { ActionCreator } from "./core"; | ||
import { Tree } from "./helpers/objects"; | ||
export declare type Dispatcher<T = any> = (payload: T) => void; | ||
export declare const connectWithActions: <T extends Tree<ActionCreator<any>>>(actions: T) => <TState, TProps>(mapStateToProps: (state: TState) => TProps) => import("react-redux").InferableComponentEnhancerWithProps<TProps & { | ||
declare type StateToProps<TState, TProps> = (state: TState) => TProps; | ||
export declare function connectWithActions<TActions extends Tree<ActionCreator<any>>, TState, TProps>(actions: TActions, mapStateToProps: StateToProps<TState, TProps>): import("react-redux").InferableComponentEnhancerWithProps<TProps & { | ||
actions: Tree<ActionCreator<any>>; | ||
}, {}>; | ||
export {}; |
@@ -7,3 +7,3 @@ "use strict"; | ||
const toDispatcher = (dispatch) => (action) => redux_1.compose(dispatch, action); | ||
exports.connectWithActions = (actions) => (mapStateToProps) => { | ||
function connectWithActions(actions, mapStateToProps) { | ||
const mapDisptachToProps = (dispatch) => ({ | ||
@@ -15,2 +15,3 @@ actions: objects_1.transformTree({ | ||
return react_redux_1.connect(mapStateToProps, mapDisptachToProps); | ||
}; | ||
} | ||
exports.connectWithActions = connectWithActions; |
{ | ||
"name": "re-reduced", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "A utility toolbelt that reduces boilerplate from your react/redux app", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
12342
204