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

@lusk/redux-entities-reducer

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lusk/redux-entities-reducer - npm Package Compare versions

Comparing version 0.1.5 to 0.2.0

lib/actions.js

72

lib/index.js

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,10 +6,14 @@ Object.defineProperty(exports, "__esModule", {

});
exports.removeEntity = exports.insertEntity = exports.replaceEntity = exports.replaceEntities = exports.clearState = undefined;
exports.selectors = exports.actions = undefined;
var _ramda = require('ramda');
var _actions = require("./actions");
var _ramda2 = _interopRequireDefault(_ramda);
var actions = _interopRequireWildcard(_actions);
var _transforms = require('./transforms');
var _selectors = require("./selectors");
var selectors = _interopRequireWildcard(_selectors);
var _transforms = require("./transforms");
var transforms = _interopRequireWildcard(_transforms);

@@ -19,50 +23,8 @@

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.actions = actions;
exports.selectors = selectors;
// Actions
// =======
var clearState = exports.clearState = function clearState() {
return {
type: 'entities/clearEntities'
};
};
var initialState = { lookupTable: {}, collections: {} };
var replaceEntities = exports.replaceEntities = _ramda2.default.curry(function (collection, ownerId, entities) {
return {
type: 'entities/replaceEntities',
payload: {
entities: entities,
collection: collection,
ownerId: ownerId
}
};
});
var replaceEntity = exports.replaceEntity = function replaceEntity(entity) {
return {
type: 'entities/replaceEntity',
payload: { entity: entity }
};
};
var insertEntity = exports.insertEntity = _ramda2.default.curry(function (collection, ownerId, entity) {
return {
type: 'entities/insertEntity',
payload: { collection: collection, ownerId: ownerId, entity: entity }
};
});
var removeEntity = exports.removeEntity = _ramda2.default.curry(function (collection, ownerId, entityId) {
return {
type: 'entities/removeEntity',
payload: { collection: collection, ownerId: ownerId, entityId: entityId }
};
});
// Reducer
// =======
var initialState = { lookupTable: {} };
var reduceEntities = function reduceEntities() {

@@ -76,15 +38,15 @@ var state = arguments.length <= 0 || arguments[0] === undefined ? initialState : arguments[0];

switch (type) {
case 'entities/clearEntities':
case "entities/clearEntities":
return initialState;
case 'entities/replaceEntity':
case "entities/replaceEntity":
return transforms.replaceEntity(payload.entity, state);
case 'entities/replaceEntities':
case "entities/replaceEntities":
return transforms.replaceEntities(payload.collection, payload.ownerId, payload.entities, state);
case 'entities/insertEntity':
case "entities/insertEntity":
return transforms.insertEntity(payload.collection, payload.ownerId, payload.entity, state);
case 'entities/removeEntity':
case "entities/removeEntity":
return transforms.removeEntity(payload.collection, payload.ownerId, payload.entityId, state);

@@ -91,0 +53,0 @@

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.getEntities = exports.getEntity = exports.getCollectionIdsByOwner = exports.getCollectionIds = exports.getLookupTable = undefined;
exports.getEntities = exports.getEntity = exports.getCollectionIds = exports.getLookupTable = undefined;
var _ramda = require('ramda');
var _ramda = require("ramda");

@@ -15,8 +15,6 @@ var _ramda2 = _interopRequireDefault(_ramda);

var getLookupTable = exports.getLookupTable = _ramda2.default.propOr({}, 'lookupTable');
var getLookupTable = exports.getLookupTable = _ramda2.default.propOr({}, "lookupTable");
var getCollectionIds = exports.getCollectionIds = _ramda2.default.propOr([]);
var getCollectionIdsByOwner = exports.getCollectionIdsByOwner = _ramda2.default.curry(function (collection, ownerId, state) {
return ownerId ? _ramda2.default.pathOr([], ['collections', ownerId, collection], state) : _ramda2.default.pathOr([], ['collections', collection], state);
var getCollectionIds = exports.getCollectionIds = _ramda2.default.curry(function (collection, owner, state) {
return _ramda2.default.pathOr([], ["collections", owner, collection], state);
});

@@ -29,3 +27,3 @@

var getEntities = exports.getEntities = _ramda2.default.curry(function (collection, ownerId, state) {
return _ramda2.default.map(getEntity(_ramda2.default.__, state), getCollectionIdsByOwner(collection, ownerId, state));
return _ramda2.default.map(getEntity(_ramda2.default.__, state), getCollectionIds(collection, ownerId, state));
});

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", {

});
exports.removeEntity = exports.insertEntity = exports.replaceEntities = exports.replaceEntity = exports.mergeInto = exports.pluckIds = undefined;
exports.removeEntity = exports.insertEntity = exports.replaceEntities = exports.replaceEntity = exports.mergeInto = exports.indexById = exports.ids = exports.id = undefined;
var _ramda = require('ramda');
var _ramda = require("ramda");

@@ -17,8 +17,12 @@ var _ramda2 = _interopRequireDefault(_ramda);

var pluckIds = exports.pluckIds = _ramda2.default.pluck('id');
var id = exports.id = _ramda2.default.prop("id");
var ids = exports.ids = _ramda2.default.pluck("id");
var indexById = exports.indexById = _ramda2.default.indexBy(_ramda2.default.prop("id"));
var mergeInto = exports.mergeInto = _ramda2.default.flip(_ramda2.default.merge);
var replaceEntity = exports.replaceEntity = function replaceEntity(entity, state) {
var transform = _ramda2.default.over(_ramda2.default.lensProp('lookupTable'), mergeInto(_defineProperty({}, entity.id, entity)));
var transform = _ramda2.default.over(_ramda2.default.lensProp("lookupTable"), mergeInto(_defineProperty({}, id(entity), entity)));

@@ -29,6 +33,4 @@ return transform(state);

var replaceEntities = exports.replaceEntities = function replaceEntities(collection, ownerId, entities, state) {
var ids = pluckIds(entities);
var transform = _ramda2.default.compose(_ramda2.default.set(_ramda2.default.lensPath(["collections", ownerId, collection]), ids(entities)), _ramda2.default.over(_ramda2.default.lensProp("lookupTable"), mergeInto(indexById(entities))));
var transform = _ramda2.default.compose(_ramda2.default.set(ownerId ? _ramda2.default.lensPath(['collections', ownerId, collection]) : _ramda2.default.lensPath(['collections', collection]), ids), _ramda2.default.over(_ramda2.default.lensProp('lookupTable'), mergeInto(_ramda2.default.zipObj(ids, entities))));
return transform(state);

@@ -38,3 +40,3 @@ };

var insertEntity = exports.insertEntity = function insertEntity(collection, ownerId, entity, state) {
var transform = _ramda2.default.compose(_ramda2.default.set(_ramda2.default.lensPath(['lookupTable', entity.id]), entity), _ramda2.default.over(ownerId ? _ramda2.default.lensPath(['collections', ownerId, collection]) : _ramda2.default.lensPath(['collections', collection]), _ramda2.default.compose(_ramda2.default.uniq, _ramda2.default.append(entity.id))));
var transform = _ramda2.default.compose(_ramda2.default.set(_ramda2.default.lensPath(["lookupTable", id(entity)]), entity), _ramda2.default.over(_ramda2.default.lensPath(["collections", ownerId, collection]), _ramda2.default.compose(_ramda2.default.uniq, _ramda2.default.append(id(entity)))));

@@ -45,5 +47,5 @@ return transform(state);

var removeEntity = exports.removeEntity = function removeEntity(collection, ownerId, entityId, state) {
var transform = _ramda2.default.compose(_ramda2.default.over(_ramda2.default.lensProp('lookupTable'), _ramda2.default.omit(entityId)), _ramda2.default.over(ownerId ? _ramda2.default.lensPath(['collections', ownerId, collection]) : _ramda2.default.lensPath(['collections', collection]), _ramda2.default.reject(_ramda2.default.equals(entityId))));
var transform = _ramda2.default.compose(_ramda2.default.over(_ramda2.default.lensProp("lookupTable"), _ramda2.default.omit(entityId)), _ramda2.default.over(_ramda2.default.lensPath(["collections", ownerId, collection]), _ramda2.default.reject(_ramda2.default.equals(entityId))));
return transform(state);
};
{
"name": "@lusk/redux-entities-reducer",
"description": "A Redux reducer for handling entities",
"version": "0.1.5",
"version": "0.2.0",
"repository": {

@@ -35,2 +35,3 @@ "type": "git",

"build": "babel source -d lib --ignore *.test.js",
"build:watch": "nodemon -w source -x \"npm run build\"",
"test": "ava -r babel-register source/**/*.test.js",

@@ -37,0 +38,0 @@ "test:watch": "ava -w -r babel-register source/**/*.test.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