New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

types-redux-orm

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

types-redux-orm

Typescript types for Redux-ORM

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

types-redux-orm

Typescript types for Redux Orm

Important

It's an alpha version of types I currently use in one of my projects. They will be updated as I proceed with the project. No backward compatibility guaranteed.

Roadmap

01/13/18 - Beta release
02/03/18 - Stable release and merge into DefinitelyTyped

Install

npm install types-redux-orm

Modify your tsconfig.json as following:

...
"typeRoots": [
      "./node_modules/types-redux-orm",
      "./node_modules/@types"
    ],
...

Recipes

Model

import { attr, IORMCommonState, IORMId, ITableState, Model, ORM } from 'redux-orm'

export class Test extends Model<ITestStateItem, IFetchIndicatorState> {
  static modelName = 'Test'

  static fields = {
    test: attr(),
    isFetching: attr({ getDefault: () => false }),
    id: attr()
  }
}

// core data which we do not have defaults for
export interface ITestStateItem {
  test: string
}

// optional data we provide defaults for
export interface IFetchIndicatorState {
  isFetching: boolean
}

// id attr is added automatically by redux-orm therefore we have IORMId interface
export type ITestState = ITableState<ITestStateItem & IORMId & IFetchIndicatorState>

export interface ITestORMState extends IORMCommonState {
  Test: ITestState
}

interface ITestORMModels {
  Test: typeof Test
}

const orm = new ORM<ITestORMState>()
orm.register<ITestORMModels>(Test)
export default orm

Reducer

interface ITestDTO {
  test: string
}

const reducerAddItem = (state: ITestORMState, action: ActionMeta<ITestDTO, any>): ITestORMState => {
  const session = orm.session(state)
  session.Test.upsert<ITestStateItem>(action.payload)
  return session.state
}

Selector

import { createSelector as createSelectorORM, IORMId, ISession } from 'redux-orm'

interface ITestDisplayItem {
  test: string
}
type ITestDisplayItemList = ITestDisplayItem[]

export const makeGetTestDisplayList = () => {
  const ormSelector = createSelectorORM<ITestORMState>(orm, (session: ISession<ITestORMState>) =>
    session.Test
      .all<ITestStateItem, IFetchIndicatorState>()
      .toRefArray()
      .map((item) => ({ ...item }))
  })
  return createSelector<IRootState, ITestORMState, ITestDisplayItemList>(
    ({ test }) => test,
    ormSelector
  )
}

FAQs

Package last updated on 02 Apr 2018

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