Skip to content

Commit

Permalink
9.2.0 R.once TS type definition miss to context argument and its type (
Browse files Browse the repository at this point in the history
…#729)

* dsa

* chore@small

* prepare

* fix 726

* feat@fix

---------

Co-authored-by: Deyan Totev <[email protected]>
  • Loading branch information
selfrefactor and Deyan Totev authored Apr 2, 2024
1 parent 6863db5 commit 1d8507b
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 43 deletions.
49 changes: 42 additions & 7 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10214,7 +10214,7 @@ This method is also known as P combinator.

```typescript

once<T extends AnyFunction>(func: T): T
once<T extends AnyFunction, C = unknown>(fn: T, context?: C): T
```

It returns a function, which invokes only once `fn` function.
Expand All @@ -10235,7 +10235,7 @@ addOnce(1)
<summary>All TypeScript definitions</summary>

```typescript
once<T extends AnyFunction>(func: T): T;
once<T extends AnyFunction, C = unknown>(fn: T, context?: C): T;
```

</details>
Expand Down Expand Up @@ -10304,6 +10304,17 @@ test('happy path', () => {
)).toBe(60)
expect(addOneOnce(40)).toBe(60)
})

test('with context', () => {
const context = { name: 'fris' }
const getNameOnce = once(function (){
return this.name
}, context)

expect(getNameOnce()).toBe('fris')
expect(getNameOnce()).toBe('fris')
expect(getNameOnce()).toBe('fris')
})
```

</details>
Expand All @@ -10324,6 +10335,14 @@ describe('R.once', () => {
const result = runOnce(1)
result // $ExpectType number
})
it('with context', () => {
const runOnce = once(function (this: any, x: number) {
return x + 2
})

const result = runOnce.call({}, 1)
result // $ExpectType number
})
})
```

Expand Down Expand Up @@ -17067,13 +17086,17 @@ unless<T>(predicate: (x: T) => boolean, whenFalseFn: (x: T) => T): (x: T) => T;
<summary><strong>R.unless</strong> source</summary>

```javascript
export function unless(predicate, whenFalse){
if (arguments.length === 1){
return _whenFalse => unless(predicate, _whenFalse)
}
import { curry } from './curry.js'

function unlessFn(
predicate, whenFalseFn, input
){
if (predicate(input)) return input

return input => predicate(input) ? input : whenFalse(input)
return whenFalseFn(input)
}

export const unless = curry(unlessFn)
```

</details>
Expand All @@ -17097,6 +17120,11 @@ test('curried', () => {
const safeIncCurried = unless(isNil)(inc)
expect(safeIncCurried(null)).toBeNull()
})

test('with 3 inputs', () => {
let result = unless(x => x.startsWith('/'), x=> x.concat('/'), '/api')
expect(result).toBe('/api')
})
```

</details>
Expand Down Expand Up @@ -18502,9 +18530,16 @@ describe('R.zipWith', () => {

## ❯ CHANGELOG

9.1.2

This comment has been minimized.

Copy link
@jerome-benoit

jerome-benoit Apr 2, 2024

@selfrefactor: Thanks. I think the changelog version numbering does not match the npm release here ;-)

This comment has been minimized.

Copy link
@selfrefactor

selfrefactor Apr 4, 2024

Author Owner

there is no 9.1.2 - I will fix it in changelog source and it will be fixed with the next release


- `R.once` TS type definition miss to context argument and its type - [Issue #728](https://github.com/selfrefactor/rambda/issues/728)

- Fix implementation of `R.unless` function - https://github.com/selfrefactor/rambda/pull/726

9.1.1

- Faster R.equals with Object.is short circuit - https://github.com/selfrefactor/rambda/pull/725

- Fix R.cond transform is unary - https://github.com/selfrefactor/rambda/issues/720

9.1.0
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
9.1.2

- `R.once` TS type definition miss to context argument and its type - [Issue #728](https://github.com/selfrefactor/rambda/issues/728)

- Fix implementation of `R.unless` function - https://github.com/selfrefactor/rambda/pull/726

9.1.1

- Faster R.equals with Object.is short circuit - https://github.com/selfrefactor/rambda/pull/725

- Fix R.cond transform is unary - https://github.com/selfrefactor/rambda/issues/720

9.1.0
Expand Down
49 changes: 42 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9607,7 +9607,7 @@ This method is also known as P combinator.

```typescript

