Skip to content

Commit

Permalink
Run prettier on all files
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-spiess committed Oct 13, 2018
1 parent 4869802 commit 0a46eef
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
},
"scripts": {
"test": "run-p test:js test:types:*",
"prettier": "prettier {{__tests__,src,type-definitions}/**.{js,flow},README.md}",
"format": "prettier --write",
"prettier": "prettier {{__tests__,src,type-definitions}/**/*.{js,flow,ts},README.md}",
"format": "yarn prettier --write",

This comment has been minimized.

Copy link
@nataly87s

nataly87s Oct 13, 2018

Contributor

is there a reason you add yarn?
it forces it to use yarn, but not everyone uses yarn (or has it installed)

This comment has been minimized.

Copy link
@philipp-spiess

philipp-spiess Oct 13, 2018

Author Owner

Ohh thanks for spotting this!

This comment has been minimized.

Copy link
@philipp-spiess

philipp-spiess Oct 13, 2018

Author Owner

Fixed it up 🙂

"test:js": "jest",
"test:types:ts": "yarn build && tsc ./type-definitions/ReComponent.d.ts --lib es2015 && dtslint type-definitions/ts-tests",
"test:types:flow": "flow check .",
Expand Down
36 changes: 22 additions & 14 deletions type-definitions/ReComponent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,63 @@ export enum UpdateType {
NO_UPDATE = 0,
UPDATE = 1,
SIDE_EFFECTS = 2,
UPDATE_WITH_SIDE_EFFECTS = 3,
UPDATE_WITH_SIDE_EFFECTS = 3
}

export type SideEffect<T> = (this: T) => any;

export type NoUpdateAction = {
type: UpdateType.NO_UPDATE;
}
};

export type UpdateAction<T> = {
type: UpdateType.UPDATE;
state: T;
}
};

export type SideEffectsAction<T> = {
type: UpdateType.SIDE_EFFECTS;
sideEffects: SideEffect<T>;
}
};

export type UpdateWithSideEffectsAction<S, SE> = {
type: UpdateType.UPDATE_WITH_SIDE_EFFECTS;
state: S;
sideEffects: SideEffect<SE>;
}
};

export type ReducerAction<S, SE> =
NoUpdateAction |
UpdateAction<S> |
SideEffectsAction<SE> |
UpdateWithSideEffectsAction<S, SE>;
| NoUpdateAction
| UpdateAction<S>
| SideEffectsAction<SE>
| UpdateWithSideEffectsAction<S, SE>;

export function NoUpdate(): NoUpdateAction;

export function Update<T>(state: T): UpdateAction<T>;

export function SideEffects<T>(sideEffect: SideEffect<T>): SideEffectsAction<T>;

export function UpdateWithSideEffects<S, SE>(state: S, sideEffects: SideEffect<SE>): UpdateWithSideEffectsAction<S, SE>;
export function UpdateWithSideEffects<S, SE>(
state: S,
sideEffects: SideEffect<SE>
): UpdateWithSideEffectsAction<S, SE>;

export type Action = {
type: string;
}
};

export class ReComponent<P = {}, S = {}> extends Component<P, S> {
static reducer<TState, TAction extends Action, TSideEffect = any>(action: Action, state: TState): ReducerAction<TState, TSideEffect>;
static reducer<TState, TAction extends Action, TSideEffect = any>(
action: Action,
state: TState
): ReducerAction<TState, TSideEffect>;

send<TAction extends Action>(action: TAction): void;

createSender<TAction extends string>(type: TAction): (<TPayload>(payload: TPayload) => { type: TAction, payload: TPayload });
createSender<TAction extends string>(
type: TAction
): (<TPayload>(payload: TPayload) => { type: TAction; payload: TPayload });
}

export class RePureComponent<P = {}, S = {}> extends ReComponent<P, S> { }
export class RePureComponent<P = {}, S = {}> extends ReComponent<P, S> {}
31 changes: 18 additions & 13 deletions type-definitions/__tests__/ReComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import * as React from "react";

import {
ReComponent,

Update,
NoUpdate,
SideEffects,
UpdateWithSideEffects
} from "../../";

type Action = {| type: "A" |} | {| type: "B" |} | {| type: "C" |} | {| type: "D" |}
type Action =
| {| type: "A" |}
| {| type: "B" |}
| {| type: "C" |}
| {| type: "D" |};

