@cerebral/react
Advanced tools
Comparing version 4.0.0-1525724201307 to 4.0.0-1526222433248
@@ -5,2 +5,7 @@ import * as React from 'react' | ||
export type IReactComponent<P = any> = | ||
| React.StatelessComponent<P> | ||
| React.ComponentClass<P> | ||
| React.ClassicComponentClass<P> | ||
interface PropsMap { | ||
@@ -15,2 +20,3 @@ [prop: string]: ResolveValue | ||
}> | ||
export const Container: React.ComponentClass<{ | ||
@@ -21,32 +27,26 @@ controller: any | ||
export function connect<P>( | ||
propsMap: P | ||
): <EP>( | ||
component: React.ComponentClass<P & EP> | React.SFC<P & EP> | ||
) => React.ComponentClass<EP> | ||
type Get = <T>(typePath: T) => T | ||
export function connect<P, EP = {}>( | ||
propsMap: P, | ||
overrideProps: ( | ||
dependencyProps: P, | ||
ownProps: EP, | ||
resolve: IResolve | ||
) => Partial<P & EP> | ||
): ( | ||
component: React.ComponentClass<P & EP> | React.SFC<P & EP> | ||
) => React.ComponentClass<EP> | ||
type Reaction = <T>(name: string, deps: T, cb: (deps: T & { get: Get }) => void) => void | ||
export function connect( | ||
propsMap: PropsMap | ||
): ( | ||
component: React.ComponentClass<any> | React.SFC<any> | ||
) => React.ComponentClass<any> | ||
type ConnectedProps = { get: Get, reaction: Reaction } | ||
export function connect( | ||
propsMap: PropsMap, | ||
overrideProps: (dependencyProps: any, ownProps: any, resolve: IResolve) => any | ||
): ( | ||
component: React.ComponentClass<any> | React.SFC<any> | ||
) => React.ComponentClass<any> | ||
// Diff / Omit taken from https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-311923766 | ||
type Omit<T, K extends keyof T> = Pick<T, ({ [P in keyof T]: P } & { [P in K]: never } & { [x: string]: never, [x: number]: never })[keyof T]>; | ||
export function connect<ExternalProps>( | ||
component:IReactComponent<ExternalProps & ConnectedProps> | ||
): IReactComponent<Omit<ExternalProps & ConnectedProps, keyof ConnectedProps>> | ||
export function connect<ExternalProps, Deps>( | ||
depsMap: Deps, | ||
component:IReactComponent<ExternalProps & Deps & ConnectedProps> | ||
): IReactComponent<Omit<ExternalProps & ConnectedProps, keyof ConnectedProps>> | ||
export function connect<ExternalProps, Deps, MergeProps>( | ||
depsMap: Deps, | ||
merge: (props: ExternalProps, deps: Deps, get: Get) => MergeProps, | ||
component:IReactComponent<MergeProps & ConnectedProps> | ||
): IReactComponent<Omit<ExternalProps & ConnectedProps, keyof ConnectedProps>> | ||
declare type ComponentDecorator = < | ||
@@ -59,5 +59,1 @@ TComponent extends React.ComponentClass<any> | ||
export function decorator(propsMap: PropsMap): ComponentDecorator | ||
export function decorator( | ||
propsMap: PropsMap, | ||
overrideProps: (dependencyProps: any, ownProps: any, resolve: IResolve) => any | ||
): ComponentDecorator |
@@ -6,21 +6,18 @@ "use strict"; | ||
}); | ||
function connect(HOC, dependencies, mergeProps) { | ||
var props = mergeProps; | ||
if (arguments.length === 2) { | ||
props = null; | ||
function connect(HOC, dependencies, mergeProps, component) { | ||
if (mergeProps && !component) { | ||
component = mergeProps; | ||
mergeProps = null; | ||
} else if (!mergeProps && !component) { | ||
component = dependencies; | ||
dependencies = {}; | ||
mergeProps = null; | ||
} | ||
return function (component) { | ||
return HOC(dependencies, props, component); | ||
}; | ||
return HOC(dependencies, mergeProps, component); | ||
} | ||
exports.default = function (HOC) { | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return connect.apply(undefined, [HOC].concat(args)); | ||
return function (dependencies, mergeProps, component) { | ||
return connect(HOC, dependencies, mergeProps, component); | ||
}; | ||
@@ -30,9 +27,5 @@ }; | ||
var decoratorFactory = exports.decoratorFactory = function decoratorFactory(HOC) { | ||
return function () { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return function (dependencies) { | ||
return function (component) { | ||
return connect.apply(undefined, [HOC].concat(args))(component); | ||
return connect(HOC, dependencies)(component); | ||
}; | ||
@@ -39,0 +32,0 @@ }; |
@@ -74,2 +74,24 @@ 'use strict'; | ||
/* | ||
We have to update any usage of "get" when the component mounts | ||
*/ | ||
}, { | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
if (this.view.dynamicDependencies.length) { | ||
this.view.update(this.props); | ||
} | ||
} | ||
/* | ||
We have to update any usage of "get" when the component updates | ||
*/ | ||
}, { | ||
key: 'componentDidUpdate', | ||
value: function componentDidUpdate() { | ||
if (this.view.dynamicDependencies.length) { | ||
this.view.update(this.props); | ||
} | ||
} | ||
/* | ||
If received props differ, we need to update any | ||
@@ -76,0 +98,0 @@ StateTrackers and tags, cause they might be using |
{ | ||
"name": "@cerebral/react", | ||
"version": "4.0.0-1525724201307", | ||
"version": "4.0.0-1526222433248", | ||
"description": "React view for Cerebral", | ||
@@ -20,3 +20,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"cerebral": "^5.0.0-1525724201307" | ||
"cerebral": "^5.0.0-1526222433248" | ||
}, | ||
@@ -23,0 +23,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
24623
268