Skip to content

Commit

Permalink
feat: convert jsdoc to flow
Browse files Browse the repository at this point in the history
```
jsdoc2flow -i .\lib\ --overwrite
```
  • Loading branch information
aminya committed Apr 1, 2021
1 parent 0eb25e9 commit 2f1d11e
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 187 deletions.
35 changes: 19 additions & 16 deletions lib/decoration-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class DecorationManagement {
*
* @return {Array<Decoration>} all the decorations in this `Minimap`
*/
getDecorations() {
getDecorations(): Array<Decoration> {
return [...this.decorationsById.values()]
}

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

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

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

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

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

Expand All @@ -174,7 +174,7 @@ export default class DecorationManagement {
* @param {number} id the decoration id
* @return {Decoration} the decoration with the given id
*/
decorationForId(id) {
decorationForId(id: number): Decoration {
return this.decorationsById.get(id)
}

Expand All @@ -186,7 +186,7 @@ export default class DecorationManagement {
* @return {Record<string, Decoration>} the decorations that intersect the passed-in
* range
*/
decorationsForScreenRowRange(startScreenRow, endScreenRow) {
decorationsForScreenRowRange(startScreenRow: number, endScreenRow: number): Record<string, Decoration> {
const decorationsByMarkerId = {}
const markers = this.findMarkers({
intersectsScreenRowRange: [startScreenRow, endScreenRow],
Expand Down Expand Up @@ -231,7 +231,7 @@ export default class DecorationManagement {
* highlight-outine decorations at a given
* row
*/
decorationsByTypeThenRows() {
decorationsByTypeThenRows(): {} {
if (this.decorationsByTypeThenRowsCache != null) {
return this.decorationsByTypeThenRowsCache
}
Expand Down Expand Up @@ -328,7 +328,10 @@ export default class DecorationManagement {
* @emits {did-add-decoration} when the decoration is created successfully
* @emits {did-change} when the decoration is created successfully
*/
decorateMarker(marker, decorationParams) {
decorateMarker(
marker: Marker,
decorationParams: { class: string, color: string, plugin: string, render: function, scope: string, type: string }
): Decoration {
if (this.destroyed || this.minimap.destroyed || marker == null) {
return
}
Expand Down Expand Up @@ -452,7 +455,7 @@ export default class DecorationManagement {
* @param {Decoration} decoration the decoration for which emitting an event
* @access private
*/
emitDecorationChanges(type, decoration) {
emitDecorationChanges(type: string, decoration: Decoration) {
if (this.destroyed || this.minimap.editorDestroyed()) {
return
}
Expand All @@ -476,7 +479,7 @@ export default class DecorationManagement {
* change object
* @access private
*/
emitRangeChanges(type, range, screenDelta) {
emitRangeChanges(type: string, range: {}, screenDelta: number) {
const startScreenRow = range.start.row
const endScreenRow = range.end.row
const lastRenderedScreenRow = this.minimap.getLastVisibleScreenRow()
Expand All @@ -503,7 +506,7 @@ export default class DecorationManagement {
* @emits {did-change} when the decoration is removed
* @emits {did-remove-decoration} when the decoration is removed
*/
removeDecoration(decoration) {
removeDecoration(decoration: Decoration) {
if (decoration == null) {
return
}
Expand Down Expand Up @@ -555,7 +558,7 @@ export default class DecorationManagement {
* @emits {did-change} when a decoration have been removed
* @emits {did-remove-decoration} when a decoration have been removed
*/
removeAllDecorationsForMarker(marker) {
removeAllDecorationsForMarker(marker: Marker) {
if (marker == null) {
return
}
Expand Down Expand Up @@ -586,7 +589,7 @@ export default class DecorationManagement {
* @param {Marker} marker the marker for which removing decorations
* @access private
*/
removedAllMarkerDecorations(marker) {
removedAllMarkerDecorations(marker: Marker) {
if (marker == null) {
return
}
Expand Down Expand Up @@ -666,7 +669,7 @@ function getOriginatorPackageName() {
* @return {Array<Object>} the array of diff ranges
* @access private
*/
function computeRangesDiffs(oldStart, oldEnd, newStart, newEnd) {
function computeRangesDiffs(oldStart: number, oldEnd: number, newStart: number, newEnd: number): Array<{}> {
const diffs = []

if (oldStart.isLessThan(newStart)) {
Expand Down
20 changes: 10 additions & 10 deletions lib/decoration.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class Decoration {
* @param {string} type the decoration type to match
* @return {boolean} whether the decoration properties match the type
*/
static isType(decorationProperties, type) {
static isType(decorationProperties: {}, type: string): boolean {
if (Array.isArray(decorationProperties.type)) {
if (decorationProperties.type.indexOf(type) >= 0) {
return true
Expand All @@ -40,7 +40,7 @@ export default class Decoration {
* be displayed
* @param {Object} properties the decoration's properties
*/
constructor(marker, minimap, properties) {
constructor(marker: Marker, minimap: Minimap, properties: {}) {
/**
* @access private
*/
Expand Down Expand Up @@ -100,7 +100,7 @@ export default class Decoration {
*
* @return {boolean} whether this decoration is destroyed or not
*/
isDestroyed() {
isDestroyed(): boolean {
return this.destroyed
}

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

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

Expand All @@ -133,7 +133,7 @@ export default class Decoration {
*
* @return {number} the decoration id
*/
getId() {
getId(): number {
return this.id
}

Expand All @@ -142,7 +142,7 @@ export default class Decoration {
*
* @return {Marker} the decoration's marker
*/
getMarker() {
getMarker(): Marker {
return this.marker
}

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

Expand All @@ -164,7 +164,7 @@ export default class Decoration {
*
* @return {Object} the decoration's properties
*/
getProperties() {
getProperties(): {} {
return this.properties
}

Expand All @@ -174,7 +174,7 @@ export default class Decoration {
*
* @param {Object} newProperties the new properties for the decoration
*/
setProperties(newProperties) {
setProperties(newProperties: {}) {
if (this.destroyed) {
return
}
Expand Down
8 changes: 4 additions & 4 deletions lib/dom-styles-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class DOMStylesReader {
* @return {string} the computed property's value
* used in CanvasDrawer
*/
retrieveStyleFromDom(scopes, property, targetNode, getFromCache) {
retrieveStyleFromDom(scopes: Array<string>, property: string, targetNode: Node, getFromCache: boolean): string {
if (!scopes.length) {
return ""
} // no scopes
Expand Down Expand Up @@ -104,7 +104,7 @@ export default class DOMStylesReader {
*
* @access private
*/
ensureDummyNodeExistence(targetNode) {
ensureDummyNodeExistence(targetNode: Node) {
if (this.targetNode !== targetNode || this.dummyNode === undefined) {
this.dummyNode = document.createElement("span")
this.dummyNode.style.visibility = "hidden"
Expand Down Expand Up @@ -159,7 +159,7 @@ const hueRegexp = /hue-rotate\((\d+)deg\)/
* @return {string} the rotated CSS color
* @access private
*/
function rotateHue(value, filter) {
function rotateHue(value: string, filter: string): string {
const match = value.match(rgbExtractRegexp)
let [, , r, g, b, , a] = match

Expand All @@ -186,7 +186,7 @@ function rotateHue(value, filter) {
* @return {Array<number>} the rotated color channels
* @access private
*/
function rotate(r, g, b, angle) {
function rotate(r: number, g: number, b: number, angle: number): Array<number> {
const matrix = [1, 0, 0, 0, 1, 0, 0, 0, 1]
const lumR = 0.2126
const lumG = 0.7152
Expand Down
10 changes: 5 additions & 5 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export { default as MinimapElement } from "./minimap-element"
* @type {boolean}
* @access private
*/
let active = false
let active: boolean = false
/**
* The toggle state of the package.
*
* @type {boolean}
* @access private
*/
let toggled = false
let toggled: boolean = false
/**
* The `Map` where Minimap instances are stored with the text editor they
* target as key.
Expand All @@ -49,14 +49,14 @@ export let editorsMinimaps = null
* @type {CompositeDisposable}
* @access private
*/
let subscriptions = null
let subscriptions: CompositeDisposable = null
/**
* The disposable that stores the package's commands subscription.
*
* @type {Disposable}
* @access private
*/
let subscriptionsOfCommands = null
let subscriptionsOfCommands: Disposable = null

/**
* The package's events emitter.
Expand Down Expand Up @@ -188,7 +188,7 @@ export function toggle() {
*
* @param {string} template the name of the template to use
*/
async function generatePlugin(template) {
async function generatePlugin(template: string) {
const { default: MinimapPluginGeneratorElement } = await import("./minimap-plugin-generator-element")
const view = new MinimapPluginGeneratorElement()
view.template = template
Expand Down
Loading

0 comments on commit 2f1d11e

Please sign in to comment.