當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mantra-core.useDeps函數代碼示例

本文整理匯總了TypeScript中mantra-core.useDeps函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript useDeps函數的具體用法?TypeScript useDeps怎麽用?TypeScript useDeps使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了useDeps函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
開發者ID:sudieartha,項目名稱:Meteor-Boilerplate-Webpack-Mantra-Typescript,代碼行數:30,代碼來源:post.ts

示例2: 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);
開發者ID:tomitrescak,項目名稱:meteor-accountsui-semanticui-react,代碼行數:29,代碼來源:user_container.ts

示例3: 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);
開發者ID:TribeMedia,項目名稱:meteor-mantra-redux-graphql,代碼行數:30,代碼來源:post.ts

示例4: 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);
開發者ID:TribeMedia,項目名稱:meteor-mantra-redux-graphql,代碼行數:30,代碼來源:create_comment.ts

示例5: useDeps

import { useDeps } from 'mantra-core';
import Layout from '../components/layout';

const depsToPropsMapper = (context: IContext) => ({
  store: context.Store,
});

export const MainLayout = useDeps(depsToPropsMapper)(Layout);
export default MainLayout;
開發者ID:tomitrescak,項目名稱:Marking,代碼行數:9,代碼來源:layout_container.ts


注:本文中的mantra-core.useDeps函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。