Skip to content

Instantly share code, notes, and snippets.

Arguments Against Promises for Promises

The argument for avoiding promises for promises is fairly simple. A promise is a representation of a value that will exit in the future. If that value is still a promise, you haven't really got to the final value yet. Conceptually having the promise doesn't really provide anything other than a means to obtain the final value, as such it's of no additional use to be able to get the intermediate nested promises: You might as well just jump straight to the value.

The "JQPFAQPFAWJPFADFFAN" Problem

This problem is explained in more detail by @erights here. The currently proposed [[Resolve]] algorithm only dictates this recursive flattening for unrecognised thenables, not for promises. THe advantage of this behavior is that a user can pick up a Promises/A+ library and return a deeply nested mess of foreign promises objects (all of which were broken enough not to do any unwrappi

Arguments in favor of Promises for Promises

The argument in favor of Promises for Promises is structured as follows:

  1. Examples
  2. Lazy Promises
  3. Remote Promises
  4. Partial Results
  5. Error Handling
  6. Testing
type Children = {
children: void | Array<Children>
message: [MessageBlame, MessageBlame, MessageBlame, MessageBlame, MessageComment, MessageBlame]
};
type Extra = {
children: void | Array<Children>
message: [MessageBlame, MessageBlame, MessageBlame, MessageBlame, MessageComment, MessageBlame] | [MessageBlame, MessageBlame]
};
type FlowErrorDuplicateProvider = {
kind: "duplicate provider"
// Press ctrl+space for code completion
export default function transformer(file, api) {
const j = api.jscodeshift;
let source = file.source;
let root = j(source);
// remove "use strict"
root.find(j.ExpressionStatement).filter(path => (
path.value.expression.type === 'Literal' &&

Making a CMS using Heroku, GitHub, node.js and React

Create a repository to be hold static website/content (done)

This repo will ultimately contain all the templates and code needed to render your website. It should deploy to Amazon S3 using travis. You can follow the instructions on https://simplestaticsite.org/ to get started.

Define Content Types

In the static repository, create a folder called "content". In this folder you can define each of the content types.

// assume that the optimiser doesn't know the base promise is never resolved
let resolve, reject;
const base = new Promise((_resolve, _reject) => {resolve = _resolve; reject = _reject;});
const end = new Promise(resolve => {
const middlePromise = new Promise(resolve => {
setTimeout(() => resolve(base), 1000);
});
resolve(middlePromise);
});

Building a MongoDB GUI

A small team at Red Gate recently set out to build a graphical interface for querying and interacting with MongoDB in just one week. As it was a new project, we got to experiment with some of the newer libraries and techniques for building rich web apps in node.js. Here are some of the more interesting things we found.

Architecture

We used express as the framework for the server side application, and browserify (via browserify-middleware) to help us structure the client side application. The beauty of browserify is that it allows us to use node.js style modules on the client side. Rather than choose any specific framework (e.g. angular or ember) we were able to mix and match just the things we needed. This makes it possible to pick the best tool for each individual job.

The client side of the application consists of a main entry point, which uses [page.js](http://vision

Web Framework

Express

A simple API that's easy to get to grips with, combined with endless middleware options to plug in extra functionality make this the perfect choice.

Connect

The foundation of express. A great starting point when you want something smaller/lower level, perhaps as a foundation for building your own web framework.

@ForbesLindesay
ForbesLindesay / peg.js
Created October 22, 2013 16:16
A CodeMirror mode for PEG.js
CodeMirror.defineMode("peg", function (config) {
var jsMode = CodeMirror.getMode(config, "javascript");
function identifier(stream) {
return stream.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);
}
return {
startState: function () {
return {
@ForbesLindesay
ForbesLindesay / parallel.js
Last active December 25, 2015 12:49
Tiny modification of https://github.com/visionmedia/co/blob/master/examples/parallel.js to make the race condition more obvious. i.e. here it will almost always occur.
a starts
b starts
c starts
co waits on a
b ends (throwing an error because `done` is undefined as it is not set until b is waited on, imagine this didn't crash the application)
c ends (throwing an error because `done` is undefined as it is not set until c is waited on, imagine this didn't crash the application)
a ends (allowing co to continue)
co waits on b