Socket
Book a DemoInstallSign in
Socket

bouchon-toolbox

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bouchon-toolbox

A set of tools for Bouchon

0.2.0
latest
Source
npmnpm
Version published
Weekly downloads
15
650%
Maintainers
1
Weekly downloads
 
Created
Source

bouchon-toolbox

A set of tools for bouchon.

## What is a selector?

A selector is a function that returns a subset of an existing collection.

They are composable and performant (by using memoization).

bouchon is providing createSelector from reselect.

filterRows

filterRows is useful to filter an array easily.

Imagine that you want to retrieve the books of an author:

import { createSelector } from 'bouchon';

const selectors = {};

selectors.all = () => state => state.books;

selectors.byId = ({author}) => state => createSelector(
  selectors.all(),
  books => books.filter(book => book.author === author)
);

It could be written easier:

import { selectors } from 'bouchon-toolbox';
const { filterRows } = selectors;

const selectors = {};

selectors.all = () => state => state.books;
selectors.byAuthor = ({author}) => filterRows(selectors.all(), 'author', author);

filterRows returns a selector that can be use inside an another selector.

For example, if you want to return the books of an author for a specific years (it can be the response of an url like /books/:author/:date), you can do like this:

import { selectors } from 'bouchon-toolbox';
const { filterRows } = selectors;

const selectors = {};

selectors.all = () => state => state.books;
selectors.byAuthor = ({author}) => filterRows(selectors.all(), 'author', author);
selectors.byDate = ({author, date}) => filterRows(selectors.byAuthor({author}), 'date', date);

extendRows

extendRows is useful to extend a collection with data of an another collection.

For example, imagine that your want the author data with your books collection:

export const selectors = {};

selectors.books = () => state => state.books;
selectors.authors = () => state => state.authors;

selectors.all = () => extendRows(
  selectors.books(),
  'author_id',
  selectors.authors(),
  'id',
  'author',
);

It will return books with their author by comparing books.author_id with authors.id (similar to a SQL join query).

Installation

npm install bouchon-toolbox

Keywords

bouchon

FAQs

Package last updated on 13 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.