本文整理匯總了TypeScript中mantra-core.composeAll函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript composeAll函數的具體用法?TypeScript composeAll怎麽用?TypeScript composeAll使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了composeAll函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: context
import {useDeps, composeWithTracker, composeAll, IKomposer, IKomposerData} from 'mantra-core';
export const composer: IKomposer = ({context, postId}, onData: IKomposerData) => {
const {Meteor, Collections, Tracker} = context();
Meteor.subscribe('posts.single', postId, () => {
const post = Collections.Posts.findOne(postId);
onData(null, {post});
});
// support latency compensation
// we don't need to invalidate tracker because of the
// data fetching from the cache.
const postFromCache = Tracker.nonreactive(() => {
return Collections.Posts.findOne(postId);
});
if (postFromCache) {
onData(null, {post: postFromCache});
} else {
onData();
}
return null;
};
export default composeAll(
composeWithTracker(composer),
useDeps()
)(Post);
示例2: context
import NewPost from '../components/newpost';
import {useDeps, composeWithTracker, composeAll, IKomposer, IKomposerData, IDepsMapper} from 'mantra-core';
export const composer: IKomposer = ({context, clearErrors}, onData: IKomposerData) => {
const {LocalState} = context();
const error = LocalState.get('SAVING_ERROR');
onData(null, {error});
// clearErrors when unmounting the component
return clearErrors;
};
export const depsMapper: IDepsMapper = (context, actions) => ({
create: actions.posts.create,
clearErrors: actions.posts.clearErrors,
context: () => context
});
export default composeAll(
composeWithTracker(composer),
useDeps(depsMapper)
)(NewPost);
示例3: onData
import { IContext } from "../configs/context";
import { useDeps, composeWithTracker, composeAll, IKomposer, IKomposerData } from "mantra-core";
import Component, { IComponentProps, IComponentActions } from "../components/logged_user_view";
import { VIEWKEY, ERRORKEY, MESSAGEKEY } from "../actions/accounts";
interface IProps {
context?: IContext;
showUserName?: boolean;
}
export const composer: IKomposer = ({context, showUserName}: IProps, onData: IKomposerData<IComponentProps>) => {
const { Meteor, i18n }: IContext = context;
onData(null, {
userName: showUserName ? Meteor.user().profile.name : "",
context: context
});
return null;
};
export const depsMapper = (context: IContext, actions: any): IComponentActions => ({
signOut: actions.accounts.signOut
});
export default composeAll<IProps>(
composeWithTracker(composer),
useDeps(depsMapper)
)(Component);
示例4: createMutation
},
forceFetch: true
}
};
};
const mapMutationsToProps = (p: any) => ({
removePostMutation: (id: string) => {
return createMutation(`
mutation removePost($id: String) {
removePost(id: $id)
}`, { id });
}
});
const mapDispatchToProps = (dispatch: IDispatch, ownProps: IProps) => ({
removePost: (mutation: any) => {
dispatch(ownProps.removePost(ownProps.postId, mutation));
},
});
const depsToPropsMapper = (context: IContext, actions: IActions) => ({
removePost: actions.posts.remove
});
export default composeAll<IProps>(
compose(apolloContainer()),
connect({ mapQueriesToProps, mapMutationsToProps, mapDispatchToProps }),
useDeps(depsToPropsMapper) // -> not needed here
)(Post);
示例5: addComment
return {
mutation: gql`
mutation addComment($postId: String, $comment: String) {
addComment(postId: $postId, comment: $comment)
}`,
variables: {
postId: postId,
comment
}
};
}
};
};
const mapStateToProps = (state: IState) => {
return {
error: state.post.error
};
};
export const mapDepsToProps = (context: IContext, actions: IActions ) => ({
create: actions.comments.create,
clearErrors: actions.general.clearErrors,
context: () => context
});
export default composeAll<IProps>(
connect({mapMutationsToProps, mapStateToProps}),
useDeps(mapDepsToProps)
)(Component);
示例6: onData
context?: () => IContext;
}
const composer: IKomposer = ({ mark }: IComponentProps, onData: IKomposerData<IComponentProps>) => {
if (mark) {
onData(null, { mark });
} else {
onData();
}
return null;
};
const mapDispatchToProps = (dispatch: any, ownProps: any): IComponentActions => ({
assignResult: (index: number, mark: any) =>
dispatch({ type: 'CHANGE_MARK', index, mark }),
changeStudent: (student: string) =>
dispatch({ type: 'STUDENT', student }),
save: () => {
dispatch({ type: 'SAVE' });
}
});
const mapStateToProps = (state: IState) => ({
mark: state.mark
});
export default composeAll<IProps>(
compose(composer),
connect(mapStateToProps, mapDispatchToProps)
)(Component);
示例7: mapQueriesToProps
import { compose, composeAll } from 'mantra-core';
import apolloContainer from './apollo';
import { connect } from 'react-apollo';
interface IProps {
context: IContainerContext;
}
function mapQueriesToProps() {
return {
data: {
query: gql`
{
posts {
_id,
title,
content
}
}
`,
forceFetch: true
}
};
};
export default composeAll<{}>(
compose(apolloContainer()),
connect({ mapQueriesToProps })
// useDeps() // -> not needed here
)(PostList);
示例8: onData
sort: { student: 1 }
};
const marks = Collections.Results.find({}, options).fetch();
// store data in the store
Store.dispatch({ type: 'RESULTS', marks });
if (id) {
Store.dispatch({ type: 'RESULT', mark: Collections.Results.findOne(id) });
} else {
Store.dispatch({ type: 'CREATE_RESULT'});
}
onData(null, {});
} else {
onData();
}
return null;
};
const mapStateToProps = (state: IState) => ({
marks: state.marks
});
export default composeAll<IProps>(
connect(mapStateToProps),
composeWithTracker(composer),
useDeps()
)(Component);
示例9: connect
addPost: generateMutationObject
};
};
// const mapDispatchToProps = (dispatch: any, ownProps: any) => {
// return {
// create: (title: string, content: string, mutation: any) => {
// dispatch(ownProps.createAction(title, content, mutation));
// }
// };
// };
const mapStateToProps = (state: IState) => {
return {
error: state.post.error
};
};
const mapDepsToProps = (context: IContext, actions: IActions) => {
return {
create: actions.posts.create
};
};
export default composeAll<{}>(
connect({mapMutationsToProps, mapStateToProps}),
useDeps(mapDepsToProps)
)(NewPost);
// export default (NewPost);
示例10: comments
ownProps: IProps;
state: IState;
}
const mapQueriesToProps = ({ ownProps }: IReduxProps): IGraphqlQuery => {
return {
data: {
query: gql`
query comments($postId: String) {
comments(postId: $postId) {
_id,
createdAt,
text,
author
}
}
`,
forceFetch: true,
variables: {
postId: ownProps.postId
}
}
};
};
export default composeAll<IProps>(
compose(apolloContainer()),
connect({ mapQueriesToProps })
)(Component);