npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@recats/cdeebee

v2.2.5

Published

React Redux data-logic library

Downloads

81

Readme

cdeebee

npm Greenkeeper badge Travis badge Recats Digital

npm i @recats/cdeebee
# or
yarn add @recats/cdeebee

cdeebee

cdeebee is an alpha version of library which goals are:

  • Provide uniform way of access to data
  • Decrease boilerplate code amount when working with data fetching, updating, committing and rollbacking

The library is highly linked with Redux library and uses Redux as an internal storage

cdeebee works like traditional relational database and stores data lists in JS object (list) with keys as table names

For instance simple example how to structure forum case:

{
  forumList: { },
  threadList: { },
  postList: { }
}

Each list is JS object with keys ~~~ primary keys (ID) of objects For instance for the sample above the whole cdeebee inside Redux will look like for the forum devoted to the discussion about Universe

{
  forumList: { 1: { title: ‘Milky Way Galaxy’ } },
  threadList: { 10001: { title: ‘Solar system’, forumID: 1 } },
  postList: {  2: { title: ‘Earth’, threadID: 10001 } }
}

There are several standard functions to work with this structure:

  1. Edit field set of object
  2. Create new object
  3. Remove object
  4. Commit changes
  5. Revert changes
  6. Set new entity for the key
  7. Atomic update for many lists (this option is used when client receives new data from API)

In addition it’s highly recommended to adopt API to work with cdeebee. But otherwise you could use normalizr before using cdeebee to change your data structure from tree-like JSON to normalised lists

Finally there is a set of tools to work with API:

  • CdeebeeRequest function with is making request to server and manage queue with active requests
  • data normalisation and updating in cdeebee
  • necessary set of callbacks (preUpdate, preSuccess, postSuccess, preError)

Install

// reducer/index.js
import { cdeebee, requestManager } from '@recats/cdeebee';

export default combineReducers({
  cdeebeee,
  requestManager, // optional (checkNetworkActivity, cancelationRequest)
})


// Usage
// actions/*.js
import { CdeebeeRequest, cdeebeeMergeStrategy } from '@recats/cdeebee';

const request = new CdeebeeRequest(
  {
    // defaultRequest data
    data: { sessionToken: 'cdeebee master' },
  },
  {
    // option params
    globalErrorHandler: (error, request, meta) => (dispatch, getState) => void,
    // default request options
    fileKey: 'files',
    bodyKey: 'body',
    method: 'POST',
    primaryKey: 'primaryKey',
    normalize: defaultNormalize,
    responseKeyCode: 'responseStatus',
    header: { 'content-type': 'application/json' },
  }
).send;

export function requestServer(fn: () => void) {
  return (dispatch: Function, getState: Function) => (
    request({
      api: apiUrl.requestCdeebeee,

      data?: { cdeebee: 'cool' },
      files?: File,

      cdeebeeMergeStrategy?: { [listName]: cdeebeeMergeStrategy // default cdeebeeMergeStrategy.merge },
      requestStrategy?: $Keys<typeof cdeebeeRequestStrategy> # default undefined,
      primaryKey?: string // default 'primaryKey',

      method?: 'POST' | 'GET' | 'PUT' | 'DELETE',
      headers?: object,
      responseCode?: string,
      requestCancel?: boolean,  // default true
      updateStore?: boolean, // default true
      normalize?: ({ response, cdeebee, mergeStrategy }) => Object,

      // files
      bodyKey: 'body',
      fileKey: 'file',

      // key
      responseKeyCode: 'responseStatus',

      preUpdate?: (payload: object) => void,
      postUpdate?: (payload: object) => void,
      preError?: (payload: object) => void,
      postError?: (payload: object) => void,
    })(dispatch, getState)
  );
}

Methods

  cdeebee
  cdeebeeHelpers
  requestManager
  CdeebeeRequest // class
  cdeebeeTypes
  cdeebeeEntityState
  cdeebeeMergeStrategy // merge storage strategy
  cdeebeeValueList
  cdeebeeActions
  cdeebeActiveRequest
  cdeebeeIActions

Actions

// setKeyValue
import { cdeebeeActions } form '@recats/cdeebee';

this.props.cdeebeeActions.dropRequestByApiUrl: (api: string);
this.props.cdeebeeActions.dropErrorsByApiUrl: (api: string);
this.props.cdeebeeActions.dropCdeebeePath(path: (string | number)[]);

// these method are not recommended for usage because is not safe
this.props.cdeebeeActions.unsafe_updateStore(
  entityList: string,
  entityID: EntityID,
  value: any, // any value
)

this.props.cdeebeeActions.setKeyValue(
  entityList: string,
  entityID: EntityID,
  valueList: cdeebeeValueList,
)

this.props.cdeebeeActions.commitEntity(
  entityList: string,
  entityID: EntityID,
  entity: object,
)

this.props.cdeebeeActions.resetEntity(
  entityList: string,
  entityID: EntityID,
)

Helpers

import { cdeebeeHelpers } from '@recats/cdeebee';

// requestCancel
cdeebeeHelpers.requestCancel(activeRequest: cdeebeActiveRequest) => void;

// checkNetworkActivity
cdeebeeHelpers.checkNetworkActivity(activeRequest: cdeebeActiveRequest, apiUrl: string | Array<string>) => boolean;

// getSubEntity element in cdeebee list
cdeebeeHelpers.getSubEntity(entity: object) => object;

// getEntityState element in cdeebee list
cdeebeeHelpers.getEntityState(entity: object) => string;

// commitEntity element in cdeebee list
cdeebeeHelpers.commitEntity(entity: object) => void;

// resetEntity element in cdeebee list
cdeebeeHelpers.resetEntity(entity: object) => void;

Data merging behavior

During data merging cdeebee could behave in different ways according to the enum value which is passed during request

  • merge uses ramda mergeDeepRight strategy to merge existing object with the new one
  • replace overrides the object