azu / azu/idempotent-bind

Change WeakMap hirerarchy

Open
#2 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
15
Forks
1
PR merge metrics
No merged PRs in 30d

Description

The library currently accesses by function, and then by context. It's much more likely that the context will be garbage collected than a function.

eg:

```
function Foo {
this._message = 'hi';
}

Foo.prototype.bar = function () {
console.log(this._message);
}
```

```
var foo = new Foo();

bind(foo.bar, foo);
```

As you can see, with OOP, `foo.bar`, which is really `Foo.prototype.bar`, will never be garbage collected, however the `foo` instance will be.

By reversing the WeakMaps, it's very likely that the `unbind` function isn't needed anymore, making `idempotent-bind` a true drop-in replacement.

I can submit a PR if this change is welcome.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the library's current WeakMap access pattern and the behavior of bind and unbind described in the issue. Check how reversing the maps affects garbage collection and whether unbind can be removed without changing the drop-in replacement behavior; done means the revised behavior is verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.