本文整理汇总了TypeScript中recompose.compose函数的典型用法代码示例。如果您正苦于以下问题:TypeScript compose函数的具体用法?TypeScript compose怎么用?TypeScript compose使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compose函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: compose
export const callDevice = () =>
compose(
connect(
undefined,
(dispatch): InjectedDispatch => ({
__injectedDispatch: dispatch,
}),
),
graphql<
CallDeviceInjectedProps & InjectedDispatch,
{},
{deviceId: string; interfaceId: string; method: string},
Partial<CallDeviceInjectedProps>
>(
gql`
mutation($deviceId: String!, $interfaceId: String!, $method: String!) {
callDevice(
deviceId: $deviceId
interfaceId: $interfaceId
method: $method
) {
id
}
}
`,
{
props: ({
mutate,
ownProps: {__injectedDispatch: dispatch},
}): CallDeviceInjectedProps => ({
callDevice(call: Call) {
return mutate!({
variables: call,
}).catch(() => {
dispatch(
action(actions.showSnackbar, {
label: 'Failed to call device',
type: 'warning' as 'warning',
}),
)
})
},
}),
},
),
)
示例2: withState
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { compose, withState } from 'recompose';
import { AdvancedFilter as Component, Props as ComponentProps } from './advanced_filter';
export interface Props {
/** Optional value for the component */
value?: string;
/** Function to invoke when the filter value is committed */
commit: (value: string) => void;
}
export const AdvancedFilter = compose<ComponentProps, Props>(
withState('value', 'onChange', ({ value }) => value || '')
)(Component);
示例3: compose
*/
export default compose(
connect(
undefined,
{ getAllLinodeConfigs }
),
lifecycle<
OutterProps & { getAllLinodeConfigs: GetAllLinodeConfigsRequest },
{}
>({
componentDidMount() {
// tslint:disable-next-line:no-shadowed-variable
const { linodeId, getAllLinodeConfigs } = this.props;
getAllLinodeConfigs({ linodeId });
},
componentDidUpdate(prevProps) {
// tslint:disable-next-line:no-shadowed-variable
const { linodeId: prevLinodeId, getAllLinodeConfigs } = this.props;
const { linodeId } = prevProps;
if (linodeId === prevLinodeId) {
return;
}
getAllLinodeConfigs({ linodeId });
}
})
);
示例4: connect
import { getLinode as _getLinode } from 'src/store/linodes/linode.requests';
import { GetLinodeRequest } from 'src/store/linodes/linodes.actions';
interface OuterProps {
linodeId: number;
}
/**
* Get the Linode on mount and on linodeId change.
*/
export default compose<OuterProps, {}>(
connect(
undefined,
{ getLinode: _getLinode }
),
lifecycle<OuterProps & { getLinode: GetLinodeRequest }, void>({
componentDidMount() {
const { linodeId, getLinode } = this.props;
getLinode({ linodeId });
},
componentDidUpdate(prevProps) {
const { linodeId: prevLinodeId } = prevProps;
const { linodeId } = this.props;
if (linodeId !== prevLinodeId) {
_getLinode({ linodeId });
}
}
})
);
示例5: withState
import Player from "common/player/Player"
import { MeasureList } from "common/measure"
interface Inner {
player: Player
measureList: MeasureList
}
interface Outer extends Inner {
playerPosition: number
}
interface Props extends Outer {
onTick: (number) => void
}
export default compose<Inner, Outer>(
withState("mbtTime", "updateMBTTime", 0),
withHandlers<Inner & { updateMBTTime: (number) => void }, {}>({
onTick: props => tick => props.updateMBTTime(props.measureList.getMBTString(tick, props.player.timebase)),
}),
lifecycle<Props, {}>({
componentDidMount() {
this.props.player.on("change-position", this.props.onTick)
},
componentWillUnmount() {
this.props.player.on("change-position", this.props.onTick)
}
})
)