Skip to content

Commit

Permalink
Prettier on prop_types.js
Browse files Browse the repository at this point in the history
  • Loading branch information
schovi committed Jun 6, 2017
1 parent a873bf5 commit 4dd3b68
Showing 1 changed file with 48 additions and 37 deletions.
85 changes: 48 additions & 37 deletions src/prop_types.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
import PropTypes from 'prop-types';

const { bool, number, string, func, shape, object, instanceOf, oneOf, oneOfType, arrayOf } = PropTypes
import {
bool,
number,
string,
func,
shape,
object,
instanceOf,
oneOf,
oneOfType,
arrayOf
} from 'prop-types'

const errMsg = function(props, propName, componentName, msgContinuation) {
return `Invalid prop '${propName}' of value '${props[propName]}' supplied to '${componentName}'${msgContinuation}`;
return `Invalid prop '${propName}' of value '${props[propName]}' supplied to '${componentName}'${msgContinuation}`
}

const iScrollPropType = (props, propName, componentName) => {
const iScroll = props[propName]
const proto = iScroll && iScroll.prototype
const proto = iScroll && iScroll.prototype

if(!iScroll || !proto || !proto.version || !proto.scrollTo)
if (!iScroll || !proto || !proto.version || !proto.scrollTo) {
return new Error(errMsg(props, propName, componentName, ', expected a iScroll object'))
}

if(+proto.version.split(".")[0] !== 5)
console.warn(componentName + ": different version than 5.x.y of iScroll is required. Some features won't work properly.")
if (Number(proto.version.split('.')[0]) !== 5) {
console.warn(
componentName +
": different version than 5.x.y of iScroll is required. Some features won't work properly."
)
}

if(props.options && props.options.zoom && !proto.zoom)
console.warn(componentName + ": options.zoom is set, but iscroll-zoom version is not required. Zoom feature won't work properly.")
if (props.options && props.options.zoom && !proto.zoom) {
console.warn(
componentName +
": options.zoom is set, but iscroll-zoom version is not required. Zoom feature won't work properly."
)
}
}

const elementOrSelectorPropType = (props, propName, componentName) => {
const value = props[propName]

if (!value || value.nodeType !== 1 || typeof(value) !== "string")
return new Error(errMsg(props, propName, componentName, ', expected a DOM element or a selector'))
if (!value || value.nodeType !== 1 || typeof value !== 'string') {
return new Error(
errMsg(props, propName, componentName, ', expected a DOM element or a selector')
)
}
}

const shrinkPropType = oneOf([false, 'clip', 'scale'])
Expand All @@ -46,41 +67,38 @@ const stringOrNumberPropType = oneOfType([string, number])

const iScrollOptionsPropType = shape({
// Basic options
useTransform: bool,
useTransform: bool,
useTransition: bool,
HWCompositing: bool,
bounce: bool,
click: bool,
disableMouse: bool,
click: bool,
disableMouse: bool,
disablePointer: bool,
disableTouch: bool,
disableTouch: bool,
eventPassthrough: oneOf([true, false, 'horizontal']),
freeScroll: bool,
freeScroll: bool,
keyBindings: oneOfType([
bool,
shape({
pageUp: stringOrNumberPropType,
pageUp: stringOrNumberPropType,
pageDown: stringOrNumberPropType,
end: stringOrNumberPropType,
end: stringOrNumberPropType,
home: stringOrNumberPropType,
left: stringOrNumberPropType,
up: stringOrNumberPropType,
up: stringOrNumberPropType,
right: stringOrNumberPropType,
down: stringOrNumberPropType
down: stringOrNumberPropType
})
]),
invertWheelDirection: bool,
momentum: bool,
momentum: bool,
mouseWheel: bool,
preventDefault: bool,
scrollX: bool,
scrollY: bool,
startX: number,
startY: number,
tap: oneOfType([
bool,
string
]),
tap: oneOfType([bool, string]),

// Scrollbars
scrollbars: oneOf([true, false, 'custom']),
Expand All @@ -90,10 +108,7 @@ const iScrollOptionsPropType = shape({
shrinkScrollbars: shrinkPropType,

// Indicators
indicators: oneOfType([
indicatorPropType,
PropTypes.arrayOf(indicatorPropType)
]),
indicators: oneOfType([indicatorPropType, PropTypes.arrayOf(indicatorPropType)]),

// Snap
snap: oneOfType([string, bool]),
Expand All @@ -119,7 +134,7 @@ const iScrollOptionsPropType = shape({
mouseWheelSpeed: number,
preventDefaultException: shape({
className: instanceOf(RegExp),
tagName: instanceOf(RegExp)
tagName: instanceOf(RegExp)
}),
resizePolling: number,

Expand All @@ -129,18 +144,14 @@ const iScrollOptionsPropType = shape({

// Generate propTypes with event function validating
const reactIScrollPropTypes = {
defer: oneOfType([
PropTypes.bool,
PropTypes.number
]),
defer: oneOfType([bool, number]),
iScroll: iScrollPropType,
onRefresh: func,
options: iScrollOptionsPropType
}


export default function(eventsNames) {
for(const eventName in eventsNames) {
for (const eventName in eventsNames) {
reactIScrollPropTypes[eventName] = func
}

Expand Down

0 comments on commit 4dd3b68

Please sign in to comment.