once<T extends AnyFunction>(func: T): T
once<T extends AnyFunction, C = unknown>(fn: T, context?: C): T
```

It returns a function, which invokes only once `fn` function.
Expand All @@ -9619,7 +9619,7 @@ It returns a function, which invokes only once `fn` function.
<summary>All TypeScript definitions</summary>

```typescript
once<T extends AnyFunction>(func: T): T;
once<T extends AnyFunction, C = unknown>(fn: T, context?: C): T;
```

</details>
Expand Down Expand Up @@ -9688,6 +9688,17 @@ test('happy path', () => {
)).toBe(60)
expect(addOneOnce(40)).toBe(60)
})

test('with context', () => {
const context = { name: 'fris' }
const getNameOnce = once(function (){
return this.name
}, context)

expect(getNameOnce()).toBe('fris')
expect(getNameOnce()).toBe('fris')
expect(getNameOnce()).toBe('fris')
})
```

</details>
Expand All @@ -9708,6 +9719,14 @@ describe('R.once', () => {
const result = runOnce(1)
result // $ExpectType number
})
it('with context', () => {
const runOnce = once(function (this: any, x: number) {
return x + 2
})

const result = runOnce.call({}, 1)
result // $ExpectType number
})
})
```

Expand Down Expand Up @@ -15876,13 +15895,17 @@ unless<T>(predicate: (x: T) => boolean, whenFalseFn: (x: T) => T): (x: T) => T;
<summary><strong>R.unless</strong> source</summary>

```javascript
export function unless(predicate, whenFalse){
if (arguments.length === 1){
return _whenFalse => unless(predicate, _whenFalse)
}
import { curry } from './curry.js'

function unlessFn(
predicate, whenFalseFn, input
){
if (predicate(input)) return input

return input => predicate(input) ? input : whenFalse(input)
return whenFalseFn(input)
}

export const unless = curry(unlessFn)
```

</details>
Expand All @@ -15906,6 +15929,11 @@ test('curried', () => {
const safeIncCurried = unless(isNil)(inc)
expect(safeIncCurried(null)).toBeNull()
})

test('with 3 inputs', () => {
let result = unless(x => x.startsWith('/'), x=> x.concat('/'), '/api')
expect(result).toBe('/api')
})
```

</details>
Expand Down Expand Up @@ -17192,9 +17220,16 @@ describe('R.zipWith', () => {

## ❯ CHANGELOG

9.1.2

- `R.once` TS type definition miss to context argument and its type - [Issue #728](https://github.com/selfrefactor/rambda/issues/728)

- Fix implementation of `R.unless` function - https://github.com/selfrefactor/rambda/pull/726

9.1.1

- Faster R.equals with Object.is short circuit - https://github.com/selfrefactor/rambda/pull/725

- Fix R.cond transform is unary - https://github.com/selfrefactor/rambda/issues/720

9.1.0
Expand Down
9 changes: 4 additions & 5 deletions dist/rambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -2380,12 +2380,11 @@ function uniqWith(predicate, list) {
return willReturn;
}

function unless(predicate, whenFalse) {
if (arguments.length === 1) {
return _whenFalse => unless(predicate, _whenFalse);
}
return input => predicate(input) ? input : whenFalse(input);
function unlessFn(predicate, whenFalseFn, input) {
if (predicate(input)) return input;
return whenFalseFn(input);
}
const unless = curry(unlessFn);

function unnest(list) {
return list.reduce((acc, item) => {
Expand Down
2 changes: 1 addition & 1 deletion dist/rambda.umd.js

Large diffs are not rendered by default.

49 changes: 42 additions & 7 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9607,7 +9607,7 @@ This method is also known as P combinator.

```typescript

once<T extends AnyFunction>(func: T): T
once<T extends AnyFunction, C = unknown>(fn: T, context?: C): T
```

It returns a function, which invokes only once `fn` function.
Expand All @@ -9619,7 +9619,7 @@ It returns a function, which invokes only once `fn` function.
<summary>All TypeScript definitions</summary>

```typescript
once<T extends AnyFunction>(func: T): T;
once<T extends AnyFunction, C = unknown>(fn: T, context?: C): T;
```

</details>
Expand Down Expand Up @@ -9688,6 +9688,17 @@ test('happy path', () => {
)).toBe(60)
expect(addOneOnce(40)).toBe(60)
})

test('with context', () => {
const context = { name: 'fris' }
const getNameOnce = once(function (){
return this.name
}, context)

expect(getNameOnce()).toBe('fris')
expect(getNameOnce()).toBe('fris')
expect(getNameOnce()).toBe('fris')
})
```

</details>
Expand All @@ -9708,6 +9719,14 @@ describe('R.once', () => {
const result = runOnce(1)
result // $ExpectType number
})
it('with context', () => {
const runOnce = once(function (this: any, x: number) {
return x + 2
})

const result = runOnce.call({}, 1)
result // $ExpectType number
})
})
```

Expand Down Expand Up @@ -15876,13 +15895,17 @@ unless<T>(predicate: (x: T) => boolean, whenFalseFn: (x: T) => T): (x: T) => T;
<summary><strong>R.unless</strong> source</summary>

```javascript
export function unless(predicate, whenFalse){
if (arguments.length === 1){
return _whenFalse => unless(predicate, _whenFalse)
}
import { curry } from './curry.js'

function unlessFn(
predicate, whenFalseFn, input
){
if (predicate(input)) return input

return input => predicate(input) ? input : whenFalse(input)
return whenFalseFn(input)
}

export const unless = curry(unlessFn)
```

</details>
Expand All @@ -15906,6 +15929,11 @@ test('curried', () => {
const safeIncCurried = unless(isNil)(inc)
expect(safeIncCurried(null)).toBeNull()
})

test('with 3 inputs', () => {
let result = unless(x => x.startsWith('/'), x=> x.concat('/'), '/api')
expect(result).toBe('/api')
})
```

</details>
Expand Down Expand Up @@ -17192,9 +17220,16 @@ describe('R.zipWith', () => {

## ❯ CHANGELOG

9.1.2

- `R.once` TS type definition miss to context argument and its type - [Issue #728](https://github.com/selfrefactor/rambda/issues/728)

- Fix implementation of `R.unless` function - https://github.com/selfrefactor/rambda/pull/726

9.1.1

- Faster R.equals with Object.is short circuit - https://github.com/selfrefactor/rambda/pull/725

- Fix R.cond transform is unary - https://github.com/selfrefactor/rambda/issues/720

9.1.0
Expand Down
6 changes: 5 additions & 1 deletion files/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2754,7 +2754,7 @@ Notes:
*/
// @SINGLE_MARKER
export function once<T extends AnyFunction>(func: T): T;
export function once<T extends AnyFunction, C = unknown>(fn: T, context?: C): T;

/*
Method: omit
Expand Down Expand Up @@ -6981,6 +6981,8 @@ Notes:
// @SINGLE_MARKER
export function mapToObject<T, U extends object>(fn: (input: T) => U|false, list: readonly T[]): U;
export function mapToObject<T, U extends object>(fn: (input: T) => U|false): (list: readonly T[]) => U;
export function mapToObject<T, U>(fn: (input: T) => object|false, list: T[]): U;
export function mapToObject<T, U>(fn: (input: T) => object|false): (list: T[]) => U;

/*
Method: mapToObjectAsync
Expand All @@ -7001,6 +7003,8 @@ Notes:
// @SINGLE_MARKER
export function mapToObjectAsync<T, U extends object>(fn: (input: T) => Promise<U|false>, list: readonly T[]): Promise<U>;
export function mapToObjectAsync<T, U extends object>(fn: (input: T) => Promise<U|false>): (list: readonly T[]) => Promise<U>;
export function mapToObjectAsync<T, U>(fn: (input: T) => Promise<Output[keyof Output]|false>, list: T[]): Promise<U>;
export function mapToObjectAsync<T, U>(fn: (input: T) => Promise<Output[keyof Output]|false>): (list: T[]) => Promise<U>;

/*
Method: mapKeys
Expand Down
2 changes: 1 addition & 1 deletion immutable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ export function on<T, U, R>(binaryFn: (a: U, b: U) => R, unaryFn: (value: T) =>
/**
* It returns a function, which invokes only once `fn` function.
*/
export function once<T extends AnyFunction>(func: T): T;
export function once<T extends AnyFunction, C = unknown>(fn: T, context?: C): T;

/**
* Logical OR
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ export function on<T, U, R>(binaryFn: (a: U, b: U) => R, unaryFn: (value: T) =>
/**
* It returns a function, which invokes only once `fn` function.
*/
export function once<T extends AnyFunction>(func: T): T;
export function once<T extends AnyFunction, C = unknown>(fn: T, context?: C): T;

/**
* Logical OR
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"test:all": "jest source/*.spec.js -u --bail=false",
"test:ci": "jest source/*.spec.js --coverage --no-cache -w 1",
"test:typings": "dtslint --localTs ./node_modules/typescript/lib --expectOnly ./source",
"test:ts": "yarn test:typings",
"ts": "yarn test:typings",
"usedby": "cd ../rambda-scripts && yarn usedby",
"x": "yarn populatedocs:x && yarn populatereadme:x && yarn immutable:x"
Expand Down
Loading

0 comments on commit 1d8507b

Please sign in to comment.