class StateMismatch extends ReComponent<{}, { count: number }, Action> {
// $ExpectError
Expand Down Expand Up @@ -54,7 +57,6 @@ class UpdateTypes extends ReComponent<{}, { count: number }, Action> {
instance.someClassProperty = 1;
// $ExpectError - `instance.someClassProperty` has to be number
instance.someClassProperty = "1";

});
}
}
Expand All @@ -63,9 +65,9 @@ class UpdateTypes extends ReComponent<{}, { count: number }, Action> {
class TypedActionTypes extends ReComponent<
{},
{ count: number },
{| type: 'CLICK' |}
{| type: "CLICK" |}
> {
handleClick = () => this.send({ type: 'CLICK' });
handleClick = () => this.send({ type: "CLICK" });

static reducer(action, state) {
switch (action.type) {
Expand Down Expand Up @@ -105,7 +107,7 @@ const absurd = <T>(x: empty): T => {
class ExhaustivelyTypedFailingActionTypes extends ReComponent<
{},
{ count: number },
{| type: 'CLICK' |} | {| type: 'CLACK' |}
{| type: "CLICK" |} | {| type: "CLACK" |}
> {
static reducer(action, state) {
switch (action.type) {
Expand Down Expand Up @@ -139,16 +141,17 @@ class ExhaustivelyTypedPassingActionTypes extends ReComponent<
}
}


class FailingPayloadType extends ReComponent<
{},
{ count: number, awesome: boolean },
{ type: "CLICK", payload: number } | { type: "CLACK", payload: boolean }
> {
// $ExpectError - `clicks` should be `number`
handleClick = (clicks: boolean) => this.send({ type: 'CLICK', payload: clicks });
handleClick = (clicks: boolean) =>
this.send({ type: "CLICK", payload: clicks });
// $ExpectError - `awesome` should be `boolean`
handleClack = (awesome: number) => this.send({ type: 'CLACK', payload: awesome });
handleClack = (awesome: number) =>
this.send({ type: "CLACK", payload: awesome });

static reducer(action, state) {
switch (action.type) {
Expand All @@ -170,9 +173,11 @@ class PassingPayloadType extends ReComponent<
{},
{ count: number, awesome: boolean },
{ type: "CLICK", payload: number } | { type: "CLACK", payload: boolean }
> {
handleClick = (clicks: number) => this.send({ type: 'CLICK', payload: clicks });
handleClack = (awesome: boolean) => this.send({ type: 'CLACK', payload: awesome });
> {
handleClick = (clicks: number) =>
this.send({ type: "CLICK", payload: clicks });
handleClack = (awesome: boolean) =>
this.send({ type: "CLACK", payload: awesome });

static reducer(action, state) {
switch (action.type) {
Expand All @@ -191,7 +196,7 @@ class PassingPayloadType extends ReComponent<
class CreateSenderTest extends ReComponent<
{},
{ count: number },
{| type: 'CLICK' |} | {| type: 'CLACK', payload: number |}
{| type: "CLICK" |} | {| type: "CLACK", payload: number |}
> {
handleClick = this.createSender("CLICK");
handleClack = this.createSender("CLACK");
Expand Down
11 changes: 9 additions & 2 deletions type-definitions/ts-tests/exports.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import * as recomponent from 'react-recomponent';
import { NoUpdate, Update, SideEffects, UpdateWithSideEffects, ReComponent, RePureComponent } from 'react-recomponent';
import * as recomponent from "react-recomponent";
import {
NoUpdate,
Update,
SideEffects,
UpdateWithSideEffects,
ReComponent,
RePureComponent
} from "react-recomponent";

NoUpdate; // $ExpectType () => NoUpdateAction
Update; // $ExpectType <T>(state: T) => UpdateAction<T>
Expand Down
7 changes: 6 additions & 1 deletion type-definitions/ts-tests/updateTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { NoUpdate, Update, SideEffects, UpdateWithSideEffects } from 'react-recomponent';
import {
NoUpdate,
Update,
SideEffects,
UpdateWithSideEffects
} from "react-recomponent";

// $ExpectType NoUpdateAction
NoUpdate();
Expand Down

0 comments on commit 0a46eef

Please sign in to comment.