This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// var | |
(function() { | |
console.log(foo); //undefined, foo is hoisted | |
var foo = "foo"; | |
console.log(bar); // ReferenceError: bar is not defined | |
})(); | |
(function() { | |
function foo() { | |
var a = (b = 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const indexBy = (value, ...fields) => { | |
if (fields.length === 0) { | |
return value; | |
} | |
const [currentField, ...rest] = fields; | |
const newValue = mapObjectValues(value, Array.isArray, indexByField, currentField); | |
return indexBy(newValue, ...rest); | |
}; | |
Array.prototype.indexBy = function(...fields) { | |
return indexBy(this, ...fields); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mapObjectValues = (value, shouldMap, mapFn, ...args) => { | |
if (shouldMap(value)) { | |
return mapFn(value, ...args); | |
} | |
return { | |
...Object.keys(value).reduce( | |
(acc, k) => ({ | |
...acc, | |
[k]: mapObjectValues(value[k], shouldMap, mapFn, ...args), | |
}), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const indexByField = (array, field) => | |
array.reduce((acc, it) => { | |
const key = it[field]; | |
const value = acc[key] ? [...acc[key], it] : [it]; | |
return { | |
...acc, | |
[key]: value, | |
}; | |
}, {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Remove duplicates from an array | |
(function () { | |
Array.prototype.unique = function () { | |
return Array.from(new Set(this)); | |
}; | |
console.log([1, 2, 3, 4, 4, 5].unique()); // [1, 2, 3, 4, 5] | |
})(); | |
// Memoized function | |
(function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Promise from "bluebird"; | |
import dhtSensorLib from "node-dht-sensor"; | |
export class DHTSensor { | |
constructor(dhtType, gpio, measurementLocation) { | |
this.dhtType = dhtType; | |
this.gpio = gpio; | |
this.measurementLocation = measurementLocation; | |
} | |
toString() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os from "os"; | |
import { Log } from "../util/log"; | |
import { SensorHandler } from "./sensorHandler"; | |
import { LEDHandler } from "./ledHandler"; | |
import config from "../config"; | |
export class SocketHandler { | |
constructor(io) { | |
this.io = io; | |
this.numConnections = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SocketIO from "socket.io"; | |
import jwt from "jsonwebtoken"; | |
import _ from "underscore"; | |
import { logError } from "../utils/log"; | |
import { ThingModel } from "../models/thing"; | |
export const setupSocketIO = server => { | |
const io = new SocketIO(server); | |
io.use(async (socket, next) => { | |
const { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect } from "react"; | |
import PropTypes from "prop-types"; | |
import { handleDataParams } from "hocs/dataParams"; | |
import store from "config/store"; | |
import RealTimeParamsPanel from "containers/RealTimeParamsPanel"; | |
import { startRealTimeData, finishRealTimeData, resetData } from "actions/data"; | |
import { reset } from "actions/common"; | |
import Charts from "containers/Charts"; | |
import { REALTIME } from "constants/chartTypes"; | |
import { THING, TYPE } from "constants/params"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
DATA_REQUEST, | |
DATA_REQUEST_SUCCESS, | |
DATA_REQUEST_ERROR, | |
ADD_DATA_ITEM, | |
RESET_DATA, | |
} from "constants/actionTypes/data"; | |
import { SocketController } from "helpers/socketController"; | |
import { RESET } from "constants/actionTypes/common"; | |
import * as fromState from "reducers"; |
OlderNewer