Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-imm

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-imm

case classes for TypeScript

  • 0.4.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ts-imm

Simple data classes in TypeScript, modeled after case classes in Scala.

Usage

class SimpleData extends Imm<SimpleData> {
  @imm public name!: string;
  @imm public address?: string;

  public someBusinessLogic(): this {
    return this.copy({name: "new name"});
  }
}

describe("imm", () => {
  it("can create a new instance", () => {
    const d = new SimpleData({name: "a"});
    expect(d.name).toEqual("a");
    expect(d.address).toBeUndefined();
  });

  it("can someBusinessLogic a property with a method", () => {
    const a = new SimpleData({name: "a"});
    expect(a.name).toEqual("a");
    const b = a.someBusinessLogic();
    expect(a.name).toEqual("a");
    expect(b.name).toEqual("new name");
  });

  it("can someBusinessLogic a property with the generic copy constructor", () => {
    const a = new SimpleData({name: "a"});
    expect(a.address).toBeUndefined();
    const b = a.copy({address: "b"});
    expect(a.address).toBeUndefined();
    expect(b.address).toEqual("b");
  });

});

Disclaimers

  • Uses an immutable.js map under the hood; in theory this is good, but I'm not an expert on that vs. just a Object.assign
  • I've not done any testing/thinking about inheritance; in case classes this was a bad idea
  • The intent is not to model your entire tree of Redux stores, this is "just data classes"

Credits

Inspiration from stimo.

Keywords

FAQs

Package last updated on 20 Oct 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc