Skip to content

Commit

Permalink
chore: apply Biome hints
Browse files Browse the repository at this point in the history
Co-authored-by: Alexis Métaireau <[email protected]>
  • Loading branch information
yohanboniface and almet committed Oct 24, 2024
1 parent 45f1221 commit 200e12e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion umap/static/umap/js/modules/slideshow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WithTemplate } from './utils.js'
import { translate } from './i18n.js'
import { WithTemplate } from './utils.js'

const TOOLBOX_TEMPLATE = `
<ul class="umap-slideshow-toolbox dark">
Expand Down
14 changes: 7 additions & 7 deletions umap/static/umap/js/modules/sync/engine.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Utils from '../utils.js'
import { HybridLogicalClock } from './hlc.js'
import { DataLayerUpdater, FeatureUpdater, MapUpdater } from './updaters.js'
import { WebSocketTransport } from './websocket.js'
import { HybridLogicalClock } from './hlc.js'
import * as Utils from '../utils.js'

/**
* The syncEngine exposes an API to sync messages between peers over the network.
Expand Down Expand Up @@ -81,7 +81,7 @@ export class SyncEngine {
}

_send(inputMessage) {
let message = this._operations.addLocal(inputMessage)
const message = this._operations.addLocal(inputMessage)

if (this.offline) return
if (this.transport) {
Expand Down Expand Up @@ -154,7 +154,7 @@ export class SyncEngine {
this.onListPeersResponse({ peers })

// Get one peer at random
let randomPeer = this._getRandomPeer()
const randomPeer = this._getRandomPeer()

if (randomPeer) {
// Retrieve the operations which happened before join.
Expand Down Expand Up @@ -254,7 +254,7 @@ export class SyncEngine {
* @returns {string|bool} the selected peer uuid, or False if none was found.
*/
_getRandomPeer() {
let otherPeers = this.peers.filter((p) => p !== this.uuid)
const otherPeers = this.peers.filter((p) => p !== this.uuid)
if (otherPeers.length > 0) {
const random = Math.floor(Math.random() * otherPeers.length)
return otherPeers[random]
Expand Down Expand Up @@ -308,7 +308,7 @@ export class Operations {
* @returns {*} clock-aware message
*/
addLocal(inputMessage) {
let message = { ...inputMessage, hlc: this._hlc.tick() }
const message = { ...inputMessage, hlc: this._hlc.tick() }
this._operations.push(message)
return message
}
Expand Down Expand Up @@ -348,7 +348,7 @@ export class Operations {
*/
storeRemoteOperations(remoteOperations) {
// get the highest date from the passed operations
let greatestHLC = remoteOperations
const greatestHLC = remoteOperations
.map((op) => op.hlc)
.reduce((max, current) => (current > max ? current : max))

Expand Down
6 changes: 3 additions & 3 deletions umap/static/umap/js/modules/sync/hlc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export class HybridLogicalClock {
* @returns object
*/
parse(raw) {
let tokens = raw.split(':')
const tokens = raw.split(':')

if (tokens.length !== 3) {
throw new SyntaxError(`Unable to parse ${raw}`)
}
let [walltime, rawNN, id] = tokens
const [walltime, rawNN, id] = tokens

let nn = Number.parseInt(rawNN)
if (Number.isNaN(nn)) {
Expand Down Expand Up @@ -92,7 +92,7 @@ export class HybridLogicalClock {
if (now > local.walltime && now > remote.walltime) {
nextValue = { ...local, walltime: now }
} else if (local.walltime == remote.walltime) {
let nn = Math.max(local.nn, remote.nn) + 1
const nn = Math.max(local.nn, remote.nn) + 1
nextValue = { ...local, nn: nn }
} else if (remote.walltime > local.walltime) {
nextValue = { ...remote, id: local.id, nn: remote.nn + 1 }
Expand Down
7 changes: 5 additions & 2 deletions umap/static/umap/js/modules/sync/updaters.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BaseUpdater {

export class MapUpdater extends BaseUpdater {
update({ key, value }) {
if (fieldInSchema(key)){
if (fieldInSchema(key)) {
this.updateObjectValue(this.map, key, value)
}

Expand All @@ -64,7 +64,10 @@ export class DataLayerUpdater extends BaseUpdater {
if (fieldInSchema(key)) {
this.updateObjectValue(datalayer, key, value)
} else {
console.debug('Not applying update for datalayer because key is not in the schema', key)
console.debug(
'Not applying update for datalayer because key is not in the schema',
key
)
}
datalayer.render([key])
}
Expand Down
14 changes: 8 additions & 6 deletions umap/static/umap/js/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function checkId(string) {
* @returns Array[string]
*/
export function getImpactsFromSchema(fields, schema) {
schema = schema || U.SCHEMA
const current_schema = schema || U.SCHEMA
const impacted = fields
.map((field) => {
// remove the option prefix for fields
Expand All @@ -46,8 +46,10 @@ export function getImpactsFromSchema(fields, schema) {
.reduce((acc, field) => {
// retrieve the "impacts" field from the schema
// and merge them together using sets
const impacts = schema[field]?.impacts || []
impacts.forEach((impact) => acc.add(impact))
const impacts = current_schema[field]?.impacts || []
for (const impact of impacts) {
acc.add(impact)
}
return acc
}, new Set())

Expand All @@ -62,10 +64,10 @@ export function getImpactsFromSchema(fields, schema) {
* @returns {boolean}
*/
export function fieldInSchema(field, schema) {
const current_schema = schema || U.SCHEMA
if (typeof field !== 'string') return false
field = field.replace('options.', '').split('.')[0]
schema = schema || U.SCHEMA
return schema[field] !== undefined
const field_name = field.replace('options.', '').split('.')[0]
return current_schema[field_name] !== undefined
}

/**
Expand Down
1 change: 0 additions & 1 deletion umap/static/umap/js/umap.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ U.Map = L.Map.extend({
},

render: function (fields) {

if (fields.includes('numberOfConnectedPeers')) {
this.renderEditToolbar()
this.propagate()
Expand Down

0 comments on commit 200e12e

Please sign in to comment.