react-transporter
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -9,2 +9,8 @@ Object.defineProperty(exports, "__esModule", { | ||
var _createRequest = require('../request/createRequest'); | ||
var _createRequest2 = _interopRequireDefault(_createRequest); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -16,11 +22,24 @@ | ||
this.config = config; | ||
this.network = config.network; | ||
} | ||
// createMiddleware() { | ||
// TODO | ||
// } | ||
_createClass(Client, [{ | ||
key: 'createMiddleware', | ||
value: function createMiddleware() { | ||
var _this = this; | ||
_createClass(Client, [{ | ||
key: "getConfig", | ||
return function () { | ||
return function (next) { | ||
return function (action) { | ||
if (action.type === 'TRANSPORTER_QUERY' || action.type === 'TRANSPORTER_MUTATION') { | ||
return next((0, _createRequest2.default)(action, _this.network.fetch)); | ||
} | ||
return next(action); | ||
}; | ||
}; | ||
}; | ||
} | ||
}, { | ||
key: 'getConfig', | ||
value: function getConfig() { | ||
@@ -27,0 +46,0 @@ return this.config; |
@@ -7,23 +7,16 @@ "use strict"; | ||
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; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Network = function () { | ||
function Network(request) { | ||
_classCallCheck(this, Network); | ||
var Network = function Network(request) { | ||
var _this = this; | ||
this.request = request; | ||
} | ||
_classCallCheck(this, Network); | ||
_createClass(Network, [{ | ||
key: "fetch", | ||
value: function fetch(schema, variables) { | ||
return this.request(schema, variables); | ||
} | ||
}]); | ||
this.fetch = function (schema, variables) { | ||
return _this.request(schema, variables); | ||
}; | ||
return Network; | ||
}(); | ||
this.request = request; | ||
}; | ||
exports.default = Network; |
@@ -6,2 +6,3 @@ 'use strict'; | ||
}); | ||
exports.withQuery = exports.Provider = exports.createTransporterSelector = exports.createTransporterRequest = exports.reducer = exports.TransporterClient = exports.TransporterNetwork = undefined; | ||
@@ -38,10 +39,8 @@ var _Network = require('./core/Network'); | ||
exports.default = { | ||
TransporterNetwork: _Network2.default, | ||
TransporterClient: _Client2.default, | ||
Provider: _Provider2.default, | ||
withQuery: _withQuery2.default, | ||
createTransporterRequest: _createRequest2.default, | ||
createTransporterSelector: _createSelector2.default, | ||
reducer: _reducers2.default | ||
}; | ||
exports.TransporterNetwork = _Network2.default; | ||
exports.TransporterClient = _Client2.default; | ||
exports.reducer = _reducers2.default; | ||
exports.createTransporterRequest = _createRequest2.default; | ||
exports.createTransporterSelector = _createSelector2.default; | ||
exports.Provider = _Provider2.default; | ||
exports.withQuery = _withQuery2.default; |
@@ -13,6 +13,2 @@ 'use strict'; | ||
var _Transporter = require('../core/Transporter'); | ||
var _Transporter2 = _interopRequireDefault(_Transporter); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -36,8 +32,2 @@ | ||
_createClass(Provider, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
// eslint-disable-next-line react/prop-types | ||
_Transporter2.default.setClient(this.props.client); | ||
} | ||
}, { | ||
key: 'render', | ||
@@ -44,0 +34,0 @@ value: function render() { |
@@ -9,14 +9,24 @@ 'use strict'; | ||
var _utils = require('../utils'); | ||
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 withQuery(request, config) { | ||
var mapStateToProps = function mapStateToProps(state) { | ||
function withQuery(requestFunc) { | ||
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var mapStateToProps = function mapStateToProps(state, props) { | ||
var request = requestFunc(props); | ||
var requestName = request.name || (0, _utils.getRequestName)(request.schema); | ||
var requests = state.transporter.requests; | ||
return { | ||
loading: state.transporter.requests[config.name].loading, | ||
error: state.transporter.requests[config.name].error | ||
loading: requests[requestName] ? requests[requestName].loading : undefined, | ||
error: requests[requestName] ? requests[requestName].error : undefined | ||
}; | ||
}; | ||
var mapDispatchToProps = function mapDispatchToProps(dispatch) { | ||
dispatch(request); | ||
var mapDispatchToProps = function mapDispatchToProps(dispatch, props) { | ||
if (typeof window === 'undefined') { | ||
dispatch(requestFunc(props)); | ||
} | ||
@@ -32,4 +42,4 @@ return { | ||
var queryProps = Object.assign({}, stateProps, dispatchProps); | ||
var tempProps = Object.assign({}, _defineProperty({}, config.name, queryProps), ownProps); | ||
return config.props(tempProps); | ||
var tempProps = Object.assign({}, _defineProperty({}, config.name || 'query', queryProps), ownProps); | ||
return config.props ? config.props(tempProps) : tempProps; | ||
}; | ||
@@ -36,0 +46,0 @@ |
@@ -22,20 +22,38 @@ 'use strict'; | ||
switch (action.type) { | ||
case 'TRANSPORTER_ALIASES_CREATE': | ||
case 'TRANSPORTER_ALIAS_CREATE': | ||
{ | ||
return _extends({}, state, _defineProperty({}, action.name, action.ids)); | ||
return _extends({}, state, _defineProperty({}, action.name, action.idOrIds)); | ||
} | ||
case 'TRANSPORTER_ALIASES_PUSH': | ||
case 'TRANSPORTER_ALIAS_UPDATE': | ||
{ | ||
return _extends({}, state, _defineProperty({}, action.name, (0, _utils.push)(state[action.name], action.ids))); | ||
if ((0, _utils.hasMany)(state[action.name])) { | ||
throw new Error('Alias \'' + action.name.name + '\' is a many alias, use push() or slice().'); | ||
} | ||
return _extends({}, state, _defineProperty({}, action.name, action.id)); | ||
} | ||
case 'TRANSPORTER_ALIASES_SLICE': | ||
case 'TRANSPORTER_ALIAS_PUSH': | ||
{ | ||
return _extends({}, state, _defineProperty({}, action.name, (0, _utils.slice)(state[action.name], action.ids))); | ||
if (!(0, _utils.hasMany)(state[action.name])) { | ||
throw new Error('Alias \'' + action.name + '\' is NOT a many alias, use update().'); | ||
} | ||
return _extends({}, state, _defineProperty({}, action.name, (0, _utils.connectionPush)(state[action.name], action.ids))); | ||
} | ||
case 'TRANSPORTER_ALIASES_DELETE': | ||
case 'TRANSPORTER_ALIAS_SLICE': | ||
{ | ||
var aliases = state; | ||
delete aliases[action.name]; | ||
return aliases; | ||
if (!(0, _utils.hasMany)(state[action.name])) { | ||
throw new Error('Alias \'' + action.name + '\' is NOT a many alias, use update().'); | ||
} | ||
return _extends({}, state, _defineProperty({}, action.name, (0, _utils.connectionSlice)(state[action.name], action.ids))); | ||
} | ||
case 'TRANSPORTER_ALIAS_DELETE': | ||
{ | ||
var newState = _extends({}, state); | ||
delete newState[action.name]; | ||
return newState; | ||
} | ||
default: | ||
@@ -42,0 +60,0 @@ { |
@@ -18,3 +18,4 @@ 'use strict'; | ||
function mergeEntities(entity1, entity2) { | ||
var mergedEntity = entity1; | ||
var mergedEntity = _extends({}, entity1); | ||
Object.keys(entity2).forEach(function (key) { | ||
@@ -24,9 +25,11 @@ if (entity1[key] && entity1[key].connection) { | ||
mergedEntity[key] = _extends({}, entity1[key], entity2[key], { | ||
connection: (0, _utils.push)(entity1[key].connection, entity2[key].connection) | ||
connection: (0, _utils.connectionPush)(entity1[key].connection, entity2[key].connection) | ||
}); | ||
} else { | ||
// add new attribute | ||
// add attribute | ||
mergedEntity[key] = entity2[key]; | ||
} | ||
}); | ||
return mergedEntity; | ||
} | ||
@@ -41,45 +44,79 @@ | ||
{ | ||
var entities = state; | ||
// merge entities | ||
var newState = _extends({}, state); | ||
Object.keys(action.entities).forEach(function (type) { | ||
if (!newState[type]) { | ||
newState[type] = {}; | ||
} | ||
Object.keys(action.entities[type]).forEach(function (key) { | ||
if (!entities[type][key]) { | ||
if (!newState[type][key]) { | ||
// insert new entity | ||
entities[type][key] = action.entities[type][key]; | ||
newState[type][key] = action.entities[type][key]; | ||
} else { | ||
// update entity | ||
entities[type][key] = mergeEntities(entities[type][key], action.entities[type][key]); | ||
newState[type][key] = mergeEntities(state[type][key], action.entities[type][key]); | ||
} | ||
}); | ||
}); | ||
return entities; | ||
return newState; | ||
} | ||
case 'TRANSPORTER_ENTITIES_DELETE': | ||
{ | ||
var _entities = state; | ||
var _newState = _extends({}, state); | ||
action.ids.forEach(function (id) { | ||
delete _entities[id[0]][id[1]]; | ||
delete _newState[id[0]][id[1]]; | ||
}); | ||
return _entities; | ||
return _newState; | ||
} | ||
case 'TRANSPORTER_ENTITIES_CONNECTION_PUSH': | ||
case 'TRANSPORTER_ENTITIES_CONNECTION_UPDATE': | ||
{ | ||
var connection = action.connection; | ||
var entity = state[connection.id[0]][connection.id[1]]; | ||
entity[connection.name].connection = (0, _utils.push)(entity[connection.name].connection, action.ids); | ||
return _extends({}, state, _defineProperty({}, connection.id[0], _extends({}, state[connection.id[0]], _defineProperty({}, connection.id[1], entity)))); | ||
var entityState = state[connection.id[0]][connection.id[1]]; | ||
if ((0, _utils.hasMany)(entityState[connection.name].connection)) { | ||
throw new Error('Connection \'' + connection.name + '\' of entity [' + connection.id[0] + ', ' + connection.id[1] + '] is a many connection, use push() or slice().'); | ||
} | ||
return _extends({}, state, _defineProperty({}, connection.id[0], _extends({}, state[connection.id[0]], _defineProperty({}, connection.id[1], _extends({}, entityState, _defineProperty({}, connection.name, _extends({}, entityState[connection.name], { | ||
connection: action.id | ||
}))))))); | ||
} | ||
case 'TRANSPORTER_ENTITIES_CONNECTION_SLICE': | ||
case 'TRANSPORTER_ENTITIES_CONNECTION_PUSH': | ||
{ | ||
var _connection = action.connection; | ||
var _entity = state[_connection.id[0]][_connection.id[1]]; | ||
_entity[_connection.name].connection = (0, _utils.slice)(_entity[_connection.name].connection, action.ids); | ||
return _extends({}, state, _defineProperty({}, _connection.id[0], _extends({}, state[_connection.id[0]], _defineProperty({}, _connection.id[1], _entity)))); | ||
var _entityState = state[_connection.id[0]][_connection.id[1]]; | ||
if (!(0, _utils.hasMany)(_entityState[_connection.name].connection)) { | ||
throw new Error('Connection \'' + _connection.name + '\' of entity [' + _connection.id[0] + ', ' + _connection.id[1] + '] is NOT a many connection, use update().'); | ||
} | ||
return _extends({}, state, _defineProperty({}, _connection.id[0], _extends({}, state[_connection.id[0]], _defineProperty({}, _connection.id[1], _extends({}, _entityState, _defineProperty({}, _connection.name, _extends({}, _entityState[_connection.name], { | ||
connection: (0, _utils.connectionPush)(_entityState[_connection.name].connection, action.ids) | ||
}))))))); | ||
} | ||
case 'TRANSPORTER_ENTITIES_CONNECTION_DELETE': | ||
case 'TRANSPORTER_ENTITIES_CONNECTION_SLICE': | ||
{ | ||
var _connection2 = action.connection; | ||
var _entity2 = state[_connection2.id[0]][_connection2.id[1]]; | ||
delete _entity2[_connection2.name]; | ||
return _extends({}, state, _defineProperty({}, _connection2.id[0], _extends({}, state[_connection2.id[0]], _defineProperty({}, _connection2.id[1], _entity2)))); | ||
var _entityState2 = state[_connection2.id[0]][_connection2.id[1]]; | ||
if (!(0, _utils.hasMany)(_entityState2[_connection2.name].connection)) { | ||
throw new Error('Connection \'' + _connection2.name + '\' of entity [' + _connection2.id[0] + ', ' + _connection2.id[1] + '] is NOT a many connection, use update().'); | ||
} | ||
return _extends({}, state, _defineProperty({}, _connection2.id[0], _extends({}, state[_connection2.id[0]], _defineProperty({}, _connection2.id[1], _extends({}, _entityState2, _defineProperty({}, _connection2.name, _extends({}, _entityState2[_connection2.name], { | ||
connection: (0, _utils.connectionSlice)(_entityState2[_connection2.name].connection, action.ids) | ||
}))))))); | ||
} | ||
case 'TRANSPORTER_ENTITIES_CONNECTION_DELETE': | ||
{ | ||
var _connection3 = action.connection; | ||
var newEntityState = _extends({}, state[_connection3.id[0]][_connection3.id[1]]); | ||
delete newEntityState[_connection3.name]; | ||
return _extends({}, state, _defineProperty({}, _connection3.id[0], _extends({}, state[_connection3.id[0]], _defineProperty({}, _connection3.id[1], newEntityState)))); | ||
} | ||
default: | ||
@@ -86,0 +123,0 @@ { |
@@ -20,3 +20,3 @@ 'use strict'; | ||
switch (action.type) { | ||
case 'TRANSPORTER_REQUESTS_START': | ||
case 'TRANSPORTER_REQUEST_START': | ||
{ | ||
@@ -28,3 +28,3 @@ return _extends({}, state, _defineProperty({}, action.name, { | ||
} | ||
case 'TRANSPORTER_REQUESTS_COMPLETED': | ||
case 'TRANSPORTER_REQUEST_COMPLETED': | ||
{ | ||
@@ -36,3 +36,3 @@ return _extends({}, state, _defineProperty({}, action.name, { | ||
} | ||
case 'TRANSPORTER_REQUESTS_ERROR': | ||
case 'TRANSPORTER_REQUEST_ERROR': | ||
{ | ||
@@ -39,0 +39,0 @@ return _extends({}, state, _defineProperty({}, action.name, { |
@@ -8,6 +8,2 @@ 'use strict'; | ||
var _Transporter = require('../core/Transporter'); | ||
var _Transporter2 = _interopRequireDefault(_Transporter); | ||
var _factory = require('./entities/factory'); | ||
@@ -21,2 +17,4 @@ | ||
var _utils = require('../utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -26,2 +24,3 @@ | ||
var entities = {}; | ||
rawEntities.forEach(function (rawEntity) { | ||
@@ -41,38 +40,54 @@ var id = rawEntity.getId(); | ||
function createRequest(request) { | ||
function createRequest(request, fetch) { | ||
var requestName = request.name || (0, _utils.getRequestName)(request.schema); | ||
return function (dispatch) { | ||
// init request status | ||
dispatch({ | ||
type: 'TRANSPORTER_REQUESTS_START', | ||
name: request.name | ||
type: 'TRANSPORTER_REQUEST_START', | ||
name: requestName | ||
}); | ||
// apply optimistic response on mutations | ||
if (request.mutation && request.optimisticResponse) { | ||
var optimisticResponse = request.optimisticResponse(_factory2.default); | ||
// immediately stop request on server for now | ||
// TODO | ||
// collect all requests on server, then send ONE request to server | ||
if (typeof window === 'undefined') { | ||
dispatch({ | ||
type: 'TRANSPORTER_REQUEST_COMPLETED', | ||
name: requestName | ||
}); | ||
} | ||
optimisticResponse.entities = formatEntities(optimisticResponse.entities); | ||
if (typeof window !== 'undefined') { | ||
// apply optimistic response on mutations | ||
if (request.type === 'TRANSPORTER_MUTATION' && request.optimisticResponse) { | ||
var optimisticResponse = request.optimisticResponse(_factory2.default); | ||
(0, _integrateResponse2.default)(dispatch, request.integration, optimisticResponse); | ||
} | ||
if (optimisticResponse && optimisticResponse.entities) { | ||
optimisticResponse.entities = formatEntities(optimisticResponse.entities); | ||
} | ||
// dispatch query | ||
_Transporter2.default.fetch(request.query || request.mutation, request.variables).then(function () { | ||
// update request status on success | ||
dispatch({ | ||
type: 'TRANSPORTER_REQUESTS_COMPLETED', | ||
name: request.name | ||
}); | ||
(0, _integrateResponse2.default)(dispatch, request.integration, optimisticResponse); | ||
} | ||
// TODO | ||
// integrateResponse(dispatch, request.integration, response); | ||
}, function (error) { | ||
// update request status on error | ||
dispatch({ | ||
type: 'TRANSPORTER_REQUESTS_ERROR', | ||
name: request.name, | ||
error: error | ||
// dispatch query | ||
fetch(request.schema, request.variables).then(function () { | ||
// update request status on success | ||
dispatch({ | ||
type: 'TRANSPORTER_REQUEST_COMPLETED', | ||
name: requestName | ||
}); | ||
// TODO | ||
// integrateResponse(dispatch, request.integration, response); | ||
}, function (error) { | ||
// update request status on error | ||
dispatch({ | ||
type: 'TRANSPORTER_REQUEST_ERROR', | ||
name: requestName, | ||
error: error | ||
}); | ||
}); | ||
}); | ||
} | ||
}; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -11,8 +11,2 @@ Object.defineProperty(exports, "__esModule", { | ||
var _utils = require('../../utils'); | ||
var _utils2 = _interopRequireDefault(_utils); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -29,12 +23,12 @@ | ||
_createClass(Entity, [{ | ||
key: 'addConnection', | ||
value: function addConnection(name, connectionIds) { | ||
var connectionAttributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
key: "addConnection", | ||
value: function addConnection(name, idOrIds) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
this.attributes[name] = _extends({}, connectionAttributes, { | ||
connection: (0, _utils2.default)(connectionIds) | ||
this.attributes[name] = _extends({}, attributes, { | ||
connection: idOrIds | ||
}); | ||
} | ||
}, { | ||
key: 'addAttribute', | ||
key: "addAttribute", | ||
value: function addAttribute(name, value) { | ||
@@ -44,3 +38,3 @@ this.attributes[name] = value; | ||
}, { | ||
key: 'getId', | ||
key: "getId", | ||
value: function getId() { | ||
@@ -47,0 +41,0 @@ return this.id; |
@@ -11,2 +11,4 @@ 'use strict'; | ||
var _utils = require('../utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -16,3 +18,3 @@ | ||
// insert/update entities | ||
if (response.entities) { | ||
if (response && response.entities) { | ||
dispatch({ | ||
@@ -25,6 +27,6 @@ type: 'TRANSPORTER_ENTITIES_UPDATE', | ||
// delete trashed entities | ||
if (response.trash) { | ||
if (response && response.trash) { | ||
dispatch({ | ||
type: 'TRANSPORTER_ENTITIES_DELETE', | ||
ids: response.trash | ||
ids: (0, _utils.enforceArray)(response.trash) | ||
}); | ||
@@ -37,4 +39,4 @@ } | ||
integration(updater, { | ||
root: response.root, | ||
trash: response.trash | ||
root: response && response.root, | ||
trash: response && response.trash | ||
}); | ||
@@ -41,0 +43,0 @@ } |
@@ -1,2 +0,23 @@ | ||
// TODO | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createRequest = require('./createRequest'); | ||
var _createRequest2 = _interopRequireDefault(_createRequest); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = function () { | ||
return function (next) { | ||
return function (action) { | ||
if (action.type === 'TRANSPORTER_REQUEST') { | ||
return next((0, _createRequest2.default)(action)); | ||
} | ||
return next(action); | ||
}; | ||
}; | ||
}; |
@@ -14,16 +14,27 @@ 'use strict'; | ||
var AliasUpdater = function () { | ||
function AliasUpdater(dispatch, alias) { | ||
function AliasUpdater(dispatch, name) { | ||
_classCallCheck(this, AliasUpdater); | ||
this.dispatch = dispatch; | ||
this.alias = alias; | ||
this.name = name; | ||
} | ||
_createClass(AliasUpdater, [{ | ||
key: 'update', | ||
value: function update(id) { | ||
this.dispatch({ | ||
type: 'TRANSPORTER_ALIAS_UPDATE', | ||
name: this.name, | ||
id: id | ||
}); | ||
} | ||
}, { | ||
key: 'add', | ||
value: function add(ids) { | ||
value: function add(idOrIds) { | ||
var ids = (0, _utils.enforceArray)(idOrIds); | ||
this.dispatch({ | ||
type: 'TRANSPORTER_ALIASES_PUSH', | ||
alias: this.alias, | ||
ids: (0, _utils.enforceArray)(ids) | ||
type: 'TRANSPORTER_ALIAS_PUSH', | ||
name: this.name, | ||
ids: ids | ||
}); | ||
@@ -33,7 +44,9 @@ } | ||
key: 'remove', | ||
value: function remove(ids) { | ||
value: function remove(idOrIds) { | ||
var ids = (0, _utils.enforceArray)(idOrIds); | ||
this.dispatch({ | ||
type: 'TRANSPORTER_ALIASES_SLICE', | ||
alias: this.alias, | ||
ids: (0, _utils.enforceArray)(ids) | ||
type: 'TRANSPORTER_ALIAS_SLICE', | ||
name: this.name, | ||
ids: ids | ||
}); | ||
@@ -40,0 +53,0 @@ } |
@@ -23,4 +23,18 @@ 'use strict'; | ||
_createClass(ConnectionUpdater, [{ | ||
key: 'update', | ||
value: function update(id) { | ||
this.dispatch({ | ||
type: 'TRANSPORTER_ENTITIES_CONNECTION_UPDATE', | ||
connection: { | ||
id: this.id, | ||
name: this.name | ||
}, | ||
id: id | ||
}); | ||
} | ||
}, { | ||
key: 'add', | ||
value: function add(ids) { | ||
value: function add(idOrIds) { | ||
var ids = (0, _utils.enforceArray)(idOrIds); | ||
this.dispatch({ | ||
@@ -32,3 +46,3 @@ type: 'TRANSPORTER_ENTITIES_CONNECTION_PUSH', | ||
}, | ||
ids: (0, _utils.enforceArray)(ids) | ||
ids: ids | ||
}); | ||
@@ -38,3 +52,5 @@ } | ||
key: 'remove', | ||
value: function remove(ids) { | ||
value: function remove(idOrIds) { | ||
var ids = (0, _utils.enforceArray)(idOrIds); | ||
this.dispatch({ | ||
@@ -46,3 +62,3 @@ type: 'TRANSPORTER_ENTITIES_CONNECTION_SLICE', | ||
}, | ||
ids: (0, _utils.enforceArray)(ids) | ||
ids: ids | ||
}); | ||
@@ -49,0 +65,0 @@ } |
@@ -17,4 +17,2 @@ 'use strict'; | ||
var _utils = require('../../utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -33,7 +31,7 @@ | ||
key: 'createAlias', | ||
value: function createAlias(alias, ids) { | ||
value: function createAlias(name, idOrIds) { | ||
this.dispatch({ | ||
type: 'TRANSPORTER_ALIASES_CREATE', | ||
alias: alias, | ||
ids: (0, _utils.enforceArray)(ids) | ||
type: 'TRANSPORTER_ALIAS_CREATE', | ||
name: name, | ||
idOrIds: idOrIds | ||
}); | ||
@@ -43,11 +41,11 @@ } | ||
key: 'getAlias', | ||
value: function getAlias(alias) { | ||
return new _AliasUpdater2.default(this.dispatch, alias); | ||
value: function getAlias(name) { | ||
return new _AliasUpdater2.default(this.dispatch, name); | ||
} | ||
}, { | ||
key: 'deleteAlias', | ||
value: function deleteAlias(alias) { | ||
value: function deleteAlias(name) { | ||
this.dispatch({ | ||
type: 'TRANSPORTER_ALIASES_DELETE', | ||
alias: alias | ||
type: 'TRANSPORTER_ALIAS_DELETE', | ||
name: name | ||
}); | ||
@@ -54,0 +52,0 @@ } |
@@ -9,6 +9,12 @@ 'use strict'; | ||
var _formatEntity = require('./formatEntity'); | ||
var _utils = require('../utils'); | ||
var _formatEntity2 = _interopRequireDefault(_formatEntity); | ||
var _formatData = require('./formatData'); | ||
var _formatData2 = _interopRequireDefault(_formatData); | ||
var _getConnectionData = require('./getConnectionData'); | ||
var _getConnectionData2 = _interopRequireDefault(_getConnectionData); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -22,4 +28,9 @@ | ||
this.hasMany = (0, _utils.hasMany)(data); | ||
this.data = this.hasMany ? data.map(function (id) { | ||
return (0, _formatData2.default)(id, state.entities[id[0]][id[1]]); | ||
}) : (0, _formatData2.default)(data, state.entities[data[0]][data[1]]); | ||
this.state = state; | ||
this.data = data; | ||
} | ||
@@ -53,15 +64,14 @@ | ||
this.data.forEach(function (attributes, key) { | ||
if (this.hasMany) { | ||
this.data.forEach(function (attributes, key) { | ||
// eslint-disable-next-line no-underscore-dangle | ||
var id = [_this.data[key].__type, _this.data[key].id]; | ||
_this.data[key][name] = (0, _getConnectionData2.default)(_this.state, id, name, constraints); | ||
}); | ||
} else { | ||
// eslint-disable-next-line no-underscore-dangle | ||
var type = _this.data[key].__type; | ||
var id = _this.data[key].id; | ||
var childrenIds = _this.state.entities[type][id][name].connection; | ||
var id = [this.data.__type, this.data.id]; | ||
this.data[name] = (0, _getConnectionData2.default)(this.state, id, name, constraints); | ||
} | ||
var entities = childrenIds.map(function (childrenId) { | ||
return (0, _formatEntity2.default)(_this.state.entities[childrenId[0]][childrenId[1]]); | ||
}); | ||
_this.data[key][name] = constraints(new Selector(entities)); | ||
}); | ||
return this; | ||
@@ -68,0 +78,0 @@ } |
@@ -13,6 +13,2 @@ 'use strict'; | ||
var _formatEntity = require('./formatEntity'); | ||
var _formatEntity2 = _interopRequireDefault(_formatEntity); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -31,6 +27,4 @@ | ||
key: 'select', | ||
value: function select(id) { | ||
var entities = [(0, _formatEntity2.default)(this.state.entities[id[0]][id[1]])]; | ||
return new _Selector2.default(entities); | ||
value: function select(ids) { | ||
return new _Selector2.default(this.state, ids); | ||
} | ||
@@ -40,11 +34,9 @@ }, { | ||
value: function selectByAlias(name) { | ||
var _this = this; | ||
if (!this.state.aliases[name]) { | ||
throw new Error('Cannot find alias \'' + name + '\'.'); | ||
} | ||
var aliasIds = this.state.aliases[name]; | ||
var entities = aliasIds.map(function (id) { | ||
return (0, _formatEntity2.default)(_this.state.entities[id[0]][id[1]]); | ||
}); | ||
return new _Selector2.default(entities); | ||
return new _Selector2.default(this.state, aliasIds); | ||
} | ||
@@ -54,11 +46,9 @@ }, { | ||
value: function selectChildren(id, name) { | ||
var _this2 = this; | ||
if (!this.state.entities[id[0]] || !this.state.entities[id[0]][id[1]]) { | ||
throw new Error('Cannot find connection \'' + name + '\' of entity [' + id[0] + ', ' + id[1] + '].'); | ||
} | ||
var childrenIds = this.state.entities[id[0]][id[1]][name].connection; | ||
var childrenIds = !this.state.entities[id[0]][id[1]][name] || !this.state.entities[id[0]][id[1]][name].connection ? [] : this.state.entities[id[0]][id[1]][name].connection; | ||
var entities = childrenIds.map(function (childrenId) { | ||
return (0, _formatEntity2.default)(_this2.state.entities[childrenId[0]][childrenId[1]]); | ||
}); | ||
return new _Selector2.default(entities); | ||
return new _Selector2.default(this.state, childrenIds); | ||
} | ||
@@ -65,0 +55,0 @@ }]); |
@@ -7,4 +7,4 @@ 'use strict'; | ||
exports.default = enforceArray; | ||
function enforceArray(ids) { | ||
return typeof ids === 'string' || ids instanceof String ? [ids] : ids; | ||
function enforceArray(data) { | ||
return typeof data[0] === 'string' || data[0] instanceof String ? [data] : data; | ||
} |
@@ -6,4 +6,8 @@ 'use strict'; | ||
}); | ||
exports.enforceArray = exports.slice = exports.push = exports.isInArray = exports.isEqual = undefined; | ||
exports.hasMany = exports.enforceArray = exports.connectionSlice = exports.connectionPush = exports.isInArray = exports.isEqual = exports.getRequestName = undefined; | ||
var _getRequestName = require('./getRequestName'); | ||
var _getRequestName2 = _interopRequireDefault(_getRequestName); | ||
var _isEqual = require('./isEqual'); | ||
@@ -17,9 +21,9 @@ | ||
var _push = require('./push'); | ||
var _connectionPush = require('./connectionPush'); | ||
var _push2 = _interopRequireDefault(_push); | ||
var _connectionPush2 = _interopRequireDefault(_connectionPush); | ||
var _slice = require('./slice'); | ||
var _connectionSlice = require('./connectionSlice'); | ||
var _slice2 = _interopRequireDefault(_slice); | ||
var _connectionSlice2 = _interopRequireDefault(_connectionSlice); | ||
@@ -30,8 +34,14 @@ var _enforceArray = require('./enforceArray'); | ||
var _hasMany = require('./hasMany'); | ||
var _hasMany2 = _interopRequireDefault(_hasMany); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.getRequestName = _getRequestName2.default; | ||
exports.isEqual = _isEqual2.default; | ||
exports.isInArray = _isInArray2.default; | ||
exports.push = _push2.default; | ||
exports.slice = _slice2.default; | ||
exports.enforceArray = _enforceArray2.default; | ||
exports.connectionPush = _connectionPush2.default; | ||
exports.connectionSlice = _connectionSlice2.default; | ||
exports.enforceArray = _enforceArray2.default; | ||
exports.hasMany = _hasMany2.default; |
@@ -6,4 +6,7 @@ 'use strict'; | ||
}); | ||
exports.default = push; | ||
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 = connectionPush; | ||
var _isInArray = require('./isInArray'); | ||
@@ -15,4 +18,4 @@ | ||
function push(ids, newIds) { | ||
var returnIds = ids; | ||
function connectionPush(ids, newIds) { | ||
var returnIds = _extends({}, ids); | ||
@@ -19,0 +22,0 @@ newIds.forEach(function (newId) { |
@@ -6,4 +6,7 @@ 'use strict'; | ||
}); | ||
exports.default = slice; | ||
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 = connectionSlice; | ||
var _isInArray = require('./isInArray'); | ||
@@ -15,4 +18,4 @@ | ||
function slice(ids, newIds) { | ||
var returnIds = ids; | ||
function connectionSlice(ids, newIds) { | ||
var returnIds = _extends({}, ids); | ||
@@ -19,0 +22,0 @@ newIds.forEach(function (newId) { |
{ | ||
"name": "react-transporter", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"main": "./lib/index.js", | ||
@@ -29,3 +29,4 @@ "description": "React.js Redux GraphQL client", | ||
"react-redux": "5.0.6", | ||
"redux": "3.7.2" | ||
"redux": "3.7.2", | ||
"redux-thunk": "2.2.0" | ||
}, | ||
@@ -36,3 +37,4 @@ "peerDependencies": { | ||
"react-redux": "^5.0.0", | ||
"redux": "^3.0.0" | ||
"redux": "^3.0.0", | ||
"redux-thunk": "^2.0.0" | ||
}, | ||
@@ -39,0 +41,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
241371
44
1050
7
8