Skip to content

Commit 1aad1a0

Browse files
committed
style: correct indentation
1 parent fb3ca5e commit 1aad1a0

15 files changed

+783
-783
lines changed

src/extendReactClass.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,39 @@ import linkClass from './linkClass';
1212
* @returns {ReactClass}
1313
*/
1414
export default (Component: Object, defaultStyles: Object, options: Object) => {
15-
const WrappedComponent = class extends Component {
16-
render () {
17-
let propsChanged,
18-
styles;
19-
20-
propsChanged = false;
21-
22-
if (this.props.styles) {
23-
styles = this.props.styles;
24-
} else if (_.isObject(defaultStyles)) {
25-
this.props = _.assign({}, this.props, {
26-
styles: defaultStyles
27-
});
28-
29-
propsChanged = true;
30-
styles = defaultStyles;
31-
} else {
32-
styles = {};
33-
}
34-
35-
const renderResult = super.render();
36-
37-
if (propsChanged) {
38-
delete this.props.styles;
39-
}
40-
41-
if (renderResult) {
42-
return linkClass(renderResult, styles, options);
43-
}
44-
45-
return React.createElement('noscript');
46-
}
15+
const WrappedComponent = class extends Component {
16+
render () {
17+
let propsChanged,
18+
styles;
19+
20+
propsChanged = false;
21+
22+
if (this.props.styles) {
23+
styles = this.props.styles;
24+
} else if (_.isObject(defaultStyles)) {
25+
this.props = _.assign({}, this.props, {
26+
styles: defaultStyles
27+
});
28+
29+
propsChanged = true;
30+
styles = defaultStyles;
31+
} else {
32+
styles = {};
33+
}
34+
35+
const renderResult = super.render();
36+
37+
if (propsChanged) {
38+
delete this.props.styles;
39+
}
40+
41+
if (renderResult) {
42+
return linkClass(renderResult, styles, options);
43+
}
44+
45+
return React.createElement('noscript');
46+
}
4747
};
4848

49-
return hoistNonReactStatics(WrappedComponent, Component);
49+
return hoistNonReactStatics(WrappedComponent, Component);
5050
};

src/generateAppendClassName.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,39 @@ import Map from './simple-map';
33
const stylesIndex = new Map();
44

55
export default (styles, styleNames: Array<string>, errorWhenNotFound: boolean): string => {
6-
let appendClassName,
7-
stylesIndexMap;
6+
let appendClassName,
7+
stylesIndexMap;
88

9-
stylesIndexMap = stylesIndex.get(styles);
9+
stylesIndexMap = stylesIndex.get(styles);
1010

11-
if (stylesIndexMap) {
12-
const styleNameIndex = stylesIndexMap.get(styleNames);
11+
if (stylesIndexMap) {
12+
const styleNameIndex = stylesIndexMap.get(styleNames);
1313

14-
if (styleNameIndex) {
15-
return styleNameIndex;
16-
}
17-
} else {
18-
stylesIndexMap = new Map();
19-
stylesIndex.set(styles, new Map());
14+
if (styleNameIndex) {
15+
return styleNameIndex;
2016
}
21-
22-
appendClassName = '';
23-
24-
for (const styleName in styleNames) {
25-
if (styleNames.hasOwnProperty(styleName)) {
26-
const className = styles[styleNames[styleName]];
27-
28-
if (className) {
29-
appendClassName += ' ' + className;
30-
} else if (errorWhenNotFound === true) {
31-
throw new Error('"' + styleNames[styleName] + '" CSS module is undefined.');
32-
}
33-
}
17+
} else {
18+
stylesIndexMap = new Map();
19+
stylesIndex.set(styles, new Map());
20+
}
21+
22+
appendClassName = '';
23+
24+
for (const styleName in styleNames) {
25+
if (styleNames.hasOwnProperty(styleName)) {
26+
const className = styles[styleNames[styleName]];
27+
28+
if (className) {
29+
appendClassName += ' ' + className;
30+
} else if (errorWhenNotFound === true) {
31+
throw new Error('"' + styleNames[styleName] + '" CSS module is undefined.');
32+
}
3433
}
34+
}
3535

36-
appendClassName = appendClassName.trim();
36+
appendClassName = appendClassName.trim();
3737

38-
stylesIndexMap.set(styleNames, appendClassName);
38+
stylesIndexMap.set(styleNames, appendClassName);
3939

40-
return appendClassName;
40+
return appendClassName;
4141
};

src/index.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,45 @@ type TypeOptions = {};
1212
* Determines if the given object has the signature of a class that inherits React.Component.
1313
*/
1414
const isReactComponent = (maybeReactComponent: any): boolean => {
15-
return 'prototype' in maybeReactComponent && _.isFunction(maybeReactComponent.prototype.render);
15+
return 'prototype' in maybeReactComponent && _.isFunction(maybeReactComponent.prototype.render);
1616
};
1717

1818
/**
1919
* When used as a function.
2020
*/
2121
const functionConstructor = (Component: Function, defaultStyles: Object, options: TypeOptions): Function => {
22-
let decoratedClass;
22+
let decoratedClass;
2323

24-
const configuration = makeConfiguration(options);
24+
const configuration = makeConfiguration(options);
2525

26-
if (isReactComponent(Component)) {
27-
decoratedClass = extendReactClass(Component, defaultStyles, configuration);
28-
} else {
29-
decoratedClass = wrapStatelessFunction(Component, defaultStyles, configuration);
30-
}
26+
if (isReactComponent(Component)) {
27+
decoratedClass = extendReactClass(Component, defaultStyles, configuration);
28+
} else {
29+
decoratedClass = wrapStatelessFunction(Component, defaultStyles, configuration);
30+
}
3131

32-
if (Component.displayName) {
33-
decoratedClass.displayName = Component.displayName;
34-
} else {
35-
decoratedClass.displayName = Component.name;
36-
}
32+
if (Component.displayName) {
33+
decoratedClass.displayName = Component.displayName;
34+
} else {
35+
decoratedClass.displayName = Component.name;
36+
}
3737

38-
return decoratedClass;
38+
return decoratedClass;
3939
};
4040

4141
/**
4242
* When used as a ES7 decorator.
4343
*/
4444
const decoratorConstructor = (defaultStyles: Object, options: TypeOptions): Function => {
45-
return (Component: Function) => {
46-
return functionConstructor(Component, defaultStyles, options);
47-
};
45+
return (Component: Function) => {
46+
return functionConstructor(Component, defaultStyles, options);
47+
};
4848
};
4949

5050
export default (...args) => {
51-
if (_.isFunction(args[0])) {
52-
return functionConstructor(args[0], args[1], args[2]);
53-
} else {
54-
return decoratorConstructor(args[0], args[1]);
55-
}
51+
if (_.isFunction(args[0])) {
52+
return functionConstructor(args[0], args[1], args[2]);
53+
} else {
54+
return decoratorConstructor(args[0], args[1]);
55+
}
5656
};

src/isIterable.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ const OLD_ITERATOR_SYMBOL = '@@iterator';
88
* @see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols
99
*/
1010
export default (maybeIterable: any): boolean => {
11-
let iterator;
11+
let iterator;
1212

13-
if (!_.isObject(maybeIterable)) {
14-
return false;
15-
}
13+
if (!_.isObject(maybeIterable)) {
14+
return false;
15+
}
1616

17-
if (ITERATOR_SYMBOL) {
18-
iterator = maybeIterable[ITERATOR_SYMBOL];
19-
} else {
20-
iterator = maybeIterable[OLD_ITERATOR_SYMBOL];
21-
}
17+
if (ITERATOR_SYMBOL) {
18+
iterator = maybeIterable[ITERATOR_SYMBOL];
19+
} else {
20+
iterator = maybeIterable[OLD_ITERATOR_SYMBOL];
21+
}
2222

23-
return _.isFunction(iterator);
23+
return _.isFunction(iterator);
2424
};

src/linkClass.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,54 @@ import parseStyleName from './parseStyleName';
88
import generateAppendClassName from './generateAppendClassName';
99

1010
const linkElement = (element: ReactElement, styles: Object, configuration: Object): ReactElement => {
11-
let appendClassName,
12-
elementIsFrozen,
13-
elementShallowCopy;
11+
let appendClassName,
12+
elementIsFrozen,
13+
elementShallowCopy;
1414

15-
elementShallowCopy = element;
15+
elementShallowCopy = element;
1616

17-
if (Object.isFrozen && Object.isFrozen(elementShallowCopy)) {
18-
elementIsFrozen = true;
17+
if (Object.isFrozen && Object.isFrozen(elementShallowCopy)) {
18+
elementIsFrozen = true;
1919

2020
// https://github.com/facebook/react/blob/v0.13.3/src/classic/element/ReactElement.js#L131
21-
elementShallowCopy = objectUnfreeze(elementShallowCopy);
22-
elementShallowCopy.props = objectUnfreeze(elementShallowCopy.props);
23-
}
21+
elementShallowCopy = objectUnfreeze(elementShallowCopy);
22+
elementShallowCopy.props = objectUnfreeze(elementShallowCopy.props);
23+
}
2424

25-
const styleNames = parseStyleName(elementShallowCopy.props.styleName || '', configuration.allowMultiple);
25+
const styleNames = parseStyleName(elementShallowCopy.props.styleName || '', configuration.allowMultiple);
2626

27-
if (React.isValidElement(elementShallowCopy.props.children)) {
28-
elementShallowCopy.props.children = linkElement(React.Children.only(elementShallowCopy.props.children), styles, configuration);
29-
} else if (_.isArray(elementShallowCopy.props.children) || isIterable(elementShallowCopy.props.children)) {
30-
elementShallowCopy.props.children = React.Children.map(elementShallowCopy.props.children, (node) => {
31-
if (React.isValidElement(node)) {
32-
return linkElement(node, styles, configuration);
33-
} else {
34-
return node;
35-
}
36-
});
37-
}
27+
if (React.isValidElement(elementShallowCopy.props.children)) {
28+
elementShallowCopy.props.children = linkElement(React.Children.only(elementShallowCopy.props.children), styles, configuration);
29+
} else if (_.isArray(elementShallowCopy.props.children) || isIterable(elementShallowCopy.props.children)) {
30+
elementShallowCopy.props.children = React.Children.map(elementShallowCopy.props.children, (node) => {
31+
if (React.isValidElement(node)) {
32+
return linkElement(node, styles, configuration);
33+
} else {
34+
return node;
35+
}
36+
});
37+
}
3838

39-
if (styleNames.length) {
40-
appendClassName = generateAppendClassName(styles, styleNames, configuration.errorWhenNotFound);
39+
if (styleNames.length) {
40+
appendClassName = generateAppendClassName(styles, styleNames, configuration.errorWhenNotFound);
4141

42-
if (appendClassName) {
43-
if (elementShallowCopy.props.className) {
44-
appendClassName = elementShallowCopy.props.className + ' ' + appendClassName;
45-
}
42+
if (appendClassName) {
43+
if (elementShallowCopy.props.className) {
44+
appendClassName = elementShallowCopy.props.className + ' ' + appendClassName;
45+
}
4646

47-
elementShallowCopy.props.className = appendClassName;
48-
}
47+
elementShallowCopy.props.className = appendClassName;
4948
}
49+
}
5050

51-
delete elementShallowCopy.props.styleName;
51+
delete elementShallowCopy.props.styleName;
5252

53-
if (elementIsFrozen) {
54-
Object.freeze(elementShallowCopy.props);
55-
Object.freeze(elementShallowCopy);
56-
}
53+
if (elementIsFrozen) {
54+
Object.freeze(elementShallowCopy.props);
55+
Object.freeze(elementShallowCopy);
56+
}
5757

58-
return elementShallowCopy;
58+
return elementShallowCopy;
5959
};
6060

6161
/**
@@ -65,9 +65,9 @@ const linkElement = (element: ReactElement, styles: Object, configuration: Objec
6565
*/
6666
export default (element: ReactElement, styles = {}, configuration = {}): ReactElement => {
6767
// @see https://github.com/gajus/react-css-modules/pull/30
68-
if (!_.isObject(element)) {
69-
return element;
70-
}
68+
if (!_.isObject(element)) {
69+
return element;
70+
}
7171

72-
return linkElement(element, styles, configuration);
72+
return linkElement(element, styles, configuration);
7373
};

src/makeConfiguration.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ import _ from 'lodash';
1212
* @returns {CSSModules~Options}
1313
*/
1414
export default (userConfiguration = {}) => {
15-
const configuration = {
16-
allowMultiple: false,
17-
errorWhenNotFound: true
18-
};
15+
const configuration = {
16+
allowMultiple: false,
17+
errorWhenNotFound: true
18+
};
1919

20-
_.forEach(userConfiguration, (value, name) => {
21-
if (_.isUndefined(configuration[name])) {
22-
throw new Error('Unknown configuration property "' + name + '".');
23-
}
20+
_.forEach(userConfiguration, (value, name) => {
21+
if (_.isUndefined(configuration[name])) {
22+
throw new Error('Unknown configuration property "' + name + '".');
23+
}
2424

25-
if (!_.isBoolean(value)) {
26-
throw new Error('"' + name + '" property value must be a boolean.');
27-
}
25+
if (!_.isBoolean(value)) {
26+
throw new Error('"' + name + '" property value must be a boolean.');
27+
}
2828

29-
configuration[name] = value;
30-
});
29+
configuration[name] = value;
30+
});
3131

32-
return configuration;
32+
return configuration;
3333
};

0 commit comments

Comments
 (0)