Skip to content

Commit 1fa3ac2

Browse files
committed
v6.3.1 - fix 6.0.0 regressions breaking event-emitted-grouped
1 parent a19f9f0 commit 1fa3ac2

File tree

7 files changed

+58
-33
lines changed

7 files changed

+58
-33
lines changed

.github/workflows/bevry.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
- run: npm run our:compile
6767
- run: npm run our:meta
6868
- name: publish to npm
69-
uses: bevry-actions/[email protected].5
69+
uses: bevry-actions/[email protected].6
7070
with:
7171
npmAuthToken: ${{ secrets.NPM_AUTH_TOKEN }}
7272
npmBranchTag: ':next'

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# History
22

3+
## v6.3.1 2023 December 29
4+
5+
- Fixed v6.0.0+ breaking compatibility with `event-emitter-grouped`; we once again export `bind` and `define`, and return the bounded function with `define`
6+
- Thank you to the sponsors: [Andrew Nesbitt](https://nesbitt.io), [Balsa](https://balsa.com), [Codecov](https://codecov.io), [Poonacha Medappa](https://poonachamedappa.com), [Rob Morris](https://github.com/Rob-Morris), [Sentry](https://sentry.io), [Syntax](https://syntax.fm)
7+
38
## v6.3.0 2023 December 29
49

510
- Updated dependencies, [base files](https://github.com/bevry/base), and [editions](https://editions.bevry.me) using [boundation](https://github.com/bevry/boundation)

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,27 @@ equal(boundedFunction.unbounded, myFunction, 'unbounded was correct')
9090
### [Deno](https://deno.land "Deno is a secure runtime for JavaScript and TypeScript, it is an alternative for Node.js")
9191

9292
``` typescript
93-
import * as pkg from 'https://unpkg.com/unbounded@^6.3.0/edition-deno/index.ts'
93+
import * as pkg from 'https://unpkg.com/unbounded@^6.3.1/edition-deno/index.ts'
9494
```
9595
### [Skypack](https://www.skypack.dev "Skypack is a JavaScript Delivery Network for modern web apps")
9696

9797
``` html
9898
<script type="module">
99-
import * as pkg from '//cdn.skypack.dev/unbounded@^6.3.0'
99+
import * as pkg from '//cdn.skypack.dev/unbounded@^6.3.1'
100100
</script>
101101
```
102102
### [unpkg](https://unpkg.com "unpkg is a fast, global content delivery network for everything on npm")
103103

104104
``` html
105105
<script type="module">
106-
import * as pkg from '//unpkg.com/unbounded@^6.3.0'
106+
import * as pkg from '//unpkg.com/unbounded@^6.3.1'
107107
</script>
108108
```
109109
### [jspm](https://jspm.io "Native ES Modules CDN")
110110

111111
``` html
112112
<script type="module">
113-
import * as pkg from '//dev.jspm.io/[email protected].0'
113+
import * as pkg from '//dev.jspm.io/[email protected].1'
114114
</script>
115115
```
116116
### [Editions](https://editions.bevry.me "Editions are the best way to produce and consume packages you care about.")

package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unbounded",
3-
"version": "6.3.0",
3+
"version": "6.3.1",
44
"license": "Artistic-2.0",
55
"description": "Function.prototype.bind replacement that provides an `unbounded` hidden property on the returned bounded function, that contains the original unbounded function",
66
"homepage": "https://github.com/bevry/unbounded",
@@ -246,7 +246,7 @@
246246
"eslint-config-bevry": "^5.3.0",
247247
"eslint-config-prettier": "^9.1.0",
248248
"eslint-plugin-prettier": "^5.1.2",
249-
"kava": "^7.6.0",
249+
"kava": "^7.7.0",
250250
"make-deno-edition": "^2.2.0",
251251
"prettier": "^3.1.1",
252252
"projectz": "^4.1.1",

source/index.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
const bind = Function.prototype.bind
2-
31
declare global {
42
interface Function {
53
/** The original function, before any binding. */
64
unbounded?: this
75
}
86
}
97

8+
/** The original native bind function, before {@link patch} wraps it. */
9+
export const bind = Function.prototype.bind
10+
1011
/**
1112
* Attach the `unbounded` property on the `bounded` function.
1213
* If `unbounded.unbounded` already exists, then it is used instead, to ensure that the `unbounded` property is always the original function.
14+
* @param bounded the bounded function
15+
* @param unbounded the original function, before any binding
1316
*/
14-
function define<T extends Function>(bounded: T, unbounded: T): void {
17+
export function define<T extends Function>(bounded: T, unbounded: T): T {
1518
if (bounded.unbounded !== unbounded) {
1619
Object.defineProperty(bounded, 'unbounded', {
1720
value: unbounded.unbounded || unbounded,
@@ -20,16 +23,25 @@ function define<T extends Function>(bounded: T, unbounded: T): void {
2023
writable: false,
2124
})
2225
}
26+
return bounded
2327
}
2428

2529
/**
2630
* Alternative to `Function.prototype.bind` that sets the `unbounded` property on the bounded function.
2731
* Types of this are not intelligent, as using the intelligent bind types causes this/unknown incompatibility. This is not important however, as the masquerading binder of {@link patch} has the intelligent types.
32+
* @example `a.bind(context, arg1, arg2)` is equivalent to `binder.call(a, context, arg1, arg2)`
33+
* @param this the function that will be bounded
34+
* @param newThis the new `this` context to attach to the bounded function
35+
* @param prefilledArguments the arguments to prefill the bounded function with
2836
*/
29-
export function binder(this: Function, thisArg: any, ...argArray: any[]): any {
30-
const bounded = bind.call(this, thisArg, ...argArray)
31-
define(bounded, this)
32-
return bounded
37+
export function binder(
38+
this: Function,
39+
newThis: any,
40+
...prefilledArguments: any[]
41+
): any {
42+
const unbounded = this
43+
const bounded = bind.call(unbounded, newThis, ...prefilledArguments)
44+
return define(bounded, unbounded)
3345
}
3446

3547
/** Patch the native `Function.prototype.bind` so that it sets the `unbounded` property on the bounded function. */

source/test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as unbounded from './index.js'
1+
import { binder, define, patch } from './index.js'
22
import { equal } from 'assert-helpers'
33
import kava from 'kava'
44

@@ -7,6 +7,14 @@ interface Context {
77
}
88

99
kava.suite('unbounded', function (suite, test) {
10+
test('define works', function () {
11+
const a = function () {}
12+
const b = function () {}
13+
const c = function () {}
14+
define(b, c)
15+
define(a, b)
16+
equal(a.unbounded, c, 'unbounded was correct')
17+
})
1018
test('binder works', function () {
1119
const context: Context = {
1220
str: 'a',
@@ -16,22 +24,22 @@ kava.suite('unbounded', function (suite, test) {
1624
return this.str
1725
}
1826

19-
const b = unbounded.binder.call(a, context)
27+
const b = binder.call(a, context)
2028
equal(b.unbounded, a, 'unbounded was correct')
2129
equal(b(), context.str, 'context was correct')
2230
equal(context.str, 'a', 'context was correct')
2331
equal(b('b'), context.str, 'context was correct')
2432
equal(context.str, 'b', 'context was correct')
2533

26-
const c = unbounded.binder.call(a, context, 'c')
34+
const c = binder.call(a, context, 'c')
2735
equal(c.unbounded, a, 'unbounded was correct')
2836
equal(c(), context.str, 'context was correct')
2937
equal(context.str, 'c', 'context was correct')
3038

3139
equal(b.unbounded, a, 'unbounded was correct')
3240
})
3341
test('patch works', function () {
34-
unbounded.patch()
42+
patch()
3543
const context: Context = {
3644
str: 'a',
3745
}

0 commit comments

Comments
 (0)