react-transporter
Advanced tools
Comparing version 0.5.11 to 0.5.12
@@ -10,7 +10,7 @@ 'use strict'; | ||
exports.default = createMutation; | ||
function createMutation(schema, options) { | ||
function createMutation(mutation, options) { | ||
return _extends({ | ||
type: 'TRANSPORTER_MUTATION', | ||
schema: schema | ||
mutation: mutation | ||
}, options); | ||
} |
@@ -10,7 +10,7 @@ 'use strict'; | ||
exports.default = createQuery; | ||
function createQuery(schema, options) { | ||
function createQuery(query, options) { | ||
return _extends({ | ||
type: 'TRANSPORTER_QUERY', | ||
schema: schema | ||
query: query | ||
}, options); | ||
} |
@@ -14,4 +14,4 @@ "use strict"; | ||
this.fetch = function (schema, variables) { | ||
return _this.request(schema, variables); | ||
this.fetch = function (query, variables) { | ||
return _this.request(query, variables); | ||
}; | ||
@@ -18,0 +18,0 @@ |
@@ -69,2 +69,3 @@ 'use strict'; | ||
var contextTypes = { | ||
// eslint-disable-next-line react/forbid-prop-types | ||
store: _propTypes2.default.object, | ||
@@ -96,2 +97,4 @@ isInBoundary: _propTypes2.default.bool | ||
/* eslint-disable react/destructuring-assignment */ | ||
var Container = function (_React$Component) { | ||
@@ -147,6 +150,11 @@ _inherits(Container, _React$Component); | ||
_this.state = { | ||
loaders: initialState, | ||
Component: !hasCodeSplit ? component : null | ||
loaders: initialState | ||
}; | ||
// Set component | ||
_this.component = { | ||
Component: !hasCodeSplit ? component : null, | ||
isConnected: false | ||
}; | ||
// Set cache | ||
@@ -232,3 +240,3 @@ _this.cache = {}; | ||
// Load code bundle if present on server & client | ||
if (hasCodeSplit && !this.state.Component) { | ||
if (hasCodeSplit && !this.component.Component) { | ||
this.handleLoad('bundle', component.bundle(), false); | ||
@@ -274,3 +282,3 @@ } | ||
if (key === 'bundle') { | ||
_this5.state.Component = resolveES6(result); | ||
_this5.component.Component = resolveES6(result); | ||
} | ||
@@ -409,13 +417,17 @@ | ||
var props = _extends({}, loaderProps, this.props); | ||
var Component = this.state.Component; | ||
// connect selectors and actions if present | ||
if (config.selectors || config.actions) { | ||
// TODO: cache function call to enhanceWithConnect in production | ||
var EnhancedComponent = (0, _enhanceWithConnect2.default)(Component); | ||
if (!this.component.isConnected) { | ||
this.component.Component = (0, _enhanceWithConnect2.default)(this.component.Component); | ||
this.component.isConnected = true; | ||
} | ||
return _react2.default.createElement(EnhancedComponent, { selectors: config.selectors, actions: config.actions, props: props }); | ||
var _Component = this.component.Component; | ||
return _react2.default.createElement(_Component, { selectors: config.selectors, actions: config.actions, props: props }); | ||
} | ||
var Component = this.component.Component; | ||
return _react2.default.createElement(Component, props); | ||
@@ -427,2 +439,3 @@ } | ||
}(_react2.default.Component); | ||
/* eslint-enable */ | ||
@@ -429,0 +442,0 @@ Container.displayName = 'Load(' + name + ')'; |
@@ -41,3 +41,3 @@ 'use strict'; | ||
function query(schema) { | ||
function query(queryParam) { | ||
var allOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -48,4 +48,2 @@ | ||
var schemaBody = schema.loc.source.body; | ||
return { | ||
@@ -60,3 +58,3 @@ request: function request(_ref, dispatch) { | ||
return resolve(); | ||
})) : load(dispatch((0, _createQuery2.default)(schemaBody, options))); | ||
})) : load(dispatch((0, _createQuery2.default)(queryParam, options))); | ||
}, | ||
@@ -74,3 +72,3 @@ props: function props(_ref2, dispatch) { | ||
return load(dispatch((0, _createQuery2.default)(schemaBody, _extends({}, options, localOptions)))); | ||
return load(dispatch((0, _createQuery2.default)(queryParam, _extends({}, options, localOptions)))); | ||
}, | ||
@@ -84,3 +82,3 @@ fetchMore: function fetchMore() { | ||
return load(dispatch((0, _createQuery2.default)(schemaBody, _extends({}, options, localOptions)), { | ||
return load(dispatch((0, _createQuery2.default)(queryParam, _extends({}, options, localOptions)), { | ||
showWhileLoading: true | ||
@@ -91,3 +89,3 @@ })); | ||
var timeout = setInterval(function () { | ||
load(dispatch((0, _createQuery2.default)(schemaBody, options), { | ||
load(dispatch((0, _createQuery2.default)(queryParam, options), { | ||
showWhileLoading: true | ||
@@ -94,0 +92,0 @@ })); |
@@ -9,4 +9,2 @@ 'use strict'; | ||
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; }; | ||
exports.default = createEntitiesReducer; | ||
@@ -49,4 +47,4 @@ | ||
var nextState = _extends({}, state); | ||
var action = _extends({}, baseAction); | ||
var nextState = JSON.parse(JSON.stringify(state)); | ||
var action = JSON.parse(JSON.stringify(baseAction)); | ||
@@ -130,6 +128,17 @@ // TRANSPORTER_REQUEST_START | ||
// update stored value | ||
(0, _updateValueBeforeRevertingOptimisticUpdate2.default)(position, state, action, getField); | ||
var value = (0, _updateValueBeforeRevertingOptimisticUpdate2.default)(position, nextState, action, getField); | ||
if (value) { | ||
if (!nextState.data[type]) { | ||
nextState.data[type] = {}; | ||
} | ||
if (!nextState.data[type][id]) { | ||
nextState.data[type][id] = {}; | ||
} | ||
nextState.data[type][id][field] = value; | ||
} | ||
// revert optimistic value | ||
nextState.optimistic.updates[type][id][field] = (0, _revertOptimisticUpdate2.default)(position, state, action, getField); | ||
nextState.optimistic.updates[type][id][field] = (0, _revertOptimisticUpdate2.default)(position, nextState, action, getField); | ||
if (nextState.optimistic.updates[type][id][field] === undefined) { | ||
@@ -136,0 +145,0 @@ delete nextState.optimistic.updates[type][id][field]; |
@@ -6,5 +6,2 @@ 'use strict'; | ||
}); | ||
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; }; | ||
exports.default = createRootsReducer; | ||
@@ -39,4 +36,4 @@ | ||
var nextState = _extends({}, state); | ||
var action = _extends({}, baseAction); | ||
var nextState = JSON.parse(JSON.stringify(state)); | ||
var action = JSON.parse(JSON.stringify(baseAction)); | ||
@@ -43,0 +40,0 @@ // TRANSPORTER_REQUEST_START |
@@ -51,4 +51,6 @@ 'use strict'; | ||
var queryBody = request.type === 'TRANSPORTER_MUTATION' ? request.mutation.loc.source.body : request.query.loc.source.body; | ||
// dispatch query | ||
return fetch(request.schema, request.variables).then(function (result) { | ||
return fetch(queryBody, request.variables).then(function (result) { | ||
return result.json().then(function (responseData) { | ||
@@ -87,2 +89,4 @@ var state = getState(); | ||
try { | ||
var data = makeData(request.updater, getState, responseData.data); | ||
// Try to add response to store | ||
@@ -94,3 +98,3 @@ dispatch({ | ||
optimisticData: optimisticData, | ||
data: responseData.data | ||
data: data | ||
}); | ||
@@ -97,0 +101,0 @@ } catch (error) { |
@@ -106,3 +106,4 @@ 'use strict'; | ||
if (!this.data.entities[type]) this.data.entities[type] = {}; | ||
this.data.entities[type][id] = entity.values; | ||
this.data.entities[type][id] = this.data.entities[type][id] ? Object.assign({}, this.data.entities[type][id], entity.values) : entity.values; | ||
} | ||
@@ -109,0 +110,0 @@ }, { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
var _StoreQuery = require('./../StoreQuery'); | ||
var _StoreQuery = require('../StoreQuery'); | ||
@@ -11,0 +11,0 @@ var _StoreQuery2 = _interopRequireDefault(_StoreQuery); |
{ | ||
"name": "react-transporter", | ||
"version": "0.5.11", | ||
"version": "0.5.12", | ||
"main": "./lib/index.js", | ||
@@ -31,20 +31,19 @@ "description": "React.js Redux GraphQL client", | ||
"dependencies": { | ||
"prop-types": "^15.6.1", | ||
"react-tree-walker": "^4.0.2", | ||
"serialize-javascript": "^1.5.0" | ||
"prop-types": "^15.7.2", | ||
"react-tree-walker": "^4.3.0", | ||
"serialize-javascript": "^1.6.1" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "6.26.0", | ||
"eslint": "4.9.0", | ||
"react": "16.4.0", | ||
"react-dom": "16.4.0", | ||
"react-kickstarter": "0.3.5", | ||
"react-redux": "5.0.7", | ||
"redux": "4.0.0", | ||
"react": "16.8.2", | ||
"react-dom": "16.8.2", | ||
"react-kickstarter": "0.4.5", | ||
"react-redux": "5.1.1", | ||
"redux": "4.0.1", | ||
"redux-thunk": "2.3.0", | ||
"rimraf": "2.6.2" | ||
"rimraf": "2.6.3" | ||
}, | ||
"peerDependencies": { | ||
"react": ">=15", | ||
"react-dom": ">=15", | ||
"react": ">=16.4.2", | ||
"react-dom": ">=16.4.2", | ||
"react-redux": ">=5", | ||
@@ -51,0 +50,0 @@ "redux": ">=3", |
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
99126
8
2199
Updatedprop-types@^15.7.2
Updatedreact-tree-walker@^4.3.0
Updatedserialize-javascript@^1.6.1