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


TypeScript prop-types.shape函數代碼示例

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


在下文中一共展示了shape函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

/**
 * watching is an ES2017 decorator that lets components subscribe
 * to actions, much like reactors. They have to define a `subscribe`
 * method that will get a watcher as only argument.
 */
export default function(constructor: Function) {
  if (!constructor.prototype.subscribe) {
    throw new Error(
      `Component ${
        constructor.name
      } is missing subscribe method (watching decorator)`
    );
  }

  const origContextTypes = (constructor as any).contextTypes || {};
  (constructor as any).contextTypes = {
    ...origContextTypes,
    store: PropTypes.shape({
      subscribe: PropTypes.func.isRequired,
      dispatch: PropTypes.func.isRequired,
      getState: PropTypes.func.isRequired,
    }),
  };

  const originalWillMount = constructor.prototype.componentWillMount;
  constructor.prototype.componentWillMount = function() {
    if (!this.context.store) {
      throw new Error(
        `Can't set up watching because no ` +
          `store in context. Did you forget to wrap your top-level component in <Provider/> ?`
      );
    }

    this.watcher = new Watcher();
    this.context.store.watcher.addSub(this.watcher);
    constructor.prototype.subscribe.call(this, this.watcher);

    if (originalWillMount) {
      originalWillMount.call(this);
    }
  };

  const originalWillUnmount = constructor.prototype.componentWillUnmount;
  constructor.prototype.componentWillUnmount = function() {
    if (!this.context.store) {
      throw new Error(
        `Can't tear down watching because no ` +
          `store in context. Did you forget to wrap your top-level component in <Provider/> ?`
      );
    }

    this.context.store.watcher.removeSub(this.watcher);
    this.watcher = null;

    if (originalWillUnmount) {
      originalWillUnmount.call(this);
    }
  };
}
開發者ID:HorrerGames,項目名稱:itch,代碼行數:59,代碼來源:watching.ts

示例2:

/* globals Element */
import * as PropTypes from 'prop-types';

/** @internal */
export const RefType = PropTypes.shape({
  current: PropTypes.instanceOf((typeof Element !== 'undefined') ? Element : Object),
});
開發者ID:MaksimMakarevich,項目名稱:devextreme-reactive,代碼行數:7,代碼來源:ref-type.ts

示例3:

   '900'
 ]),
 /**
  * @platform ios
  */
 fontVariant: ReactPropTypes.arrayOf(
   ReactPropTypes.oneOf([
     'small-caps',
     'oldstyle-nums',
     'lining-nums',
     'tabular-nums',
     'proportional-nums'
   ])
 ),
 textShadowOffset: ReactPropTypes.shape({
   width: ReactPropTypes.number,
   height: ReactPropTypes.number
 }),
 textShadowRadius: ReactPropTypes.number,
 textShadowColor: ColorPropType,
 /**
  * @platform ios
  */
 letterSpacing: ReactPropTypes.number,
 lineHeight: ReactPropTypes.number,
 /**
  * Specifies text alignment. The value 'justify' is only supported on iOS and
  * fallbacks to `left` on Android.
  */
 textAlign: ReactPropTypes.oneOf([
   'auto' /* default */,
   'left',
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:32,代碼來源:TextStylePropTypes.ts

示例4:

   * transformation. Objects should not be combined. Use a single key/value pair
   * per object.
   *
   * The rotate transformations require a string so that the transform may be
   * expressed in degrees (deg) or radians (rad). For example:
   *
   * `transform([{ rotateX: '45deg' }, { rotateZ: '0.785398rad' }])`
   *
   * The skew transformations require a string so that the transform may be
   * expressed in degrees (deg). For example:
   *
   * `transform([{ skewX: '45deg' }])`
   */
  transform: ReactPropTypes.arrayOf(
    ReactPropTypes.oneOfType([
      ReactPropTypes.shape({perspective: ReactPropTypes.number}),
      ReactPropTypes.shape({rotate: ReactPropTypes.string}),
      ReactPropTypes.shape({rotateX: ReactPropTypes.string}),
      ReactPropTypes.shape({rotateY: ReactPropTypes.string}),
      ReactPropTypes.shape({rotateZ: ReactPropTypes.string}),
      ReactPropTypes.shape({scale: ReactPropTypes.number}),
      ReactPropTypes.shape({scaleX: ReactPropTypes.number}),
      ReactPropTypes.shape({scaleY: ReactPropTypes.number}),
      ReactPropTypes.shape({translateX: ReactPropTypes.number}),
      ReactPropTypes.shape({translateY: ReactPropTypes.number}),
      ReactPropTypes.shape({skewX: ReactPropTypes.string}),
      ReactPropTypes.shape({skewY: ReactPropTypes.string})
    ])
  ),

  /**
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:31,代碼來源:TransformPropTypes.ts

示例5: function

import { Watcher } from "common/util/watcher";
export { Watcher } from "common/util/watcher";

import PropTypes from "prop-types";
import { rendererLogger } from "renderer/logger";

export const storeShape = PropTypes.shape({
  subscribe: PropTypes.func.isRequired,
  dispatch: PropTypes.func.isRequired,
  getState: PropTypes.func.isRequired,
});

/**
 * watching is an ES2017 decorator that lets components subscribe
 * to actions, much like reactors. They have to define a `subscribe`
 * method that will get a watcher as only argument.
 */
export default function(constructor: Function) {
  if (!constructor.prototype.subscribe) {
    throw new Error(
      `Component ${
        constructor.name
      } is missing subscribe method (watching decorator)`
    );
  }

  const origContextTypes = (constructor as any).contextTypes || {};
  (constructor as any).contextTypes = {
    ...origContextTypes,
    store: storeShape,
  };
開發者ID:itchio,項目名稱:itch,代碼行數:31,代碼來源:watching.ts

示例6: SingleChildShape

  });

parentSchema
  .morphTo({
    Single: singleChildSchema,
    'Model::Multiple': multipleChildrenSchema,
  }, 'polymorph', '_type', '_fk')
  .belongsToMany({
    children: multipleChildrenSchema,
  })
  .hasOne({
    orphan: singleChildSchema,
  });

export const MultipleChildrenShape = PropTypes.shape({
  uuid: PropTypes.string,
});

export interface MultipleChildrenShape {
  uuid?: string;
}

export const SingleChildShape = PropTypes.shape({
  id: PropTypes.number,
  active: PropTypes.bool,
  self: (...args) => SingleChildShape(...args),
});

export interface SingleChildShape {
  id?: number;
  active?: boolean;
開發者ID:milesj,項目名稱:shapeshifter,代碼行數:31,代碼來源:infer-and-schema-generics.ts

示例7: emit

import Emitter from '@devexperts/utils/dist/emitter/Emitter';
import * as PropTypes from 'prop-types';

export const EVENT_SCROLABLE = {
	RESIZE: 'EVENT_SCROLABLE:RESIZE',
	SCROLL: 'EVENT_SCROLLABLE:SROLL',
	SCROLLBAR_UPDATE: 'EVENT_SCROLABLE:SCROLLBAR_UPDATE',
};

export class ScrollableInternalEmitter extends Emitter {
	emit(event: any, ...args: any[]) {
		this._emit(event, ...args);
	}
}

export const SCROLLABLE_CONTEXT_EMITTER = '__SCROLLABLE__CONTEXT_EMITTER__';
export const CONTEXT_TYPES = {
	[SCROLLABLE_CONTEXT_EMITTER.toString()]: PropTypes.instanceOf(ScrollableInternalEmitter).isRequired,
	size: PropTypes.shape({
		width: PropTypes.number,
		height: PropTypes.number,
	}),
};
開發者ID:sutarmin,項目名稱:dx-platform,代碼行數:23,代碼來源:Scrollable.const.ts

示例8:

        foo: string;
        bar?: boolean;
        baz?: any
    };
    optionalNumber?: number | null;
    customProp?: typeof uniqueType;
}

