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

redux-state-branch

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-state-branch - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

26

dist/index.d.ts

@@ -51,8 +51,13 @@ import { Reducer, Middleware, StoreEnhancer } from 'redux';

/** Get an item by id */
byId: <T extends string | string[] | null>(state: any, { id }: {
byId: (state: any, { id }: {
/** The ID of your item */
id?: T | undefined;
}) => T extends string[] ? {
id?: string | null | undefined;
}) => ItemT | undefined;
/** Get multiple items by their id */
byIds: (state: any, { ids }: {
/** The ID of your item */
ids: (string | null | undefined)[];
}) => {
[itemId: string]: ItemT | undefined;
} : ItemT | undefined;
};
/** Gets an object map of unique ids to items {itemId: ItemT} */

@@ -207,8 +212,13 @@ mapById: (state: any) => {

/** Get an item by id */
byId: <T extends string | string[] | null>(state: any, { id }: {
byId: (state: any, { id }: {
/** The ID of your item */
id?: T | undefined;
}) => T extends string[] ? {
id?: string | null | undefined;
}) => ItemT | undefined;
/** Get multiple items by their id */
byIds: (state: any, { ids }: {
/** The ID of your item */
ids: (string | null | undefined)[];
}) => {
[itemId: string]: ItemT | undefined;
} : ItemT | undefined;
};
/** Gets an object map of unique ids to items {itemId: ItemT} */

@@ -215,0 +225,0 @@ mapById: (state: any) => {

@@ -80,12 +80,16 @@ "use strict";

var id = _a.id;
if (Array.isArray(id)) {
var objects = id.reduce(function (acc, aId) {
acc[aId] = state[name].items[aId || ''];
return acc;
}, {});
// @ts-ignore This is a valid return, but Typescript can't return Array.isArray ahead of time
return objects;
}
return state[name].items[id || ''];
},
/** Get multiple items by their id */
byIds: function (
/** Your store's state object. */
state, _a) {
var ids = _a.ids;
return ids.reduce(function (acc, id) {
if (id) {
acc[id] = state[name].items[id || ''];
}
return acc;
}, {});
},
/** Gets an object map of unique ids to items {itemId: ItemT} */

@@ -92,0 +96,0 @@ mapById: function (

@@ -212,7 +212,8 @@ "use strict";

it('byId', function () {
expect(branch.select.byId(state, { id: 'testUser' })).toBe(DEFAULT_STATE.items.testUser);
var res = branch.select.byId(state, { id: 'testUser' });
expect(res).toBe(DEFAULT_STATE.items.testUser);
});
it('byId multiple', function () {
it('byIds multiple', function () {
var _a;
var res = branch.select.byId(state, { id: ['testUser', 'testUser2'] });
var res = branch.select.byIds(state, { ids: ['testUser', 'testUser2'] });
expect(res).toEqual((_a = {},

@@ -219,0 +220,0 @@ _a[DEFAULT_STATE.items.testUser.id] = DEFAULT_STATE.items.testUser,

{
"name": "redux-state-branch",
"version": "1.2.0",
"version": "1.2.1",
"private": false,

@@ -5,0 +5,0 @@ "description": "A library for simplified Redux development.",

Sorry, the diff of this file is not supported yet

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