dynamic-on-change

An utility for managing on change functions

Package no longer maintained.
Last updated 3 years ago by danielpanpm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install dynamic-on-change 
SYNC missed versions from official npm registry.

dynamic-on-change

An utility for managing on change functions. This is meant to be used with react components for avoiding binding instance methods.

Typescript support. Made in typescript ;)

Example

import dynamicOnChange from "./index";
const a = {
  hello: "world",
  foo: 3,
};
const onChange = dynamicOnChange<typeof a>((key, value) => {
  a[key] = value;
});
onChange.foo(5);
expect(a).toMatchObject({ hello: "world", foo: 5 });
onChange.hello("me");
expect(a).toMatchObject({ hello: "me", foo: 5 });

// invalid in typescript
onChange.foo("hello"); // error: Argument of type '"hello"' is not assignable to parameter of type 'number'.
onChange.hello(3); // error: Argument of type '3' is not assignable to parameter of type 'string'.
onChange.asdf("me"); // error: Property 'asdf' does not exist on type 'dynamicOnChanges<{ hello: string; foo: number; }>'.

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

1 Versions

  • 1.0.0 [deprecated]           ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (14)

Copyright 2014 - 2021 © npmmirror.com |