@cerebral/fluent
Advanced tools
Comparing version
@@ -7,2 +7,8 @@ import { Component } from './Hoc'; | ||
}) => EP, passedComponent: Component<Props & EP>): Component<Props>; | ||
export declare type ModuleConnector<TState, TSignals> = { | ||
module: { | ||
state: TState; | ||
signals: TSignals; | ||
}; | ||
}; | ||
export declare type Connector<TProps, TState, TSignals> = { | ||
@@ -19,1 +25,9 @@ state: TState; | ||
}; | ||
export declare function ModuleConnectFactory<TState, TSignals>(): { | ||
To: <TModuleState, TModuleSignals>(stateLookup: (state: TState) => TModuleState, signalsLookup: (state: TSignals) => TModuleSignals) => <TProps>() => { | ||
with: <EP>(connector: (connect: Connector<TProps, TState, TSignals> & ModuleConnector<TModuleState, TModuleSignals>) => EP) => { | ||
to: (passedComponent: Component<TProps & EP>) => Component<TProps>; | ||
toClass: (passedComponent: (props: TProps & EP) => Component<TProps & EP>) => Component<TProps>; | ||
}; | ||
}; | ||
}; |
import { ObservableMap as MobxObservableMap } from 'mobx'; | ||
import { BaseControllerClass, ModuleClass, ControllerOptions } from 'cerebral'; | ||
export { ConnectFactory } from './connect'; | ||
export { ConnectFactory, ModuleConnectFactory } from './connect'; | ||
export { pathFor } from './paths'; | ||
@@ -5,0 +5,0 @@ export { SequenceFactory, SequenceWithPropsFactory, IContext, IBranchContext } from 'function-tree/fluent'; |
import Hoc from './Hoc'; | ||
import { CerebralError } from 'cerebral'; | ||
export default function connect(dependencies, passedComponent) { | ||
@@ -11,9 +12,12 @@ return Hoc(dependencies, passedComponent); | ||
to: function (passedComponent) { | ||
return connect(connector, passedComponent); | ||
var con = getConnector(connector); | ||
return connect(con, passedComponent); | ||
}, | ||
toClass: function (passedComponent) { | ||
return connect(connector, passedComponent({})); | ||
}, | ||
var fakeProps = getFakeProps(); | ||
var con = getConnector(connector); | ||
return connect(con, passedComponent(fakeProps)); | ||
} | ||
}; | ||
}, | ||
} | ||
}; | ||
@@ -23,1 +27,52 @@ } | ||
} | ||
export function ModuleConnectFactory() { | ||
function To(stateLookup, signalsLookup) { | ||
return function returned() { | ||
return { | ||
with: function (connector) { | ||
return { | ||
to: function (passedComponent) { | ||
var con = getConnector(connector, { stateLookup: stateLookup, signalsLookup: signalsLookup }); | ||
return connect(con, passedComponent); | ||
}, | ||
toClass: function (passedComponent) { | ||
var fakeProps = getFakeProps(); | ||
var con = getConnector(connector, { stateLookup: stateLookup, signalsLookup: signalsLookup }); | ||
return connect(con, passedComponent(fakeProps)); | ||
} | ||
}; | ||
} | ||
}; | ||
}; | ||
} | ||
return { To: To }; | ||
} | ||
function getFakeProps() { | ||
var handler = { | ||
get: function (target, name) { | ||
throw new CerebralError("The props lambda parameter should only be used to conveniently get the type of the components generic props parameter. Use `this.props` in the component instead."); | ||
} | ||
}; | ||
var fakeProps = Proxy ? new Proxy({}, handler) : {}; | ||
return fakeProps; | ||
} | ||
function getConnector(connector, lookups) { | ||
var con; | ||
if (lookups) { | ||
con = function (x) { | ||
return connector({ | ||
state: x.state, | ||
signals: x.signals, | ||
module: { | ||
state: lookups.stateLookup(x.state), | ||
signals: lookups.signalsLookup(x.signals) | ||
}, | ||
props: x.props | ||
}); | ||
}; | ||
} | ||
else { | ||
con = connector; | ||
} | ||
return con; | ||
} |
@@ -17,3 +17,3 @@ var __extends = (this && this.__extends) || (function () { | ||
import Model from './Model'; | ||
export { ConnectFactory } from './connect'; | ||
export { ConnectFactory, ModuleConnectFactory } from './connect'; | ||
export { pathFor } from './paths'; | ||
@@ -20,0 +20,0 @@ export { SequenceFactory, SequenceWithPropsFactory, } from 'function-tree/fluent'; |
{ | ||
"name": "@cerebral/fluent", | ||
"version": "1.0.0-1521659945175", | ||
"version": "1.0.0-1521800530349", | ||
"description": "Makes Cerebral typescript friendly", | ||
@@ -27,3 +27,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"cerebral": "^4.2.0-1521659945175", | ||
"cerebral": "^4.2.0-1521800530349", | ||
"mobx": "^3.4.1" | ||
@@ -30,0 +30,0 @@ }, |
84650
3.38%2015
3.55%