Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier config change #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# see https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt

# Prettier change:
# "trailingComma": "es5" -> "all";
# "printWidth": 80 -> 100;
f6326cffe7c08ee5755c3c4f46a27458165b1553
4 changes: 2 additions & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"bracketSpacing": true,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 100,
"trailingComma": "all",
"tabWidth": 4
}
14 changes: 14 additions & 0 deletions README.dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ Here is how you do this:
* [new tag] v0.0.9 -> v0.0.9

```

## Format the code

### ignore-revs-file

Sometimes (after long and bloody discussions) we decide to change `.prettierrc.json`. It leads to a huge commit,
as `Prettier` automatically reformats all the project files in a pre-commit hook. This commit has no use for git-blame,
so we'd like to ignore it, i.e. see the blame of previous commit for strings affected by reformatting.
Here comes [.git-blame-ignore-revs](./.git-blame-ignore-revs) file where we list such commits.
To make it work in your local repo, run

```shell
git config blame.ignoreRevsFile .git-blame-ignore-revs
```
3 changes: 1 addition & 2 deletions src/TestUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const inc = (x: number) => x + 1
export const sum = (...nums: number[]) =>
nums.reduce((x: number, y: number) => x + y, 0)
export const sum = (...nums: number[]) => nums.reduce((x: number, y: number) => x + y, 0)
export const identity = <T>(x: T) => x
export const negate = (x: boolean) => !x

Expand Down
29 changes: 11 additions & 18 deletions src/impl/FormulaCell.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ import { FormulaCell, Cell, SourceCell, cell, map } from '../index'
const justString = 'a'

// functions passed to map
const mapFn = (
n1: number,
n2: number,
n3: number,
s1: string,
s2: string,
s3: string
) =>
const mapFn = (n1: number, n2: number, n3: number, s1: string, s2: string, s3: string) =>
[
Math.round(n1) + Math.round(n2) + Math.round(n3),
s1.toUpperCase() + s2.toUpperCase() + s3.toUpperCase(),
Expand All @@ -49,7 +42,7 @@ import { FormulaCell, Cell, SourceCell, cell, map } from '../index'
n3: boolean,
s1: string,
s2: string,
s3: string
s3: string,
) =>
[
Math.round(n1) + Math.round(n2) + (n3 ? 1 : 2),
Expand All @@ -61,7 +54,7 @@ import { FormulaCell, Cell, SourceCell, cell, map } from '../index'
n3: number,
s1: string,
s2: string,
s3: boolean
s3: boolean,
) =>
[
Math.round(n1) + Math.round(n2) + Math.round(n3),
Expand All @@ -76,7 +69,7 @@ import { FormulaCell, Cell, SourceCell, cell, map } from '../index'
justNumber,
stringCell,
formulaStringCell,
justString
justString,
)
const allFormulaInput = map(
mapFn,
Expand All @@ -85,7 +78,7 @@ import { FormulaCell, Cell, SourceCell, cell, map } from '../index'
formulaNumberCell,
formulaStringCell,
formulaStringCell,
formulaStringCell
formulaStringCell,
)
const allCellInput = map(
mapFn,
Expand All @@ -94,7 +87,7 @@ import { FormulaCell, Cell, SourceCell, cell, map } from '../index'
numberCell,
stringCell,
stringCell,
stringCell
stringCell,
)
const allRawInput = map(
mapFn,
Expand All @@ -103,7 +96,7 @@ import { FormulaCell, Cell, SourceCell, cell, map } from '../index'
justNumber,
justString,
justString,
justString
justString,
)

// tests
Expand All @@ -125,8 +118,8 @@ import { FormulaCell, Cell, SourceCell, cell, map } from '../index'
justNumber,
stringCell,
formulaStringCell,
justString
)
justString,
),
)
expectError(
map(
Expand All @@ -136,7 +129,7 @@ import { FormulaCell, Cell, SourceCell, cell, map } from '../index'
justNumber,
stringCell,
formulaStringCell,
justString
)
justString,
),
)
}
73 changes: 29 additions & 44 deletions src/impl/FormulaCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export class FormulaCell<T> implements Cell<T>, Recalculable {

public deref(): T {
if (this.destroyed) {
throw new OperationOnDestroyedCellError(
'Impossible to deref a destroyed cell'
)
throw new OperationOnDestroyedCellError('Impossible to deref a destroyed cell')
}
return this.val
}
Expand All @@ -41,7 +39,7 @@ export class FormulaCell<T> implements Cell<T>, Recalculable {
'\noccurred while recalculating\n',
this,
'\nwith the following arguments\n',
args
args,
)
return this.val
}
Expand All @@ -53,9 +51,7 @@ export class FormulaCell<T> implements Cell<T>, Recalculable {

public addSubscriber(subscriber: Recalculable & Destroyable): void {
if (this.destroyed) {
throw new OperationOnDestroyedCellError(
'Impossible to subscribe a destroyed cell'
)
throw new OperationOnDestroyedCellError('Impossible to subscribe a destroyed cell')
}
this.subs.add(subscriber)
}
Expand Down Expand Up @@ -96,37 +92,29 @@ type InferReturn<T> = T extends (...args: any[]) => infer U ? U : never
export function formula<
T1 extends Value<unknown>,
FN extends (val1: UnwrapCell<T1>) => unknown,
R = InferReturn<FN>
R = InferReturn<FN>,
>(fn: FN, input1: T1): T1 extends Cell<any> ? FormulaCell<R> : R
export function formula<
T1 extends Value<unknown>,
T2 extends Value<unknown>,
FN extends (val1: UnwrapCell<T1>, val2: UnwrapCell<T2>) => unknown,
R = InferReturn<FN>
R = InferReturn<FN>,
>(
fn: FN,
input1: T1,
input2: T2
): T1 extends Cell<any>
? FormulaCell<R>
: T2 extends Cell<any>
? FormulaCell<R>
: R
input2: T2,
): T1 extends Cell<any> ? FormulaCell<R> : T2 extends Cell<any> ? FormulaCell<R> : R
export function formula<
T1 extends Value<unknown>,
T2 extends Value<unknown>,
T3 extends Value<unknown>,
FN extends (
val1: UnwrapCell<T1>,
val2: UnwrapCell<T2>,
val3: UnwrapCell<T3>
) => unknown,
R = InferReturn<FN>
FN extends (val1: UnwrapCell<T1>, val2: UnwrapCell<T2>, val3: UnwrapCell<T3>) => unknown,
R = InferReturn<FN>,
>(
fn: FN,
input1: T1,
input2: T2,
input3: T3
input3: T3,
): T1 extends Cell<any>
? FormulaCell<R>
: T2 extends Cell<any>
Expand All @@ -143,15 +131,15 @@ export function formula<
val1: UnwrapCell<T1>,
val2: UnwrapCell<T2>,
val3: UnwrapCell<T3>,
val4: UnwrapCell<T4>
val4: UnwrapCell<T4>,
) => unknown,
R = InferReturn<FN>
R = InferReturn<FN>,
>(
fn: FN,
input1: T1,
input2: T2,
input3: T3,
input4: T4
input4: T4,
): T1 extends Cell<any>
? FormulaCell<R>
: T2 extends Cell<any>
Expand All @@ -172,16 +160,16 @@ export function formula<
val2: UnwrapCell<T2>,
val3: UnwrapCell<T3>,
val4: UnwrapCell<T4>,
val5: UnwrapCell<T5>
val5: UnwrapCell<T5>,
) => unknown,
R = InferReturn<FN>
R = InferReturn<FN>,
>(
fn: FN,
input1: T1,
input2: T2,
input3: T3,
input4: T4,
input5: T5
input5: T5,
): T1 extends Cell<any>
? FormulaCell<R>
: T2 extends Cell<any>
Expand All @@ -206,17 +194,17 @@ export function formula<
val3: UnwrapCell<T3>,
val4: UnwrapCell<T4>,
val5: UnwrapCell<T5>,
val6: UnwrapCell<T6>
val6: UnwrapCell<T6>,
) => unknown,
R = InferReturn<FN>
R = InferReturn<FN>,
>(
fn: FN,
input1: T1,
input2: T2,
input3: T3,
input4: T4,
input5: T5,
input6: T6
input6: T6,
): T1 extends Cell<any>
? FormulaCell<R>
: T2 extends Cell<any>
Expand Down Expand Up @@ -245,9 +233,9 @@ export function formula<
val4: UnwrapCell<T4>,
val5: UnwrapCell<T5>,
val6: UnwrapCell<T6>,
val7: UnwrapCell<T7>
val7: UnwrapCell<T7>,
) => unknown,
R = InferReturn<FN>
R = InferReturn<FN>,
>(
fn: FN,
input1: T1,
Expand All @@ -256,7 +244,7 @@ export function formula<
input4: T4,
input5: T5,
input6: T6,
input7: T7
input7: T7,
): T1 extends Cell<any>
? FormulaCell<R>
: T2 extends Cell<any>
Expand Down Expand Up @@ -289,9 +277,9 @@ export function formula<
val5: UnwrapCell<T5>,
val6: UnwrapCell<T6>,
val7: UnwrapCell<T7>,
val8: UnwrapCell<T8>
val8: UnwrapCell<T8>,
) => unknown,
R = InferReturn<FN>
R = InferReturn<FN>,
>(
fn: FN,
input1: T1,
Expand All @@ -301,7 +289,7 @@ export function formula<
input5: T5,
input6: T6,
input7: T7,
input8: T8
input8: T8,
): T1 extends Cell<any>
? FormulaCell<R>
: T2 extends Cell<any>
Expand Down Expand Up @@ -338,9 +326,9 @@ export function formula<
val6: UnwrapCell<T6>,
val7: UnwrapCell<T7>,
val8: UnwrapCell<T8>,
val9: UnwrapCell<T9>
val9: UnwrapCell<T9>,
) => unknown,
R = InferReturn<FN>
R = InferReturn<FN>,
>(
fn: FN,
input1: T1,
Expand All @@ -351,7 +339,7 @@ export function formula<
input6: T6,
input7: T7,
input8: T8,
input9: T9
input9: T9,
): T1 extends Cell<any>
? FormulaCell<R>
: T2 extends Cell<any>
Expand All @@ -371,10 +359,7 @@ export function formula<
: T9 extends Cell<any>
? FormulaCell<R>
: R
export function formula<T>(
fn: Function,
...sources: Value<unknown>[]
): FormulaCell<T> | T {
export function formula<T>(fn: Function, ...sources: Value<unknown>[]): FormulaCell<T> | T {
if (sources.some(isCell)) {
return new FormulaCell(fn, ...sources)
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/impl/Formulas.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ import {
expectType<FormulaCell<number | boolean | undefined>>(field(s1, recCell))
expectType<FormulaCell<number | boolean | undefined>>(field(s2, recCell))
// Notice: non-existing key Symbol('c')
expectType<FormulaCell<number | boolean | undefined>>(
field(Symbol('c'), recCell)
)
expectType<FormulaCell<number | boolean | undefined>>(field(Symbol('c'), recCell))

// cannot pass key of wrong type
expectError(field(1, recCell))
Expand Down
Loading