Skip to content

Commit ba938ad

Browse files
authored
Merge pull request particle-iot#42 from AntonPuko/flowClean
decorators flow annotations
2 parents 1fa8c19 + 0131122 commit ba938ad

File tree

5 files changed

+53
-31
lines changed

5 files changed

+53
-31
lines changed

src/lib/decorators/allowUpload.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import type { Decorator, HttpVerb } from './types';
1+
// @flow
22

3+
import type { Decorator, Descriptor } from './types';
4+
import type Controller from '../controllers/Controller';
5+
6+
/* eslint-disable no-param-reassign */
37
export default (
48
fileName: string,
59
maxCount: number = 0,
6-
): Decorator => (target, name, descriptor): Object => {
7-
const allowedUploads = target[name].allowedUploads || [];
8-
allowedUploads.push({
9-
maxCount: maxCount ? maxCount : undefined,
10-
name: fileName,
11-
});
12-
target[name].allowedUploads = allowedUploads;
13-
return descriptor;
14-
};
10+
): Decorator<Controller> =>
11+
(target: Controller, name: string, descriptor: Descriptor): Descriptor => {
12+
const allowedUploads = target[name].allowedUploads || [];
13+
allowedUploads.push({
14+
maxCount,
15+
name: fileName,
16+
});
17+
18+
target[name].allowedUploads = allowedUploads;
19+
return descriptor;
20+
};

src/lib/decorators/anonymous.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// @flow
22

3-
import type { Decorator } from './types';
3+
import type { Decorator, Descriptor } from './types';
4+
import type Controller from '../controllers/Controller';
45

5-
export default (): Decorator =>
6-
(target, name, descriptor): Object => {
7-
// eslint-disable-next-line no-param-reassign
6+
/* eslint-disable no-param-reassign */
7+
export default (): Decorator<Controller> =>
8+
(target: Controller, name: string, descriptor: Descriptor): Descriptor => {
89
target[name].anonymous = true;
910
return descriptor;
1011
};

src/lib/decorators/httpVerb.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import type { Decorator, HttpVerb } from './types';
1+
// @flow
22

3-
export default (
4-
httpVerb: HttpVerb,
5-
): Decorator => (target, name, descriptor): Object => {
6-
target[name].httpVerb = httpVerb;
7-
return descriptor;
8-
};
3+
import type { Decorator, Descriptor } from './types';
4+
import type Controller from '../controllers/Controller';
5+
6+
/* eslint-disable no-param-reassign */
7+
export default (httpVerb: HttpVerb): Decorator<Controller> =>
8+
(target: Controller, name: string, descriptor: Descriptor): Descriptor => {
9+
target[name].httpVerb = httpVerb;
10+
return descriptor;
11+
};

src/lib/decorators/route.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
export default (
2-
route: string,
3-
): Decorator => (target, name, descriptor): Object => {
4-
target[name].route = route;
5-
return descriptor;
6-
};
1+
// @flow
2+
3+
import type { Decorator, Descriptor } from './types';
4+
import type Controller from '../controllers/Controller';
5+
6+
/* eslint-disable no-param-reassign */
7+
export default (route: string): Decorator<Controller> =>
8+
(target: Controller, name: string, descriptor: Descriptor): Descriptor => {
9+
target[name].route = route;
10+
return descriptor;
11+
};

src/lib/decorators/types.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
// @flow
22

3-
export type Decorator = (
4-
target: Object,
3+
export type Decorator<TType> = (
4+
target: TType,
55
name: string,
6-
descriptor: Object,
7-
) => Object;
6+
descriptor: Descriptor,
7+
) => Descriptor;
8+
9+
export type Descriptor = {
10+
configurable: boolean,
11+
enumerable: boolean,
12+
value: Function,
13+
writeable: boolean,
14+
};
815

916
export type HttpVerb =
1017
'checkout' |

0 commit comments

Comments
 (0)