mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 03:42:37 +02:00
chore: apply Biome hints
Co-authored-by: Alexis Métaireau <alexis@notmyidea.org>
This commit is contained in:
parent
45f1221d00
commit
200e12e0d9
6 changed files with 24 additions and 20 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { WithTemplate } from './utils.js'
|
|
||||||
import { translate } from './i18n.js'
|
import { translate } from './i18n.js'
|
||||||
|
import { WithTemplate } from './utils.js'
|
||||||
|
|
||||||
const TOOLBOX_TEMPLATE = `
|
const TOOLBOX_TEMPLATE = `
|
||||||
<ul class="umap-slideshow-toolbox dark">
|
<ul class="umap-slideshow-toolbox dark">
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
import * as Utils from '../utils.js'
|
||||||
|
import { HybridLogicalClock } from './hlc.js'
|
||||||
import { DataLayerUpdater, FeatureUpdater, MapUpdater } from './updaters.js'
|
import { DataLayerUpdater, FeatureUpdater, MapUpdater } from './updaters.js'
|
||||||
import { WebSocketTransport } from './websocket.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.
|
* The syncEngine exposes an API to sync messages between peers over the network.
|
||||||
|
@ -81,7 +81,7 @@ export class SyncEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
_send(inputMessage) {
|
_send(inputMessage) {
|
||||||
let message = this._operations.addLocal(inputMessage)
|
const message = this._operations.addLocal(inputMessage)
|
||||||
|
|
||||||
if (this.offline) return
|
if (this.offline) return
|
||||||
if (this.transport) {
|
if (this.transport) {
|
||||||
|
@ -154,7 +154,7 @@ export class SyncEngine {
|
||||||
this.onListPeersResponse({ peers })
|
this.onListPeersResponse({ peers })
|
||||||
|
|
||||||
// Get one peer at random
|
// Get one peer at random
|
||||||
let randomPeer = this._getRandomPeer()
|
const randomPeer = this._getRandomPeer()
|
||||||
|
|
||||||
if (randomPeer) {
|
if (randomPeer) {
|
||||||
// Retrieve the operations which happened before join.
|
// Retrieve the operations which happened before join.
|
||||||
|
@ -254,7 +254,7 @@ export class SyncEngine {
|
||||||
* @returns {string|bool} the selected peer uuid, or False if none was found.
|
* @returns {string|bool} the selected peer uuid, or False if none was found.
|
||||||
*/
|
*/
|
||||||
_getRandomPeer() {
|
_getRandomPeer() {
|
||||||
let otherPeers = this.peers.filter((p) => p !== this.uuid)
|
const otherPeers = this.peers.filter((p) => p !== this.uuid)
|
||||||
if (otherPeers.length > 0) {
|
if (otherPeers.length > 0) {
|
||||||
const random = Math.floor(Math.random() * otherPeers.length)
|
const random = Math.floor(Math.random() * otherPeers.length)
|
||||||
return otherPeers[random]
|
return otherPeers[random]
|
||||||
|
@ -308,7 +308,7 @@ export class Operations {
|
||||||
* @returns {*} clock-aware message
|
* @returns {*} clock-aware message
|
||||||
*/
|
*/
|
||||||
addLocal(inputMessage) {
|
addLocal(inputMessage) {
|
||||||
let message = { ...inputMessage, hlc: this._hlc.tick() }
|
const message = { ...inputMessage, hlc: this._hlc.tick() }
|
||||||
this._operations.push(message)
|
this._operations.push(message)
|
||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
@ -348,7 +348,7 @@ export class Operations {
|
||||||
*/
|
*/
|
||||||
storeRemoteOperations(remoteOperations) {
|
storeRemoteOperations(remoteOperations) {
|
||||||
// get the highest date from the passed operations
|
// get the highest date from the passed operations
|
||||||
let greatestHLC = remoteOperations
|
const greatestHLC = remoteOperations
|
||||||
.map((op) => op.hlc)
|
.map((op) => op.hlc)
|
||||||
.reduce((max, current) => (current > max ? current : max))
|
.reduce((max, current) => (current > max ? current : max))
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,12 @@ export class HybridLogicalClock {
|
||||||
* @returns object
|
* @returns object
|
||||||
*/
|
*/
|
||||||
parse(raw) {
|
parse(raw) {
|
||||||
let tokens = raw.split(':')
|
const tokens = raw.split(':')
|
||||||
|
|
||||||
if (tokens.length !== 3) {
|
if (tokens.length !== 3) {
|
||||||
throw new SyntaxError(`Unable to parse ${raw}`)
|
throw new SyntaxError(`Unable to parse ${raw}`)
|
||||||
}
|
}
|
||||||
let [walltime, rawNN, id] = tokens
|
const [walltime, rawNN, id] = tokens
|
||||||
|
|
||||||
let nn = Number.parseInt(rawNN)
|
let nn = Number.parseInt(rawNN)
|
||||||
if (Number.isNaN(nn)) {
|
if (Number.isNaN(nn)) {
|
||||||
|
@ -92,7 +92,7 @@ export class HybridLogicalClock {
|
||||||
if (now > local.walltime && now > remote.walltime) {
|
if (now > local.walltime && now > remote.walltime) {
|
||||||
nextValue = { ...local, walltime: now }
|
nextValue = { ...local, walltime: now }
|
||||||
} else if (local.walltime == remote.walltime) {
|
} 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 }
|
nextValue = { ...local, nn: nn }
|
||||||
} else if (remote.walltime > local.walltime) {
|
} else if (remote.walltime > local.walltime) {
|
||||||
nextValue = { ...remote, id: local.id, nn: remote.nn + 1 }
|
nextValue = { ...remote, id: local.id, nn: remote.nn + 1 }
|
||||||
|
|
|
@ -64,7 +64,10 @@ export class DataLayerUpdater extends BaseUpdater {
|
||||||
if (fieldInSchema(key)) {
|
if (fieldInSchema(key)) {
|
||||||
this.updateObjectValue(datalayer, key, value)
|
this.updateObjectValue(datalayer, key, value)
|
||||||
} else {
|
} 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])
|
datalayer.render([key])
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ export function checkId(string) {
|
||||||
* @returns Array[string]
|
* @returns Array[string]
|
||||||
*/
|
*/
|
||||||
export function getImpactsFromSchema(fields, schema) {
|
export function getImpactsFromSchema(fields, schema) {
|
||||||
schema = schema || U.SCHEMA
|
const current_schema = schema || U.SCHEMA
|
||||||
const impacted = fields
|
const impacted = fields
|
||||||
.map((field) => {
|
.map((field) => {
|
||||||
// remove the option prefix for fields
|
// remove the option prefix for fields
|
||||||
|
@ -46,8 +46,10 @@ export function getImpactsFromSchema(fields, schema) {
|
||||||
.reduce((acc, field) => {
|
.reduce((acc, field) => {
|
||||||
// retrieve the "impacts" field from the schema
|
// retrieve the "impacts" field from the schema
|
||||||
// and merge them together using sets
|
// and merge them together using sets
|
||||||
const impacts = schema[field]?.impacts || []
|
const impacts = current_schema[field]?.impacts || []
|
||||||
impacts.forEach((impact) => acc.add(impact))
|
for (const impact of impacts) {
|
||||||
|
acc.add(impact)
|
||||||
|
}
|
||||||
return acc
|
return acc
|
||||||
}, new Set())
|
}, new Set())
|
||||||
|
|
||||||
|
@ -62,10 +64,10 @@ export function getImpactsFromSchema(fields, schema) {
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
export function fieldInSchema(field, schema) {
|
export function fieldInSchema(field, schema) {
|
||||||
|
const current_schema = schema || U.SCHEMA
|
||||||
if (typeof field !== 'string') return false
|
if (typeof field !== 'string') return false
|
||||||
field = field.replace('options.', '').split('.')[0]
|
const field_name = field.replace('options.', '').split('.')[0]
|
||||||
schema = schema || U.SCHEMA
|
return current_schema[field_name] !== undefined
|
||||||
return schema[field] !== undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -224,7 +224,6 @@ U.Map = L.Map.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function (fields) {
|
render: function (fields) {
|
||||||
|
|
||||||
if (fields.includes('numberOfConnectedPeers')) {
|
if (fields.includes('numberOfConnectedPeers')) {
|
||||||
this.renderEditToolbar()
|
this.renderEditToolbar()
|
||||||
this.propagate()
|
this.propagate()
|
||||||
|
|
Loading…
Reference in a new issue