This package has been deprecated

Author message:

Package no longer maintained.

dynamic-on-change
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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; }>'.

Readme

Keywords

Package Sidebar

Install

npm i dynamic-on-change

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

4.61 kB

Total Files

5

Last publish

Collaborators

  • danielpanpm