本文整理汇总了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);
}
};
}
示例2:
/* globals Element */
import * as PropTypes from 'prop-types';
/** @internal */
export const RefType = PropTypes.shape({
current: PropTypes.instanceOf((typeof Element !== 'undefined') ? Element : Object),
});
示例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',
示例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})
])
),
/**
示例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,
};
示例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;
示例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,
}),
};
示例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,
示例9:
import * as PropTypes from 'prop-types';
export const SomeShape = PropTypes.shape({});
示例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
})