Skip to content

Commit a940203

Browse files
committed
added a build process and built version to git
1 parent fed4e38 commit a940203

File tree

7 files changed

+132
-9
lines changed

7 files changed

+132
-9
lines changed

.babelrc

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

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[*.js]
2+
indent_style = space
3+
indent_size = 2

dist/tweet-embed.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
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; }; }();
8+
9+
var _react = require('react');
10+
11+
var _react2 = _interopRequireDefault(_react);
12+
13+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14+
15+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16+
17+
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; }
18+
19+
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; }
20+
21+
var callbacks = [];
22+
23+
function addScript(src, cb) {
24+
if (callbacks.length === 0) {
25+
callbacks.push(cb);
26+
var s = document.createElement('script');
27+
s.setAttribute('src', src);
28+
s.onload = function () {
29+
return callbacks.forEach(function (cb) {
30+
return cb();
31+
});
32+
};
33+
document.body.appendChild(s);
34+
} else {
35+
callbacks.push(cb);
36+
}
37+
}
38+
39+
var TweetEmbed = function (_React$Component) {
40+
_inherits(TweetEmbed, _React$Component);
41+
42+
function TweetEmbed() {
43+
_classCallCheck(this, TweetEmbed);
44+
45+
return _possibleConstructorReturn(this, (TweetEmbed.__proto__ || Object.getPrototypeOf(TweetEmbed)).apply(this, arguments));
46+
}
47+
48+
_createClass(TweetEmbed, [{
49+
key: 'componentDidMount',
50+
value: function componentDidMount() {
51+
var _this2 = this;
52+
53+
var options = this.props.options || {};
54+
55+
var renderTweet = function renderTweet() {
56+
window.twttr.widgets.createTweetEmbed(_this2.props.id, _this2._div, options);
57+
};
58+
if (!window.twttr) {
59+
addScript('//platform.twitter.com/widgets.js', renderTweet);
60+
} else {
61+
renderTweet();
62+
}
63+
}
64+
}, {
65+
key: 'render',
66+
value: function render() {
67+
var _this3 = this;
68+
69+
return _react2.default.createElement('div', { ref: function ref(c) {
70+
_this3._div = c;
71+
} });
72+
}
73+
}]);
74+
75+
return TweetEmbed;
76+
}(_react2.default.Component);
77+
78+
TweetEmbed.propTypes = {
79+
id: _react.PropTypes.string,
80+
options: _react.PropTypes.object
81+
};
82+
83+
exports.default = TweetEmbed;

package.json

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "react-tweet-embed",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "react component that you supply tweet id and you'll get a tweet embed back, nothing more",
5-
"main": "tweet-embed.js",
6-
"jspm": {
7-
"format": "esm"
8-
},
5+
"main": "dist/tweet-embed.js",
96
"scripts": {
10-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "BABEL_ENV=test ava",
8+
"pretest": "standard",
9+
"build": "babel tweet-embed.js --out-dir dist",
10+
"clean": "rimraf dist",
11+
"prepublish": "npm test && npm run clean && npm run build"
1112
},
1213
"repository": {
1314
"type": "git",
@@ -21,5 +22,27 @@
2122
"homepage": "https://github.com/capaj/react-tweet-embed#readme",
2223
"dependencies": {
2324
"react": "^15.3.2"
25+
},
26+
"devDependencies": {
27+
"ava": "^0.16.0",
28+
"babel": "^6.5.2",
29+
"babel-cli": "^6.18.0",
30+
"babel-preset-react-app": "^1.0.0",
31+
"react-snappy": "^0.2.3",
32+
"standard": "^8.5.0"
33+
},
34+
"ava": {
35+
"files": [
36+
"*.spec.js"
37+
],
38+
"babel": "inherit",
39+
"require": [
40+
"babel-register"
41+
]
42+
},
43+
"standard": {
44+
"ignore": [
45+
"dist/"
46+
]
2447
}
2548
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div></div>

tweet-embed.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {PropTypes} from 'react'
22

3-
var callbacks = [];
3+
const callbacks = []
44

55
function addScript (src, cb) {
66
if (callbacks.length === 0) {
@@ -16,7 +16,7 @@ function addScript (src, cb) {
1616

1717
class TweetEmbed extends React.Component {
1818
componentDidMount () {
19-
const options = this.props.options || {};
19+
const options = this.props.options || {}
2020

2121
const renderTweet = () => {
2222
window.twttr.widgets.createTweetEmbed(this.props.id, this._div, options)
@@ -28,7 +28,9 @@ class TweetEmbed extends React.Component {
2828
}
2929
}
3030
render () {
31-
return React.createElement('div', { ref: (c) => this._div = c })
31+
return <div ref={(c) => {
32+
this._div = c
33+
}} />
3234
}
3335
}
3436

tweet-embed.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import test from 'ava'
2+
import snappy from 'react-snappy'
3+
import TweetEmbed from './tweet-embed'
4+
import React from 'react'
5+
6+
test('renders', t => {
7+
snappy.check(<TweetEmbed id='692527862369357824' />)
8+
})

0 commit comments

Comments
 (0)