Skip to content

Instantly share code, notes, and snippets.

@kesne
kesne / README.md
Last active April 20, 2017 00:00
global.env

Why?

There's no standardized, cross-platform, developer-friendly way to detect what environment you're running code in. The JS community has generally centered around reading process.env.NODE_ENV, but this property feels out of place in browser code, and requires a lot of typing at every usage (it's too easy to get wrong or flip the condition backwards). Some people set up __DEV__ to transpile down to process.env.NODE_ENV !== 'production' for a better developer experience.

Enter global.env

A new property, hung on the global object. This spec is to satisfy node, browser, and native.

What is it?

@kesne
kesne / index.js
Last active December 16, 2017 20:37
better-worker
import BetterWorker from 'better-worker';
const bgSort = new BetterWorker((threads) => {
return threads.sort((threadA, threadB) => {
return threadA.id > threadB.id ? 1 : -1;
});
});
// Using the worker-ified function:

You want to logically group fields together based on their auth strategy.

You can define a type that groups your service fields together:

type Services {
  updateUser(name: String!): User
  activateUser(active: Boolean!): User
}
// We have two types of work, A, B. We schedule A to be done very frequently!
// It doesn't take a lot of time (maybe a ms or two), but B can take a decent
// amount of time (maybe 10ms+).
//
// Write a scheduler that can perform tasks A and B as often as possible, BUT
// does not result in any frame skipping (do not lock the main thread for very
// long).
// MOCK TO MAKE NODE WORK:
if (typeof requestAnimationFrame === "undefined") {