本文整理匯總了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)
}
})
)