Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-react-relay-pagination

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-react-relay-pagination - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

113

build/index.js

@@ -0,18 +1,50 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
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; };
import _ from 'lodash';
import React from 'react';
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; }; }();
export function relayPagination(query, Component) {
return class extends React.Component {
constructor(props) {
var _this;
exports.relayPagination = relayPagination;
exports.mergeResults = mergeResults;
_this = super(props);
var _lodash = require('lodash');
this.loadMore = function (reload, variables) {
var _lodash2 = _interopRequireDefault(_lodash);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
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; }
function relayPagination(query, Component) {
return function (_React$Component) {
_inherits(_class2, _React$Component);
function _class2(props) {
_classCallCheck(this, _class2);
var _this = _possibleConstructorReturn(this, (_class2.__proto__ || Object.getPrototypeOf(_class2)).call(this, props));
_this.loadMore = function (reload, variables) {
return _this.props.data.fetchMore({
query,
query: query,
variables: Object.assign({}, _this.props.data.variables, variables),
updateQuery: function (previousResult, { fetchMoreResult }) {
updateQuery: function updateQuery(previousResult, _ref) {
var fetchMoreResult = _ref.fetchMoreResult;
return mergeResults(previousResult, fetchMoreResult, reload);

@@ -24,20 +56,26 @@ }

console.log('component', Component);
return _this;
}
render() {
return React.createElement(Component, _extends({}, this.props, { loadMore: this.loadMore }));
}
};
_createClass(_class2, [{
key: 'render',
value: function render() {
return _react2.default.createElement(Component, _extends({}, this.props, { loadMore: this.loadMore }));
}
}]);
return _class2;
}(_react2.default.Component);
}
function mergeEdges(previous, current, reload) {
const newEdges = current.edges;
const pageInfo = current.pageInfo;
let edges = [];
var newEdges = current.edges;
var pageInfo = current.pageInfo;
var edges = [];
if (reload) {
edges = [...newEdges];
edges = [].concat(_toConsumableArray(newEdges));
} else {
if (previous) {
edges = [...previous.edges, ...newEdges];
edges = [].concat(_toConsumableArray(previous.edges), _toConsumableArray(newEdges));
} else {

@@ -53,11 +91,32 @@ edges = newEdges;

export function mergeResults(previous, current, reload) {
let result = {};
if (typeof current === 'object') {
for (let property of _.keys(current)) {
if (property === 'edges') {
return mergeEdges(previous, current, reload);
} else {
result[property] = mergeResults(previous[property], current[property]);
function mergeResults(previous, current, reload) {
var result = {};
if ((typeof current === 'undefined' ? 'undefined' : _typeof(current)) === 'object') {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = _lodash2.default.keys(current)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var property = _step.value;
if (property === 'edges') {
return mergeEdges(previous, current, reload);
} else {
result[property] = mergeResults(previous[property], current[property]);
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}

@@ -64,0 +123,0 @@ } else {

{
"name": "apollo-react-relay-pagination",
"version": "1.0.6",
"version": "1.0.7",
"description": "This is a helper library to write less code when using relay style pagination with apollo and react.",

@@ -5,0 +5,0 @@ "main": "build/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc