# mtarh-cbind

> Extra lightweight callbacks memorization

Latest version **0.0.3** (published 2019-03-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install mtarh-cbind
pnpm add mtarh-cbind
yarn add mtarh-cbind
bun add mtarh-cbind
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2019-03-05 |
| First published | 2019-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | blrplex |
| Keywords | npm-package, package, npm, mtarh, bind, react, bind, callback |

## Links

- npm: https://www.npmjs.com/package/mtarh-cbind
- Repository: https://github.com/BLRplex/mtarh-cbind
- Homepage: https://github.com/BLRplex/mtarh-cbind#readme
- Issues: https://github.com/BLRplex/mtarh-cbind/issues
- npm.io page: https://npm.io/package/mtarh-cbind

## Dependencies (1)

- [weakmap-polyfill](https://npm.io/package/weakmap-polyfill.md) ^2.0.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2019-03-05
- 0.0.2 — 2019-03-05
- 0.0.1 — 2019-03-05

## README

# MTarh CBind

![Travis (.com)](https://img.shields.io/travis/com/BLRplex/mtarh-cbind.svg) ![Codecov](https://img.shields.io/codecov/c/github/BLRplex/mtarh-cbind.svg) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/BLRplex/mtarh-cbind.svg)

### Overview
The library allows to avoid creating multiple callbacks (memorize feature).

The `mtarhCBind(callback[, context])([callbackArguments])` always returns the same pointer, it does not create new functions for new calls even if arguments are different.

### Examples
```
function foo(a) {
    return a + 1;
}

const f1 = mtarhCBind(foo)(1);
const f2 = mtarhCBind(foo)(2);

f1(); // returns 2
f2(); // returns 3
f1 === f2; // true
```

### React use cases
```
const MyComponent = () => (
    <div onClick={() => {}}>Click me</div>
)
```

Each time when MyComponent renders it creates a new callback for "onClick" method. We can avoid it:
```
const MyComponent = () => (
    <div onClick={mtarhCBind(() => {})()}>Click me</div>
)
```

It allows to send custom arguments to callback. It merges previosly binded arguments with passed.
```
const handleElementClick = (event, index) => {};

const MyComponent = () => (
    <div>
        {elements.map((element, index) => (
            <li onClick={mtarhCBind(handleElementClick)(index)}>element</li>
        ))}
    </div>
)
```

---
_Source: https://npm.io/package/mtarh-cbind · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
