Comparing version 1.0.0 to 1.1.0
82
index.js
@@ -6,4 +6,6 @@ 'use strict'; | ||
}); | ||
exports.live = exports.connect = exports.Provider = undefined; | ||
exports.connect = exports.Provider = undefined; | ||
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; }; | ||
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; }; }(); | ||
@@ -17,4 +19,2 @@ | ||
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"); } } | ||
@@ -54,48 +54,37 @@ | ||
var connect = exports.connect = function connect(query) { | ||
var nextVersion = 0; | ||
var connect = exports.connect = function connect(query, isLive) { | ||
return function (Consumer) { | ||
var version = nextVersion++; | ||
var Connection = function (_Component2) { | ||
_inherits(Connection, _Component2); | ||
function Connection() { | ||
function Connection(props, context) { | ||
_classCallCheck(this, Connection); | ||
return _possibleConstructorReturn(this, Object.getPrototypeOf(Connection).apply(this, arguments)); | ||
} | ||
var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(Connection).call(this, props, context)); | ||
_createClass(Connection, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
var _this3 = this; | ||
_this2.state = { results: null }; | ||
_this2.version = version; | ||
this.queries = []; | ||
var q = _this2.context.horizon.model(query(_this2.context.horizon))(_this2.props); | ||
Object.keys(query).forEach(function (queryName) { | ||
var results = query[queryName](_this3.context.horizon); | ||
if (results.fetch) results = results.fetch(); | ||
if (isLive) { | ||
q = q.watch(); | ||
} else { | ||
q = q.fetch(); | ||
} | ||
if (results.subscribe) { | ||
_this3.queries.push(results.subscribe(function (data) { | ||
var _this3$setState; | ||
q.subscribe(function (results) { | ||
return _this2.setState({ results: results }); | ||
}); | ||
return _this2; | ||
} | ||
return _this3.setState((_this3$setState = {}, _defineProperty(_this3$setState, queryName, data), _defineProperty(_this3$setState, queryName + '__loaded', true), _this3$setState)); | ||
}, function (error) { | ||
return _this3.setState(_defineProperty({}, queryName + '__error', error)); | ||
})); | ||
} else { | ||
_this3.setState(_defineProperty({}, queryName, results)); | ||
} | ||
}); | ||
} | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
this.queries.forEach(function (q) { | ||
return q.unsubscribe(); | ||
}); | ||
} | ||
}, { | ||
_createClass(Connection, [{ | ||
key: 'render', | ||
value: function render() { | ||
return _react2.default.createElement(Consumer, this.state); | ||
return _react2.default.createElement(Consumer, _extends({}, this.state.results, this.props)); | ||
} | ||
@@ -107,2 +96,17 @@ }]); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Connection.prototype.componentWillUpdate = function componentWillUpdate() { | ||
var _this3 = this; | ||
if (this.version == version) { | ||
return; | ||
} | ||
this.version = version; | ||
this.context.horizon.model(query(this.context.horizon))(this.props).fetch().subscribe(function (results) { | ||
return _this3.setState({ results: results }); | ||
}); | ||
}; | ||
} | ||
Connection.contextTypes = { horizon: _react2.default.PropTypes.any }; | ||
@@ -114,7 +118,5 @@ | ||
var live = exports.live = function live(query) { | ||
return function (hz) { | ||
return query(hz).watch(); | ||
}; | ||
connect.live = function (query) { | ||
return connect(query, true); | ||
}; | ||
{ | ||
"name": "hzql", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Easy querying for Horizon and React", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7990
5
86
1