apollo-map-props
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -1,3 +0,34 @@ | ||
export { default as withClient } from './withClient'; | ||
export { default as withMutation } from './withMutation'; | ||
export { default as withQuery } from './withQuery'; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _withClient = require('./withClient'); | ||
Object.defineProperty(exports, 'withClient', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_withClient).default; | ||
} | ||
}); | ||
var _withMutation = require('./withMutation'); | ||
Object.defineProperty(exports, 'withMutation', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_withMutation).default; | ||
} | ||
}); | ||
var _withQuery = require('./withQuery'); | ||
Object.defineProperty(exports, 'withQuery', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_withQuery).default; | ||
} | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
@@ -1,14 +0,30 @@ | ||
import _extends from 'babel-runtime/helpers/extends'; | ||
import React from 'react'; | ||
import { ApolloConsumer } from 'react-apollo'; | ||
'use strict'; | ||
export default function withClient(mapClientToProps) { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
exports.default = withClient; | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _reactApollo = require('react-apollo'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function withClient(mapClientToProps) { | ||
return function (WrappedComponent) { | ||
var component = function component(props) { | ||
return React.createElement( | ||
ApolloConsumer, | ||
return _react2.default.createElement( | ||
_reactApollo.ApolloConsumer, | ||
null, | ||
function (client) { | ||
var mappedProps = mapClientToProps(client, props); | ||
return React.createElement(WrappedComponent, _extends({}, props, mappedProps)); | ||
return _react2.default.createElement(WrappedComponent, (0, _extends3.default)({}, props, mappedProps)); | ||
} | ||
@@ -18,5 +34,5 @@ ); | ||
component.displayName = 'withClient(' + WrappedComponent.displayName + ')'; | ||
return component; | ||
component.displayName = 'withClient(' + (WrappedComponent.displayName || WrappedComponent.name || 'Component') + ')'; | ||
return _react2.default.memo(component); | ||
}; | ||
} |
@@ -1,12 +0,31 @@ | ||
import _extends from 'babel-runtime/helpers/extends'; | ||
import _get from 'lodash/get'; | ||
import React from 'react'; | ||
import { Mutation } from 'react-apollo'; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
exports.default = withMutation; | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _reactApollo = require('react-apollo'); | ||
var _get = require('./get'); | ||
var _get2 = _interopRequireDefault(_get); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function getDisplayName(mapProps) { | ||
var props = mapProps({}); | ||
return _get(props, 'mutation.definitions[0].name.value'); | ||
return (0, _get2.default)(props, 'mutation', 'definitions', 0, 'name', 'value'); | ||
} | ||
export default function withMutation(mapPropsFn, mapResultToPropsFn) { | ||
function withMutation(mapPropsFn, mapResultToPropsFn) { | ||
var mapProps = mapPropsFn || function () { | ||
@@ -22,8 +41,8 @@ return {}; | ||
var component = function component(props) { | ||
return React.createElement( | ||
Mutation, | ||
_extends({ displayName: displayName }, mapProps(props)), | ||
return _react2.default.createElement( | ||
_reactApollo.Mutation, | ||
(0, _extends3.default)({ displayName: displayName }, mapProps(props)), | ||
function (mutate, result) { | ||
var mappedProps = mapResultToProps(mutate, result, props); | ||
return React.createElement(WrappedComponent, _extends({}, props, mappedProps)); | ||
return _react2.default.createElement(WrappedComponent, (0, _extends3.default)({}, props, mappedProps)); | ||
} | ||
@@ -34,4 +53,4 @@ ); | ||
component.displayName = 'withMutation(' + displayName + ')'; | ||
return component; | ||
return _react2.default.memo(component); | ||
}; | ||
} |
@@ -1,7 +0,25 @@ | ||
import _extends from 'babel-runtime/helpers/extends'; | ||
import _get from 'lodash/get'; | ||
import React from 'react'; | ||
import { Query } from 'react-apollo'; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
exports.default = withQuery; | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _reactApollo = require('react-apollo'); | ||
var _get = require('./get'); | ||
var _get2 = _interopRequireDefault(_get); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var DEFAULT_FETCH_POLICY = 'cache-and-network'; | ||
@@ -11,6 +29,6 @@ | ||
var props = mapProps({}); | ||
return _get(props, 'query.definitions[0].name.value'); | ||
return (0, _get2.default)(props, 'query', 'definitions', 0, 'name', 'value'); | ||
} | ||
export default function withQuery(mapProps, mapResultToProps) { | ||
function withQuery(mapProps, mapResultToProps) { | ||
var displayName = getDisplayName(mapProps); | ||
@@ -20,8 +38,8 @@ | ||
var component = function component(props) { | ||
return React.createElement( | ||
Query, | ||
_extends({ fetchPolicy: DEFAULT_FETCH_POLICY }, mapProps(props)), | ||
return _react2.default.createElement( | ||
_reactApollo.Query, | ||
(0, _extends3.default)({ fetchPolicy: DEFAULT_FETCH_POLICY }, mapProps(props)), | ||
function (result) { | ||
var mappedProps = mapResultToProps(result, props); | ||
return React.createElement(WrappedComponent, _extends({}, props, mappedProps)); | ||
return _react2.default.createElement(WrappedComponent, (0, _extends3.default)({}, props, mappedProps)); | ||
} | ||
@@ -32,4 +50,4 @@ ); | ||
component.displayName = 'withQuery(' + displayName + ')'; | ||
return component; | ||
return _react2.default.memo(component); | ||
}; | ||
} |
{ | ||
"name": "apollo-map-props", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "To help with props mapping when using apollo with React", | ||
@@ -8,4 +8,4 @@ "main": "build/index.js", | ||
"scripts": { | ||
"build": "npm run babelify:esmodules", | ||
"babelify:esmodules": "BABEL_ENV=esmodules babel src --out-dir build" | ||
"build": "npm run babelify:modules", | ||
"babelify:modules": "BABEL_ENV=modules babel src --out-dir build" | ||
}, | ||
@@ -12,0 +12,0 @@ "repository": { |
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
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
15757
15
214