Skip to content

Instantly share code, notes, and snippets.

@singh-shweta
singh-shweta / fetchAllWithVarWithClosure.js
Created February 3, 2022 09:29
fetchAll method working fine with closure
function fetchData(url, c) {
console.log("url====", url);
setTimeout(function () {
console.log("===in fetchdata callback for url===", url);
return c("response" + url);
}, 100 * url.length);
}
function fetchAll(urls, callback) {
/* responsesArray contains reponses index wise*/
@singh-shweta
singh-shweta / fetchAllWithVar.js
Created February 3, 2022 07:53
Fetch All using var- the behavior
function fetchData(url, c) {
console.log("url====", url);
setTimeout(function () {
console.log("===in fetchdata callback for url===", url);
return c("response" + url);
}, 100 * url.length);
}
function fetchAll(urls, callback) {
/* responsesArray contains reponses index wise*/
@singh-shweta
singh-shweta / fetchAll.js
Created January 27, 2022 19:23
A javascript implementation of fetchAll without using Promises
function fetchData(url, c) {
console.log("url====", url);
setTimeout(function () {
console.log("===in fetchdata callback for url===", url);
return c("response" + url);
}, 100 * url.length);
}
function fetchAll(urls, callback) {
/* responsesArray contains reponses index wise*/
@singh-shweta
singh-shweta / CardsWithGraph.js
Last active May 26, 2020 17:10
CardWithGraph and Intersection Observer use
import React, { Suspense, useState } from "react";
import {
Card,
Button,
CardTitle,
CardText,
CardSubtitle,
CardBody,
Row,
Col,
import React, { Suspense, useState } from "react";
import {
Card,
Button,
CardTitle,
CardText,
CardSubtitle,
CardBody,
Row,
Col,
@singh-shweta
singh-shweta / exampe.js
Last active May 10, 2020 16:24
This is just a component for example which can be used in any react project . This link in the component logs the navigation through the worker
import React from 'react';
import { sendLog } from "../initiateWorker";
/**
This is just a component for example which can be used in any react project .
This link in the component logs the navigation by passing the object to the worker using the sendLog exposed
*/
const AnchorLinkWithLogging = () => {
return (
<a
@singh-shweta
singh-shweta / initiateWorker.js
Last active May 10, 2020 17:21
Worker examples
import workerFile from "./worker";
export let logWorker, sendLog;
/**Checking if browser supports Workers */
if (window.Worker) {
logWorker = new Worker(workerFile); //initiates a worker thread
sendLog = (msg) => {
logWorker.postMessage(msg); //postMessage helps to communicate with the worker thread.
}