Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bumps match-media-mock to 0.1.1, fixing lodash vuln #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions lib/MatchMediaProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
'use strict';

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

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 _class, _temp;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _mobx = require('mobx');

var _matchMedia = require('./matchMedia');

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return 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 breakpoints = void 0;

var setObservable = function setObservable(observable, obj) {
return _mobx.set ? (0, _mobx.set)(observable, obj) : (0, _mobx.extendObservable)(observable, obj);
};

var MatchMediaProvider = (_temp = _class = function (_Component) {
_inherits(MatchMediaProvider, _Component);

function MatchMediaProvider(props) {
_classCallCheck(this, MatchMediaProvider);

var _this = _possibleConstructorReturn(this, (MatchMediaProvider.__proto__ || Object.getPrototypeOf(MatchMediaProvider)).call(this, props));

_this.handleResize = function (e) {
e.preventDefault();
_this.matchBreakpoints();
};

_this.matchBreakpoints = function () {
(0, _mobx.runInAction)('match breakpoints', function () {
(0, _matchMedia.setMatchMediaConfig)();
Object.keys(_this.templates).forEach(function (key) {
return _this.updateBreakpoints(key, _this.templates[key]);
});
});
};

_this.updateBreakpoints = (0, _mobx.action)('update breakpoints', function (key, val) {
var match = (0, _matchMedia.matchMedia)(val).matches;
setObservable(_this.props.breakpoints, _defineProperty({}, key, match));
});

if (!breakpoints) breakpoints = Object.assign({}, (0, _mobx.toJS)(_this.props.breakpoints));
if (!_this.templates) _this.templates = Object.assign({}, (0, _mobx.toJS)(breakpoints));
return _this;
}

_createClass(MatchMediaProvider, [{
key: 'componentDidMount',
value: function componentDidMount() {
window.addEventListener('resize', this.handleResize); // eslint-disable-line
this.matchBreakpoints(); // set initials values
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
window.removeEventListener('resize', this.handleResize); // eslint-disable-line
}
}, {
key: 'render',
value: function render() {
return _react2.default.createElement(
'div',
null,
this.props && this.props.children
);
}
}]);

return MatchMediaProvider;
}(_react.Component), _class.propTypes = {
children: _propTypes2.default.node,
breakpoints: _propTypes2.default.object
}, _temp);
exports.default = MatchMediaProvider;
module.exports = exports['default'];
18 changes: 18 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.MatchMediaProvider = exports.setMatchMediaConfig = exports.matchMedia = undefined;

var _matchMedia = require('./matchMedia');

var _MatchMediaProvider = require('./MatchMediaProvider');

var _MatchMediaProvider2 = _interopRequireDefault(_MatchMediaProvider);

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

exports.matchMedia = _matchMedia.matchMedia;
exports.setMatchMediaConfig = _matchMedia.setMatchMediaConfig;
exports.MatchMediaProvider = _MatchMediaProvider2.default;
43 changes: 43 additions & 0 deletions lib/matchMedia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.setMatchMediaConfig = exports.matchMedia = undefined;

var _matchMediaMock = require('match-media-mock');

var _matchMediaMock2 = _interopRequireDefault(_matchMediaMock);

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

var matchMedia = _matchMediaMock2.default.create();

var config = null;

var setMatchMediaConfig = function setMatchMediaConfig() {
var req = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;

var isClient = typeof window !== 'undefined';

if (!isClient && req) {
config = {
type: 'screen',
width: req.params.width,
height: req.params.height
};
}

if (isClient && !req) {
config = {
type: 'screen',
width: window.innerWidth, // eslint-disable-line
height: window.innerHeight // eslint-disable-line
};
}

if (config) matchMedia.setConfig(config);
};

exports.matchMedia = matchMedia;
exports.setMatchMediaConfig = setMatchMediaConfig;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
}
},
"dependencies": {
"match-media-mock": "0.1.0"
"match-media-mock": "^0.1.1"
},
"peerDependencies": {
"mobx": "^2.5.0 || ^3.0.0 || ^4.0.0 || ^5.0.0",
Expand Down
Loading