const innerProps = {
    foo: PropTypes.string.isRequired,
    bar: PropTypes.bool,
    baz: PropTypes.any
};

const arrayOfTypes = [PropTypes.string, PropTypes.bool, PropTypes.shape({
    foo: PropTypes.string,
    bar: PropTypes.number.isRequired
})];
type PropTypesMap = PropTypes.ValidationMap<Props>;

// TS checking
const propTypes: PropTypesMap = {
    any: PropTypes.any,
    array: PropTypes.array.isRequired,
    bool: PropTypes.bool.isRequired,
    element: PropTypes.element.isRequired,
    func: PropTypes.func.isRequired,
    node: PropTypes.node,
    requiredNode: PropTypes.node.isRequired,
    number: PropTypes.number.isRequired,
    object: PropTypes.object.isRequired,
    string: PropTypes.string.isRequired,
開發者ID:Jeremy-F,項目名稱:DefinitelyTyped,代碼行數:32,代碼來源:prop-types-tests.ts

示例9:

import * as PropTypes from 'prop-types';

export const SomeShape = PropTypes.shape({});
開發者ID:vcarrera,項目名稱:react-docgen-typescript,代碼行數:3,代碼來源:shapes.ts

示例10:

import * as PropTypes from 'prop-types'

export default PropTypes.shape({
  subscribe: PropTypes.func.isRequired,
  getState: PropTypes.func.isRequired,
  getFormState: PropTypes.func.isRequired,
  setFormState: PropTypes.func.isRequired,
  dispatch: PropTypes.func.isRequired,
  addValidator: PropTypes.func.isRequired,
  removeValidator: PropTypes.func.isRequired,
  addSubmitListener: PropTypes.func.isRequired,
  removeSubmitListener: PropTypes.func.isRequired,
  validate: PropTypes.func.isRequired,
  submit: PropTypes.func.isRequired,
  setValue: PropTypes.func.isRequired,
  setValidationError: PropTypes.func.isRequired,
  clearValidationError: PropTypes.func.isRequired,
  reset: PropTypes.func.isRequired,
  clear: PropTypes.func.isRequired,
  unsubscribe: PropTypes.func.isRequired
})
開發者ID:jschr,項目名稱:react-redux-local-form,代碼行數:21,代碼來源:formStoreShape.ts


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