Skip to content

Commit

Permalink
added a build process and built version to git
Browse files Browse the repository at this point in the history
  • Loading branch information
capaj committed Nov 14, 2016
1 parent fed4e38 commit a940203
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "react"]
}
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.js]
indent_style = space
indent_size = 2
83 changes: 83 additions & 0 deletions dist/tweet-embed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

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; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

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; }

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; }

var callbacks = [];

function addScript(src, cb) {
if (callbacks.length === 0) {
callbacks.push(cb);
var s = document.createElement('script');
s.setAttribute('src', src);
s.onload = function () {
return callbacks.forEach(function (cb) {
return cb();
});
};
document.body.appendChild(s);
} else {
callbacks.push(cb);
}
}

var TweetEmbed = function (_React$Component) {
_inherits(TweetEmbed, _React$Component);

function TweetEmbed() {
_classCallCheck(this, TweetEmbed);

return _possibleConstructorReturn(this, (TweetEmbed.__proto__ || Object.getPrototypeOf(TweetEmbed)).apply(this, arguments));
}

_createClass(TweetEmbed, [{
key: 'componentDidMount',
value: function componentDidMount() {
var _this2 = this;

var options = this.props.options || {};

var renderTweet = function renderTweet() {
window.twttr.widgets.createTweetEmbed(_this2.props.id, _this2._div, options);
};
if (!window.twttr) {
addScript('//platform.twitter.com/widgets.js', renderTweet);
} else {
renderTweet();
}
}
}, {
key: 'render',
value: function render() {
var _this3 = this;

return _react2.default.createElement('div', { ref: function ref(c) {
_this3._div = c;
} });
}
}]);

return TweetEmbed;
}(_react2.default.Component);

TweetEmbed.propTypes = {
id: _react.PropTypes.string,
options: _react.PropTypes.object
};

exports.default = TweetEmbed;
35 changes: 29 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "react-tweet-embed",
"version": "1.0.1",
"version": "1.0.2",
"description": "react component that you supply tweet id and you'll get a tweet embed back, nothing more",
"main": "tweet-embed.js",
"jspm": {
"format": "esm"
},
"main": "dist/tweet-embed.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "BABEL_ENV=test ava",
"pretest": "standard",
"build": "babel tweet-embed.js --out-dir dist",
"clean": "rimraf dist",
"prepublish": "npm test && npm run clean && npm run build"
},
"repository": {
"type": "git",
Expand All @@ -21,5 +22,27 @@
"homepage": "https://github.com/capaj/react-tweet-embed#readme",
"dependencies": {
"react": "^15.3.2"
},
"devDependencies": {
"ava": "^0.16.0",
"babel": "^6.5.2",
"babel-cli": "^6.18.0",
"babel-preset-react-app": "^1.0.0",
"react-snappy": "^0.2.3",
"standard": "^8.5.0"
},
"ava": {
"files": [
"*.spec.js"
],
"babel": "inherit",
"require": [
"babel-register"
]
},
"standard": {
"ignore": [
"dist/"
]
}
}
1 change: 1 addition & 0 deletions snapshots/TweetEmbed_id_1_from_tweet-embed.spec.js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div></div>
8 changes: 5 additions & 3 deletions tweet-embed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {PropTypes} from 'react'

var callbacks = [];
const callbacks = []

function addScript (src, cb) {
if (callbacks.length === 0) {
Expand All @@ -16,7 +16,7 @@ function addScript (src, cb) {

class TweetEmbed extends React.Component {
componentDidMount () {
const options = this.props.options || {};
const options = this.props.options || {}

const renderTweet = () => {
window.twttr.widgets.createTweetEmbed(this.props.id, this._div, options)
Expand All @@ -28,7 +28,9 @@ class TweetEmbed extends React.Component {
}
}
render () {
return React.createElement('div', { ref: (c) => this._div = c })
return <div ref={(c) => {
this._div = c
}} />
}
}

Expand Down
8 changes: 8 additions & 0 deletions tweet-embed.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import test from 'ava'
import snappy from 'react-snappy'
import TweetEmbed from './tweet-embed'
import React from 'react'

test('renders', t => {
snappy.check(<TweetEmbed id='692527862369357824' />)
})

0 comments on commit a940203

Please sign in to comment.