🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

json-api-denormalizr

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-api-denormalizr

## Getting Started

0.1.1
Source
npm
Version published
Weekly downloads
544
-14.06%
Maintainers
1
Weekly downloads
 
Created
Source

json-api-denormalizr

Getting Started

npm install json-api-denormalizr --save

Documentation

  • Quick Start
  • API
  • Usage with Reselect

Quickstart

Given the following store / state in your Redux application:

{
  "entities": {
    "postBlock": {
      "2620": {
        "id": "2620",
        "attributes": {
          "text": "I am great!",
          "id": "2620"
        },
        "relationships": {
          "question": {
            "data": {
              "id": "295",
              "type": "question"
            }
          }
        }
      }
    },
    "question": {
      "295": {
        "id": "295",
        "attributes": {
          "text": "How are you?",
          "id": "295"
        }
      }
    }
  }
}
import { denormalize } from 'json-api-denormalizr';

denormalize(state, {
  id: '2620',
  attributes: {
    text: 'I am great!',
    id: '2620'
  },
  relationships: {
    question: {
      data: {
        id: '295',
        type: 'question'
      }
    }
  }
});

// equivalent to:
denormalize(state, state.entities.postBlock['2620'])

Will result in:

{
  "id": "2620",
  "question": {
    "id": "295",
    "text": "How are you?"
  },
  "text": "I am great!"
}

API

denormalize(state, entity, options = {})

  • state: your application state
  • entity: the top level entity
  • options:
    • pathToEntities:
      • Where all your entities are located in the store. Assumes all your entities are at the same level of the store.

Usage with Reselect

Quick example using selectors:

import { createSelector } from 'reselect';
import { denormalize } from 'json-api-denormalizr';

const entitiesSelector = state => state.entities;
const booksSelector = state => state.entities.books;

export const bookSelector = bookId => {
  return createSelector([entitiesSelector, booksSelector], (entities, books) => {
    const book = books[bookId];

    return denormalize(entities, book, {
      pathToEntities: 'entities'
    });
  });
};

Contributing

npm test

Keywords

redux

FAQs

Package last updated on 03 Jul 2017

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