1.0.1 • Published 6 years ago

plain-class v1.0.1

Weekly downloads
5
License
Unlicense
Repository
github
Last release
6 years ago

plain-class Build Status

Base class to return a plain object from your class.

Even if it is required to be a plain object, you can use class syntax (also TypeScript).

Install

npm install plain-class

Example

Define action creator as a class in TypeScript

import Plain from 'plain-class';

export class RequestPosts extends Plain {
  readonly type = 'REQUEST_POSTS';
  constructor(
    public subreddit: string
  ) { super(); }
}

Define partial state as a class in TypeScript

import Plain from 'plain-class';
import { Reducer } from 'redux';
import { Action } from '../actions';

class Posts extends Plain {
  isFetching = false;
  didInvalidate = false;
  items: string[] = [];
  lastUpdated: number | undefined = undefined;
}

const posts: Reducer<Posts> = (state = new Posts, action: Action) => {
  // ...
};

License

Unlicense