Skip to content

Commit 2c778ef

Browse files
committed
Updated babel, added tests
1 parent 873257b commit 2c778ef

7 files changed

Lines changed: 62 additions & 30 deletions

File tree

.babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"react",
4+
"es2015"
5+
]
6+
}

example/example.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
},
1414
module: {
1515
loaders: [
16-
{ test: /\.jsx$|\.es6$|\.js$/, loaders: ['babel-loader?stage=0'], exclude: /node_modules/ },
16+
{ test: /\.jsx$|\.es6$|\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ },
1717
]
1818
},
1919
plugins: [

example/server.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
},
2323
module: {
2424
loaders: [
25-
{ test: /\.jsx$|\.es6$|\.js$/, loaders: ['react-hot', 'babel-loader?stage=0'], exclude: /node_modules/ },
25+
{ test: /\.jsx$|\.es6$|\.js$/, loaders: ['react-hot', 'babel-loader'], exclude: /node_modules/ },
2626
{ test: /\.scss$|\.css$/, loader: 'style-loader!style!css!sass' },
2727
{ test: /\.(jpe?g|png|gif)$/i, loader: 'url?limit=10000!img?progressive=true' }
2828
]

lib/image.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,54 @@
11
'use strict';
22

3-
Object.defineProperty(exports, '__esModule', {
3+
Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
66

77
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
88

9-
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
9+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1010

11-
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
11+
var _react = require('react');
1212

13-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
13+
var _react2 = _interopRequireDefault(_react);
1414

15-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
15+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1616

17-
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
17+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1818

19-
var _react = require('react');
19+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2020

21-
var _react2 = _interopRequireDefault(_react);
21+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2222

23-
var Image = (function (_React$Component) {
23+
var Image = function (_React$Component) {
2424
_inherits(Image, _React$Component);
2525

2626
function Image() {
27-
var _this = this;
28-
2927
_classCallCheck(this, Image);
3028

31-
_get(Object.getPrototypeOf(Image.prototype), 'constructor', this).call(this);
32-
33-
this.fadeIn = function () {
34-
_this.setState({ opacity: 1 });
35-
};
29+
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Image).call(this));
3630

37-
this.state = {
31+
_this.state = {
3832
opacity: 0
3933
};
34+
_this.fadeIn = _this.fadeIn.bind(_this);
35+
return _this;
4036
}
4137

4238
_createClass(Image, [{
39+
key: 'fadeIn',
40+
value: function fadeIn() {
41+
this.setState({ opacity: 1 });
42+
}
43+
}, {
4344
key: 'render',
4445
value: function render() {
4546
//this vs including an Object.assign polyfill
4647
var style = this.props.style || {};
4748
style.transition = 'opacity ' + (this.props.speed || 1) + 's';
4849
style.opacity = this.state.opacity;
4950

50-
return _react2['default'].createElement('img', _extends({}, this.props, {
51+
return _react2.default.createElement('img', _extends({}, this.props, {
5152
style: style,
5253
src: this.props.src,
5354
onLoad: this.fadeIn
@@ -56,7 +57,6 @@ var Image = (function (_React$Component) {
5657
}]);
5758

5859
return Image;
59-
})(_react2['default'].Component);
60+
}(_react2.default.Component);
6061

61-
exports['default'] = Image;
62-
module.exports = exports['default'];
62+
exports.default = Image;

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "legit-image",
3-
"version": "0.0.3",
3+
"version": "0.1.0",
44
"description": "an img tag, with built in lazy loading",
55
"main": "lib/image.js",
66
"scripts": {
7-
"compile": "babel src --stage 0 --out-dir lib;",
8-
"prepublish": "babel src --stage 0 --out-dir lib;",
7+
"test": "mocha tests --recursive --require babel-register",
8+
"test-watch": "mocha tests --recursive --require babel-register --watch",
9+
"compile": "babel src --out-dir lib;",
910
"dev-server": "webpack-dev-server --config ./example/server.config.js --hot --port 8881",
1011
"example": "webpack --config ./example/example.config.js"
1112
},
@@ -27,9 +28,16 @@
2728
},
2829
"homepage": "https://github.com/legitcode/image#readme",
2930
"devDependencies": {
30-
"babel": "^5.8.23",
31-
"babel-core": "^5.8.23",
32-
"babel-loader": "^5.3.2",
31+
"babel-cli": "^6.7.5",
32+
"babel-core": "^6.7.6",
33+
"babel-loader": "^6.2.4",
34+
"babel-preset-es2015": "^6.6.0",
35+
"babel-preset-react": "^6.5.0",
36+
"babel-register": "^6.7.2",
37+
"chai": "^3.5.0",
38+
"enzyme": "^2.2.0",
39+
"mocha": "^2.4.5",
40+
"react-addons-test-utils": "^15.0.1",
3341
"react-hot-loader": "^1.3.0",
3442
"webpack": "^1.12.1",
3543
"webpack-dev-server": "^1.10.1"

src/image.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ export default class Image extends React.Component{
77
this.state = {
88
opacity: 0
99
}
10+
this.fadeIn = this.fadeIn.bind(this)
1011
}
1112

12-
fadeIn = () =>{
13+
fadeIn() {
1314
this.setState({opacity: 1})
1415
}
1516

tests/image.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
import { expect } from 'chai'
3+
import { shallow } from 'enzyme'
4+
import Image from '../src/image'
5+
6+
describe('Image', () => {
7+
it('renders with opacity: 0', () => {
8+
const wrapper = shallow(<Image src="blah" />)
9+
expect(wrapper.props().style.opacity).to.equal(0)
10+
})
11+
12+
it('changes opacity on state change', () => {
13+
const wrapper = shallow(<Image src="blah" />)
14+
wrapper.setState({ opacity: 1 })
15+
expect(wrapper.props().style.opacity).to.equal(1)
16+
})
17+
})

0 commit comments

Comments
 (0)