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