Skip to content

Commit 2f1d11e

Browse files
committed
feat: convert jsdoc to flow
``` jsdoc2flow -i .\lib\ --overwrite ```
1 parent 0eb25e9 commit 2f1d11e

File tree

8 files changed

+224
-187
lines changed

8 files changed

+224
-187
lines changed

lib/decoration-management.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default class DecorationManagement {
8080
*
8181
* @return {Array<Decoration>} all the decorations in this `Minimap`
8282
*/
83-
getDecorations() {
83+
getDecorations(): Array<Decoration> {
8484
return [...this.decorationsById.values()]
8585
}
8686

@@ -96,7 +96,7 @@ export default class DecorationManagement {
9696
* - decoration: the decoration object that was created
9797
* @return {Disposable} a disposable to stop listening to the event
9898
*/
99-
onDidAddDecoration(callback) {
99+
onDidAddDecoration(callback: (event: Object) => void): Disposable {
100100
return this.emitter.on("did-add-decoration", callback)
101101
}
102102

@@ -112,7 +112,7 @@ export default class DecorationManagement {
112112
* - decoration: the decoration object that was created
113113
* @return {Disposable} a disposable to stop listening to the event
114114
*/
115-
onDidRemoveDecoration(callback) {
115+
onDidRemoveDecoration(callback: (event: Object) => void): Disposable {
116116
return this.emitter.on("did-remove-decoration", callback)
117117
}
118118

@@ -131,7 +131,7 @@ export default class DecorationManagement {
131131
* - decoration: the decoration object that was created
132132
* @return {Disposable} a disposable to stop listening to the event
133133
*/
134-
onDidChangeDecoration(callback) {
134+
onDidChangeDecoration(callback: (event: Object) => void): Disposable {
135135
return this.emitter.on("did-change-decoration", callback)
136136
}
137137

@@ -150,7 +150,7 @@ export default class DecorationManagement {
150150
* - decoration: the decoration object that was created
151151
* @return {Disposable} a disposable to stop listening to the event
152152
*/
153-
onDidChangeDecorationRange(callback) {
153+
onDidChangeDecorationRange(callback: (event: Object) => void): Disposable {
154154
return this.emitter.on("did-change-decoration-range", callback)
155155
}
156156

@@ -164,7 +164,7 @@ export default class DecorationManagement {
164164
* triggered
165165
* @return {Disposable} a disposable to stop listening to the event
166166
*/
167-
onDidUpdateDecoration(callback) {
167+
onDidUpdateDecoration(callback: (decoration: Decoration) => void): Disposable {
168168
return this.emitter.on("did-update-decoration", callback)
169169
}
170170

@@ -174,7 +174,7 @@ export default class DecorationManagement {
174174
* @param {number} id the decoration id
175175
* @return {Decoration} the decoration with the given id
176176
*/
177-
decorationForId(id) {
177+
decorationForId(id: number): Decoration {
178178
return this.decorationsById.get(id)
179179
}
180180

@@ -186,7 +186,7 @@ export default class DecorationManagement {
186186
* @return {Record<string, Decoration>} the decorations that intersect the passed-in
187187
* range
188188
*/
189-
decorationsForScreenRowRange(startScreenRow, endScreenRow) {
189+
decorationsForScreenRowRange(startScreenRow: number, endScreenRow: number): Record<string, Decoration> {
190190
const decorationsByMarkerId = {}
191191
const markers = this.findMarkers({
192192
intersectsScreenRowRange: [startScreenRow, endScreenRow],
@@ -231,7 +231,7 @@ export default class DecorationManagement {
231231
* highlight-outine decorations at a given
232232
* row
233233
*/
234-
decorationsByTypeThenRows() {
234+
decorationsByTypeThenRows(): {} {
235235
if (this.decorationsByTypeThenRowsCache != null) {
236236
return this.decorationsByTypeThenRowsCache
237237
}
@@ -328,7 +328,10 @@ export default class DecorationManagement {
328328
* @emits {did-add-decoration} when the decoration is created successfully
329329
* @emits {did-change} when the decoration is created successfully
330330
*/
331-
decorateMarker(marker, decorationParams) {
331+
decorateMarker(
332+
marker: Marker,
333+
decorationParams: { class: string, color: string, plugin: string, render: function, scope: string, type: string }
334+
): Decoration {
332335
if (this.destroyed || this.minimap.destroyed || marker == null) {
333336
return
334337
}
@@ -452,7 +455,7 @@ export default class DecorationManagement {
452455
* @param {Decoration} decoration the decoration for which emitting an event
453456
* @access private
454457
*/
455-
emitDecorationChanges(type, decoration) {
458+
emitDecorationChanges(type: string, decoration: Decoration) {
456459
if (this.destroyed || this.minimap.editorDestroyed()) {
457460
return
458461
}
@@ -476,7 +479,7 @@ export default class DecorationManagement {
476479
* change object
477480
* @access private
478481
*/
479-
emitRangeChanges(type, range, screenDelta) {
482+
emitRangeChanges(type: string, range: {}, screenDelta: number) {
480483
const startScreenRow = range.start.row
481484
const endScreenRow = range.end.row
482485
const lastRenderedScreenRow = this.minimap.getLastVisibleScreenRow()
@@ -503,7 +506,7 @@ export default class DecorationManagement {
503506
* @emits {did-change} when the decoration is removed
504507
* @emits {did-remove-decoration} when the decoration is removed
505508
*/
506-
removeDecoration(decoration) {
509+
removeDecoration(decoration: Decoration) {
507510
if (decoration == null) {
508511
return
509512
}
@@ -555,7 +558,7 @@ export default class DecorationManagement {
555558
* @emits {did-change} when a decoration have been removed
556559
* @emits {did-remove-decoration} when a decoration have been removed
557560
*/
558-
removeAllDecorationsForMarker(marker) {
561+
removeAllDecorationsForMarker(marker: Marker) {
559562
if (marker == null) {
560563
return
561564
}
@@ -586,7 +589,7 @@ export default class DecorationManagement {
586589
* @param {Marker} marker the marker for which removing decorations
587590
* @access private
588591
*/
589-
removedAllMarkerDecorations(marker) {
592+
removedAllMarkerDecorations(marker: Marker) {
590593
if (marker == null) {
591594
return
592595
}
@@ -666,7 +669,7 @@ function getOriginatorPackageName() {
666669
* @return {Array<Object>} the array of diff ranges
667670
* @access private
668671
*/
669-
function computeRangesDiffs(oldStart, oldEnd, newStart, newEnd) {
672+
function computeRangesDiffs(oldStart: number, oldEnd: number, newStart: number, newEnd: number): Array<{}> {
670673
const diffs = []
671674

672675
if (oldStart.isLessThan(newStart)) {

lib/decoration.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default class Decoration {
2121
* @param {string} type the decoration type to match
2222
* @return {boolean} whether the decoration properties match the type
2323
*/
24-
static isType(decorationProperties, type) {
24+
static isType(decorationProperties: {}, type: string): boolean {
2525
if (Array.isArray(decorationProperties.type)) {
2626
if (decorationProperties.type.indexOf(type) >= 0) {
2727
return true
@@ -40,7 +40,7 @@ export default class Decoration {
4040
* be displayed
4141
* @param {Object} properties the decoration's properties
4242
*/
43-
constructor(marker, minimap, properties) {
43+
constructor(marker: Marker, minimap: Minimap, properties: {}) {
4444
/**
4545
* @access private
4646
*/
@@ -100,7 +100,7 @@ export default class Decoration {
100100
*
101101
* @return {boolean} whether this decoration is destroyed or not
102102
*/
103-
isDestroyed() {
103+
isDestroyed(): boolean {
104104
return this.destroyed
105105
}
106106

@@ -113,7 +113,7 @@ export default class Decoration {
113113
* when the event is triggered
114114
* @return {Disposable} a disposable to stop listening to the event
115115
*/
116-
onDidChangeProperties(callback) {
116+
onDidChangeProperties(callback: (change: {}) => void): Disposable {
117117
return this.emitter.on("did-change-properties", callback)
118118
}
119119

@@ -124,7 +124,7 @@ export default class Decoration {
124124
* is triggered
125125
* @return {Disposable} a disposable to stop listening to the event
126126
*/
127-
onDidDestroy(callback) {
127+
onDidDestroy(callback: () => void): Disposable {
128128
return this.emitter.on("did-destroy", callback)
129129
}
130130

@@ -133,7 +133,7 @@ export default class Decoration {
133133
*
134134
* @return {number} the decoration id
135135
*/
136-
getId() {
136+
getId(): number {
137137
return this.id
138138
}
139139

@@ -142,7 +142,7 @@ export default class Decoration {
142142
*
143143
* @return {Marker} the decoration's marker
144144
*/
145-
getMarker() {
145+
getMarker(): Marker {
146146
return this.marker
147147
}
148148

@@ -155,7 +155,7 @@ export default class Decoration {
155155
* matches any in the array.
156156
* @return {boolean} whether this decoration match the passed-in type
157157
*/
158-
isType(type) {
158+
isType(type: string | Array): boolean {
159159
return Decoration.isType(this.properties, type)
160160
}
161161

@@ -164,7 +164,7 @@ export default class Decoration {
164164
*
165165
* @return {Object} the decoration's properties
166166
*/
167-
getProperties() {
167+
getProperties(): {} {
168168
return this.properties
169169
}
170170

@@ -174,7 +174,7 @@ export default class Decoration {
174174
*
175175
* @param {Object} newProperties the new properties for the decoration
176176
*/
177-
setProperties(newProperties) {
177+
setProperties(newProperties: {}) {
178178
if (this.destroyed) {
179179
return
180180
}

lib/dom-styles-reader.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class DOMStylesReader {
4747
* @return {string} the computed property's value
4848
* used in CanvasDrawer
4949
*/
50-
retrieveStyleFromDom(scopes, property, targetNode, getFromCache) {
50+
retrieveStyleFromDom(scopes: Array<string>, property: string, targetNode: Node, getFromCache: boolean): string {
5151
if (!scopes.length) {
5252
return ""
5353
} // no scopes
@@ -104,7 +104,7 @@ export default class DOMStylesReader {
104104
*
105105
* @access private
106106
*/
107-
ensureDummyNodeExistence(targetNode) {
107+
ensureDummyNodeExistence(targetNode: Node) {
108108
if (this.targetNode !== targetNode || this.dummyNode === undefined) {
109109
this.dummyNode = document.createElement("span")
110110
this.dummyNode.style.visibility = "hidden"
@@ -159,7 +159,7 @@ const hueRegexp = /hue-rotate\((\d+)deg\)/
159159
* @return {string} the rotated CSS color
160160
* @access private
161161
*/
162-
function rotateHue(value, filter) {
162+
function rotateHue(value: string, filter: string): string {
163163
const match = value.match(rgbExtractRegexp)
164164
let [, , r, g, b, , a] = match
165165

@@ -186,7 +186,7 @@ function rotateHue(value, filter) {
186186
* @return {Array<number>} the rotated color channels
187187
* @access private
188188
*/
189-
function rotate(r, g, b, angle) {
189+
function rotate(r: number, g: number, b: number, angle: number): Array<number> {
190190
const matrix = [1, 0, 0, 0, 1, 0, 0, 0, 1]
191191
const lumR = 0.2126
192192
const lumG = 0.7152

lib/main.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ export { default as MinimapElement } from "./minimap-element"
2727
* @type {boolean}
2828
* @access private
2929
*/
30-
let active = false
30+
let active: boolean = false
3131
/**
3232
* The toggle state of the package.
3333
*
3434
* @type {boolean}
3535
* @access private
3636
*/
37-
let toggled = false
37+
let toggled: boolean = false
3838
/**
3939
* The `Map` where Minimap instances are stored with the text editor they
4040
* target as key.
@@ -49,14 +49,14 @@ export let editorsMinimaps = null
4949
* @type {CompositeDisposable}
5050
* @access private
5151
*/
52-
let subscriptions = null
52+
let subscriptions: CompositeDisposable = null
5353
/**
5454
* The disposable that stores the package's commands subscription.
5555
*
5656
* @type {Disposable}
5757
* @access private
5858
*/
59-
let subscriptionsOfCommands = null
59+
let subscriptionsOfCommands: Disposable = null
6060

6161
/**
6262
* The package's events emitter.
@@ -188,7 +188,7 @@ export function toggle() {
188188
*
189189
* @param {string} template the name of the template to use
190190
*/
191-
async function generatePlugin(template) {
191+
async function generatePlugin(template: string) {
192192
const { default: MinimapPluginGeneratorElement } = await import("./minimap-plugin-generator-element")
193193
const view = new MinimapPluginGeneratorElement()
194194
view.template = template

0 commit comments

Comments
 (0)