Skip to content

Instantly share code, notes, and snippets.

@pirfalt
pirfalt / .phoenix.js
Created February 5, 2014 15:58
Pirfalts Phoenix config
// HELPERS
// Sometimes it's easier to work with edges instead of point + size
// {x, y, height, width} => {top, bottom, left right}
function frameToRect(frame) {
return {
left: frame.x,
right: frame.x + frame.width,
top: frame.y,
bottom: frame.y + frame.height

Stream based on callbacks

Its almost a port of the w3c specc, but uses callbacks instead of promises.

Why?

To see if i could, the w3c specc is one of the best speccs i have seen, very readable and easy to follow. The only thing i question is the use of promises in that situation. The only place you can reasnobly call read is from within the promise resolution. If you dont use the good parts of promises (cached values for multiple, possible late, readers) but treat them like a one shot event, it seams like a simple callback is the thing your looking for.

@pirfalt
pirfalt / signal.js
Created November 9, 2013 11:55
JS: Signal
function signal(creator) {
return function listen(listener) {
return creator(listener)
}
}
@pirfalt
pirfalt / signal.md
Last active December 27, 2015 20:29
Signals (one event, emiters)

Signals (one event, emiters)

// signal := ( creator:(listener) => void ) => ( listener:(data) => void )
function signal(creator) {
  return function listen(listener) {
    // The magic, hand the listener to the creator
    creator(listener)
  }
}