Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'slugid' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
async handleAction(message) {
let { payload, exchange, routes } = message;
// We encode the task id/run into the job guid so extract the task id.
let [taskId, runId] = payload.job_guid.split('/')
taskId = slugid.encode(taskId);
console.log(`Received ${payload.action} event for task ${taskId} by ${payload.requester}`);
let task = await this.queue.task(taskId);
switch (payload.action) {
case 'cancel':
await this.handleCancel(taskId, runId, task, payload);
break;
case 'retrigger':
await this.handleRetrigger(taskId, runId, task, payload);
break;
default:
console.log(`[action handler] unknown action ${payload.action}`);
}
}
}
if (numericifyVersion(React.version) < 15.6) {
console.warn(
'HiGlass requires React v15.6 or higher. Current version: ', React.version
);
}
this.pubSub = createPubSub();
this.domEvent = createDomEvent(this.pubSub);
this.pubSubs = [];
this.minHorizontalHeight = 20;
this.minVerticalWidth = 20;
this.resizeSensor = null;
this.uid = slugid.nice();
this.tiledPlots = {};
this.genomePositionSearchBoxes = {};
// keep track of the xScales of each Track Renderer
this.xScales = {};
this.yScales = {};
this.topDiv = null;
this.zoomToDataExtentOnInit = new Set();
// a reference of view / track combinations
// to be used with combined to viewAndTrackUid
this.viewTrackUidsToCombinedUid = {};
this.combinedUidToViewTrack = {};
// event listeners for when the scales of a view change
// bypasses the React event framework because this needs
}
debug('Channel was closed unexpectedly');
that.emit('error', new Error(
'Channel closed unexpectedly, likely server initiated shutdown'
));
});
return channel.prefetch(that._options.prefetch);
});
// Find queue name and decide if this is an exclusive queue
var exclusive = !this._options.queueName;
// Construct queue name
this._queueName = [
'queue', // Required by pulse security model
this._connection.namespace, // Required by pulse security model
this._options.queueName || 'exclusive/' + slugid.v4(),
].join('/');
// Create queue
var queueCreated = channelCreated.then(function() {
var opts = {
exclusive: exclusive,
durable: !exclusive,
autoDelete: exclusive,
};
// Set max length if provided
if (that._options.maxLength) {
opts.maxLength = that._options.maxLength;
}
return channel.assertQueue(that._queueName, opts);
});
let timeToDeadline = secondsTo(task.deadline);
// If deadline is reached, we don't care to publish a message about the task
// being pending.
if (timeToDeadline === 0) {
// This should not happen, but if timing is right it is possible.
console.log('runId: %s of taskId: %s became pending after deadline, ' +
'skipping pending message publication to azure queue',
runId, task.taskId);
return;
}
// Put message queue
return this._putMessage(queueNames[task.priority], {
taskId: task.taskId,
runId: runId,
hintId: slugid.v4(),
}, {
ttl: timeToDeadline,
visibility: 0,
});
}
debug("Connection error in AMQPListener: ", err.stack);
that.emit('error', err);
});
return that._conn.createConfirmChannel();
}).then(function(channel_) {
channel = channel_;
channel.on('error', function(err) {
debug("Channel error in AMQPListener: ", err.stack);
that.emit('error', err);
});
return channel.prefetch(that._options.prefetch);
});
// Find queue name and decide if this is an exclusive queue
var exclusive = !this._options.queueName;
this._queueName = this._options.queueName || slugid.v4();
// Create queue
var queueCreated = channelCreated.then(function() {
var opts = {
exclusive: exclusive,
durable: !exclusive,
autoDelete: exclusive,
};
// Set max length if provided
if (that._options.maxLength) {
opts.maxLength = that._options.maxLength;
}
return channel.assertQueue(that._queueName, opts);
});
// Create bindings
await Promise.all(cfgs.map(async cfg => {
// This must be unique to currently existing instances and match [a-z]([-a-z0-9]*[a-z0-9])?
// The lost entropy from downcasing, etc should be ok due to the fact that
// only running instances need not be identical. We do not use this name to identify
// workers in taskcluster.
const poolName = workerPoolId.replace(/[\/_]/g, '-').slice(0, 38);
const instanceName = `${poolName}-${slugid.nice().replace(/_/g, '-').toLowerCase()}`;
let op;
try {
const res = await this._enqueue('query', () => this.compute.instances.insert({
project: this.project,
zone: cfg.zone,
requestId: uuid.v4(), // This is just for idempotency
requestBody: {
...cfg, // We spread this in first so that users can't override stuff we set below
name: instanceName,
labels: {
...cfg.labels || {},
'created-by': `taskcluster-wm-${this.providerId}`.replace(/[^a-zA-Z0-9-]/g, '-'),
'managed-by': 'taskcluster',
'worker-pool-id': workerPoolId.replace(/[^a-zA-Z0-9-]/g, '-').toLowerCase(),
constructor(context, options) {
// create a clipped SVG Path
super(context, options);
const {
registerViewportChanged,
removeViewportChanged,
setDomainsCallback,
} = context;
const uid = slugid.nice();
this.uid = uid;
this.options = options;
this.removeViewportChanged = removeViewportChanged;
this.setDomainsCallback = setDomainsCallback;
this.viewportXDomain = null;
this.viewportYDomain = null;
const maxHalf = Number.MAX_VALUE / 2;
this.brush = brush(true)
.extent([[-maxHalf, -maxHalf], [maxHalf, maxHalf]])
.on('brush', this.brushed.bind(this));
this.gBrush = this.gMain
typeof this.options.maxPos !== 'undefined'
&& !Number.isNaN(+this.options.maxPos)
)
? +this.options.maxPos
: 180;
// HiGlass currently only supports squared tile sets but maybe in the
// future...
this.minY = this.options.minY || this.minX;
this.maxY = this.options.maxY || this.maxX;
this.maxZoom = 19;
this.maxWidth = this.maxX - this.minX;
this.animate = animate;
this.uuid = slugid.nice();
this.refreshTilesDebounced = debounce(
this.refreshTiles.bind(this), ZOOM_DEBOUNCE
);
}
handleTrackAdded(viewId, newTrack, position, host = null) {
this.addDefaultTrackOptions(newTrack);
// make sure the new track has a uid
if (!newTrack.uid) newTrack.uid = slugid.nice();
if (newTrack.contents) {
// add default options to combined tracks
for (const ct of newTrack.contents) { this.addDefaultTrackOptions(ct); }
}
if (this.state.addTrackPosition) {
// we've already added the track, remove the add track dialog
this.setState({
addTrackPosition: null,
});
}
if (host) {
// we're adding a series rather than a whole new track
this.handleSeriesAdded(viewId, newTrack, position, host);
this.initialVerticalTrackHeight = this.initialHorizontalTrackWidth;
this.initialVerticalTrackWidth = this.initialVerticalTrackHeight;
this.initLayouts();
this.setupTrackDescriptions();
let tracks = this.props.viewConfig.tracks;
let currentTop = 0;
this.twoD = false; // are there any 2D tracks? this affects how the genomic
// coordinates are displayed in the search box
//this.heightSpecified = true; // do any of the tracks request a particular height?
for (let i = 0; i < tracks.length; i++) {
let trackHeight = this.defaultDims[this.trackDescriptions[tracks[i].type].position].height;
let trackWidth = this.defaultDims[this.trackDescriptions[tracks[i].type].position].width;
let trackId = slugid.nice();
if (this.trackDescriptions[tracks[i].type].position == 'left' ||
this.trackDescriptions[tracks[i].type].position == 'center')
this.twoD = true
if (this.trackDescriptions[tracks[i].type].position == 'center' &&
this.trackDescriptions[tracks[i].type].overlay == false)
if (!('height' in tracks[i]))
this.heightSpecified = false;
if ('height' in tracks[i]) {
trackHeight = tracks[i].height;
}
if ('width' in tracks[i])
trackWidth = tracks[i].width;
if ('uid' in tracks[i])